Electrical – DC motor control ULN2803

dcdc motoresp8266pwm

I'm trying to do some basic DC motor (pump) control through an Adafruit Feather Huzzah (ESP8266) and an ULN2803 Darlington transistor array; I've wired it up as follows:

enter image description here

And my code goes a little something like this:

void setup() {
  Serial.begin(9600);
  pinMode(14, OUTPUT);
  analogWrite(14, 0);
}

void loop() {

  if (Serial.available())
  {
    int speed = Serial.parseInt();
    if (speed >= 0 && speed <= 1023)
    {
      analogWrite(14, speed);
      Serial.print("PWM set to ");
      Serial.println(speed);
    }
  }
}

Unfortunately, unless analogWrite() is set to 1023, the motor only humms and does not rotate.

What I've done to troubleshoot:

  • I've used a (cheap) voltmeter to validate that the voltage going to
    the motor is variable as I adjust the analogWrite() value.
  • Also, I've replaced the motor with a LED strip and it fades properly as I adjust the analogWrite() value.
  • Finally, I've hooked the motor up to a desktop power supply, and was
    able to validate that as I reduce the voltage from 12V to 0V, the
    motor slows down.

What am I missing?

Best Answer

@WesleyLee got me on the right track; it looks like the starting voltage has to be high enough to get the motor spinning (at least initially).

The sketch below will get the motor running at a very low voltage:

void setup() {
  Serial.begin(9600);
  pinMode(14, OUTPUT);
}

void loop() {

  analogWrite(14, 1023);
  delay(15);
  analogWrite(14, 200);
  delay(3000);
}

It's not a beautiful solution but I suppose it works for my application. That's what you get for buying cheap pumps I guess.