Hi :). I am creating an arduino bluetooth car. I am using the L298n h bridge and 2 9volt motor with a current draw of 70ma. For the bluetooth I used an hc 05 bluetooth module.
Problem:
I can control both motors if i program it to run together, I can also run motor b individually if I want to turn right, but I cannot control motor a individually so I cannot turn left.
I have connected everything properly. I connected "enA" and "In1, In2" pins for both motors on the digital pins of my arduino. I used 9v power supply for my l298n and the arduino has its own power via usb.
Looking forward to your reply. Thanks!
int enA = 8;
int In1 = 9;
int In2 = 10;
int enB = 11;
int In3 = 12;
int In4 = 13;
int data;
void setup() {
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(In1, OUTPUT);
pinMode(In2, OUTPUT);
pinMode(In3, OUTPUT);
pinMode(In4, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available()>0){
data = Serial.read();
}
switch(data){
case '1': //Forward
digitalWrite(In1, HIGH);
digitalWrite(In2, LOW);
digitalWrite(In3, HIGH);
digitalWrite(In4, LOW);
analogWrite(enA, 255);
analogWrite(enB, 255);
break;
case '2': //Left
digitalWrite(In1, LOW);
digitalWrite(In2, LOW);
digitalWrite(In3, HIGH);
digitalWrite(In4, LOW);
analogWrite(enA, 255);
analogWrite(enB, 0);
break;
case '3': //Right
digitalWrite(In1, HIGH);
digitalWrite(In2, LOW);
digitalWrite(In3, Low);
digitalWrite(In4, LOW);
analogWrite(enA, 0);
analogWrite(enB, 255);
break;
case '4': //Full Stop
digitalWrite(In1, LOW);
digitalWrite(In2, LOW);
digitalWrite(In3, LOW);
digitalWrite(In4, LOW);
analogWrite(enA, 0);
analogWrite(enB, 0);
break;
default:
break;
}
}
All works except for left.