I'm studying H-Bridge for DC-motors. I have a 9V battery, DC-motor (9v), Arduino Nano and L293D. I follow Jeremy Blooms Book about Arduino. Well, the system works perfectly with PC connected. When I turn off the PC and connect to the battery only, it doesn't work at all. The system should work only with 9V battery.
```const uint8_t EN = 10;
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);
}```
A0 pin is used for Rotate sensor (PWM)
[![The circuit][1]][1]
[1]: https://i.sstatic.net/GliSw.png