12v fan controller with Adafruit Motor Shield, PWM problems

I’ll kick this off by explaining what I’m trying to do. I’m working on a virtual reality wind generator for use with my Oculus Rift while playing GTA 5 (among other games). I get the speed value through a memory address used by the game, then export that value to a text file with a LUA script, then feed that text file to the Arduino through the Processing IDE. Everything is working fairly well (I think) up until I try to fine tune my fan speed. It’s a large 150mm 12v fan hooked into the Adafruit Motor Shield. Here is the Arduino code I’m using to test it out:

#include <AFMotor.h>

AF_DCMotor fan(4, MOTOR34_64KHZ); // create motor #4, 64KHz pwm

void setup() {

  Serial.begin(9600);           // set up Serial library at 9600 bps
  fan.setSpeed(200);     // set the speed to 200/255

void loop() {


Here is the info on the Adafruit Shield I’m using.

Running the fan at 255 seems to work as it should, but when I decrease the speed, it starts behaving erratically and sort of pulses, rather than spinning at a constant speed. It will not spin up with a speed of anything less than 150. Given the nature of the project, I’ll need somewhat precise control over the fan speed and I’ll need to be able to spin the fan at slower speeds. Any ideas on how to get it spinning at a constant slower rate instead of having it pulse when I lower the speed value?

SIDE NOTE: As I understand it, most 12v PWM fans use a frequency of 25khz. The Adafruit Motor Shield uses 64, 8, 2, and 1khz PWM frequencies. Could this be causing it to behave strangely?

SIDE NOTE 2: This is a PWM fan, but using the PWM pin that’s built into the fan causes some really strange behavior as well. There is a lot of delay when changing the fan speed, which simply won’t work for this project. I’m trying the Adafruit Motor Shield as an attempt at having more precise control over the fan’s speed.

…and the model number or datasheet for the fan? That’s the more important detail.

It’s probably a brushless fan with its own motor controller. It won’t work* with PWM. A brushed fan is what you need, as it has no controller on board.

*“won’t work” = pretty much the behaviour you’re describing

This is the fan I’m using. I couldn’t find a datasheet for it anywhere.

Yeah it’s a brushless fan and I’m sure it has it’s own PWM controller, but I’m only using the + and - wires from the fan and using the Adafruit shield + Arduino to control PWM, so wouldn’t that bypass the fan’s built-in controller? It seems like it would treat it as any other DC motor.

I’ve tried my setup with a smaller fan (also brushless) powered directly by one of the Arduino’s PWM pins, and it worked flawlessly. It spun at constant rates and sped up and slowed down exactly as I told it to. The problem is there just isn’t enough juice to power a larger fan, so here I am.

No, the brushless controller works to keep the fan spinning regardless of fluctuations in the input voltage. It is trying to do its job and you are fighting it.

You got lucky with the little one - extremely lucky as even a small fan can burn out an Arduino output pin. 40mA maximum is only 0.2W and that's a terribly small amount of power for a fan.

Get a regular brushed fan or a smarter fan that has a speed control and a datasheet that tells you how to drive it.