I'm studying H-Bridge for DC motors. I have a 9V battery, DC motor (9v), Arduino Nano and L293D. I'm following Jeremy Bloom's book about Arduino. Well, the system works perfectly with a PC connected. When I turn off the PC and connect the battery only, it doesn't work at all. The system should work only with a 9V battery.
const uint8_t MC1 = 8; const uint8_t MC2 = 7; const uint8_t POT = 0; uint16_t velocity = 0; uint16_t PWM = 0; void forward(uint16_t); void reverse(uint16_t); void brake(); void setup(){ Serial.begin(9600); pinMode(EN, OUTPUT); pinMode(MC1, OUTPUT); pinMode(MC2, OUTPUT); brake(); } void loop(){ Serial.println(PWM); PWM = analogRead(POT); if (PWM > 562){ velocity = map(PWM, 563, 1023, 0, 255); forward(velocity); } if (PWM < 462){ velocity = map(PWM, 461, 0, 0, 255); reverse(velocity); } } void forward(uint16_t speedValue){ digitalWrite(EN, LOW); digitalWrite(MC1, HIGH); digitalWrite(MC2, LOW); analogWrite(EN, speedValue); } void reverse(uint16_t speedValue){ digitalWrite(EN, LOW); digitalWrite(MC1, LOW); digitalWrite(MC2, HIGH); analogWrite(EN, speedValue); } void brake(){ digitalWrite(EN, LOW); digitalWrite(MC1, LOW); digitalWrite(MC2, LOW); digitalWrite(EN, HIGH); }``` The A0 pin is used to rotate the sensor (PWM). [![The circuit][1]][1] [1]: https://i.sstatic.net/GliSw.png