0

I followed this tutorial: enter link description here

I built it according to the schematic except I didn't connect an LED (I assume this isn't the problem). This is the schematic: Schematic I'm a beginner so at first I connected the TX and RX of the HC-05 and the UNO but after getting errors I unplugged them from the UNO, uploaded the code, then plugged them back in (is this correct?) This is the code that I uploaded to my UNO:

char t;

void setup() {
pinMode(13,OUTPUT);   //left motors forward
pinMode(12,OUTPUT);   //left motors reverse
pinMode(11,OUTPUT);   //right motors forward
pinMode(10,OUTPUT);   //right motors reverse
pinMode(9,OUTPUT);   //Led
Serial.begin(9600);

}

void loop() {
if(Serial.available()){
  t = Serial.read();
  Serial.println(t);
}

if(t == 'F'){            //move forward(all motors rotate in forward direction)
  digitalWrite(13,HIGH);
  digitalWrite(11,HIGH);
}

else if(t == 'G'){      //move reverse (all motors rotate in reverse direction)
  digitalWrite(12,HIGH);
  digitalWrite(10,HIGH);
}

else if(t == 'L'){      //turn right (left side motors rotate in forward direction, right side motors doesn't rotate)
  digitalWrite(11,HIGH);
}

else if(t == 'R'){      //turn left (right side motors rotate in forward direction, left side motors doesn't rotate)
  digitalWrite(13,HIGH);
}

else if(t == 'W'){    //turn led on or off)
  digitalWrite(9,HIGH);
}
else if(t == 'w'){
  digitalWrite(9,LOW);
}

else if(t == 'S'){      //STOP (all motors stop)
  digitalWrite(13,LOW);
  digitalWrite(12,LOW);
  digitalWrite(11,LOW);
  digitalWrite(10,LOW);
}
delay(100);
}

Then I paired with the HC-05 and used the ArduinoCar app which works as follows: if I press forward it will send 'F' if I press backward it will send 'G' and so on. I successfully connected to HC-05. However when I press forward, the motors don't move this goes for all the other directions. The thing is when I press forward, for example, the UNO lights up (the L and TX LEDs light up) so I'm pretty sure it's getting received by the UNO but something is still wrong...

edit: I got it to work by powering the L298n (9V) and the UNO (rn connected to computer) separately and now the right and left work perfectly the problem is the forward and backward, when I press either of them only one wheel turns and it's stuttering and will stop quickly, is it because 9V is too small for both motors?

  • if I press forward it will send 'F' ... do you receive an 'F'? – jsotola Oct 19 at 16:07
  • Yes I have confirmed this in the serial monitor. 'F' is received and then 'S' when I stop pressing it – Michelle Adeline Oct 20 at 1:32
  • write minimum code to run one motor in one direction for 2 seconds – jsotola Oct 20 at 4:30
  • I am facing the same problem. here the car is not moving to any direction. what should i do?? – Tasmim Afrin Dec 2 at 8:04
  • What motors are you using? Are they 6V or 12V or 24 V. But more likely the Battery or Power Supply can not deliver the needed amount of current. Because the needed Voltage stays the same for either two or four motors in parallel. But the current would be twice as much. – Peter Paul Kiefer Dec 2 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.