Dc motor arduino

Hi everyone its my first time to post here. I want to make a temperature controlled fan Using Arduino with DHT11 sensor but first I want to make the DC motor spin first. Now the problem is my DC motor wont spin (Obviously)

Here is the reference video of the project the I want to make.
(YouTube?
v=0Fcyj5g26MM)

I will provide my set up, Diagram and serial monitor below. Please help me.

Here is the code.(exact code in the video)

//www.elegoo.com
//2016.12.12

/************************
Exercise the motor using
the L293D chip
************************/

#define ENABLE 5
#define DIRA 3
#define DIRB 4

int i;
 
void setup() {
  //---set pin direction
  pinMode(ENABLE,OUTPUT);
  pinMode(DIRA,OUTPUT);
  pinMode(DIRB,OUTPUT);
  Serial.begin(9600);
}

void loop() {
  //---back and forth example
    Serial.println("One way, then reverse");
    digitalWrite(ENABLE,HIGH); // enable on
    for (i=0;i<5;i++) {
    digitalWrite(DIRA,HIGH); //one way
    digitalWrite(DIRB,LOW);
    delay(500);
    digitalWrite(DIRA,LOW);  //reverse
    digitalWrite(DIRB,HIGH);
    delay(500);
  }
  digitalWrite(ENABLE,LOW); // disable
  delay(2000);

  Serial.println("fast Slow example");
  //---fast/slow stop example
  digitalWrite(ENABLE,HIGH); //enable on
  digitalWrite(DIRA,HIGH); //one way
  digitalWrite(DIRB,LOW);
  delay(3000);
  digitalWrite(ENABLE,LOW); //slow stop
  delay(1000);
  digitalWrite(ENABLE,HIGH); //enable on
  digitalWrite(DIRA,LOW); //one way
  digitalWrite(DIRB,HIGH);
  delay(3000);
  digitalWrite(DIRA,LOW); //fast stop
  delay(2000);

  Serial.println("PWM full then slow");
  //---PWM example, full speed then slow
  analogWrite(ENABLE,255); //enable on
  digitalWrite(DIRA,HIGH); //one way
  digitalWrite(DIRB,LOW);
  delay(2000);
  analogWrite(ENABLE,180); //half speed
  delay(2000);
  analogWrite(ENABLE,128); //half speed
  delay(2000);
  analogWrite(ENABLE,50); //half speed
  delay(2000);
  analogWrite(ENABLE,128); //half speed
  delay(2000);
  analogWrite(ENABLE,180); //half speed
  delay(2000);
  analogWrite(ENABLE,255); //half speed
  delay(2000);
  digitalWrite(ENABLE,LOW); //all done
  delay(10000);
}



You are using a 9V battery.
This type of battery may not be able to supply enough current to turn the motor.
Either use an external 9V power source or use 6 AA batteries in series. (6 x 1.5V = 9V).

1 Like

Hello! I just built a test circuit using your code with an external power supply, and seems to works fine. Also works with a 9v battery so perhaps your breadboard power supply is not supplying voltage?

The other Vcc (opposite corner of L293D) also needs power...

Quite right. The motor runs faster when both vccs are powered.

100nF capacitors near IC's are missing...

If I connect the Dc motor directly to the battery, it spins sir.

The same wiring and code? Mine does not workπŸ˜…

There is no capacitor in the video

So I will put another power supply module in opposite part?

But with 1 9V does it run? you tried?

9v batteries are for smoke alarms.

Do not use with Arduino especially when using motors, servos and the like.

Also do not use breadboard for connection of the above.

1 Like

What is the reason breadboard si not needed? in the video works fine

Any tips how to make this thing works? my wiring seems fine right?

I used both your code and schematic and it worked fine.

If you have a multimeter test for voltage on the breadboard.

As @build_1971 said you should have the other vcc powered.

Double check your wiring. In your picture it looks like the Motor GND ,and the LM293D GND are in the wrong places.

No...you are running a motor via a breadboard.
They were never made for those currents.

This is the same thing but it works?