Hello,
I have just bought an Arduino Nano v3.0, and as a first project I decided to control two DC motors (by making use of pwm). I saw many examples on the internet and decided to try one, however I could not make it work. Could you please help me?
Wiring:
motor wirings:
L293D pins 3-6-11-14
two for pwm:
L293D pin1 - arduino D9
L293D pin9 - arduino D10
digital pins:
L293D pin2 - arduino D11
L293D pin7 - arduino D12
L293D pin10 - arduino D4
L293D pin15 - arduino D5
grounds:
L293D pin4-5-12-13 - arduino ground
L293D pin8 to external 9V supply (also supply's ground goes to arduino's ground)
L293D pin16 to arduino 5V
and here is the code:
#define E1 12 // Enable Pin for motor 1
#define E2 13 // Enable Pin for motor 2
#define I1 14 // Control pin 1 for motor 1
#define I2 15 // Control pin 2 for motor 1
#define I3 7 // Control pin 1 for motor 2
#define I4 8 // Control pin 2 for motor 2
void setup() {
pinMode(E1, OUTPUT);
pinMode(E2, OUTPUT);
pinMode(I1, OUTPUT);
pinMode(I2, OUTPUT);
pinMode(I3, OUTPUT);
pinMode(I4, OUTPUT);
}
void loop() {
analogWrite(E1, 153); // Run in half speed
digitalWrite(E2, 255); // Run in full speed
digitalWrite(I1, HIGH);
digitalWrite(I2, LOW);
digitalWrite(I3, HIGH);
digitalWrite(I4, LOW);
delay(10000);
// change direction
digitalWrite(E1, LOW);
digitalWrite(E2, LOW);
delay(200);
digitalWrite(E1, 255); // Run in full speed
digitalWrite(E2, 153); // Run in half speed
digitalWrite(I1, LOW);
digitalWrite(I2, HIGH);
digitalWrite(I3, LOW);
digitalWrite(I4, HIGH);
delay(10000);
}
Could you help me what is wrong? I could not figure it out?
Regards,
Frank