Hello,
My car doesnt respond to my command from bluetooh terminal after i have once controlled the car. How can i fix this. The baudrate of the bluetooth module is 115200 and i set my serial monitor to 115200. You can find my code in the attachment.
The program both doesnt work at pc or with external battery. What i want : i want to control my car from my smartphone first from a bluetooth terminal app for testing. If i send a letter F then the car goes forward, if i send the letter B then the car goes Backwards. i have my esp8266 connect to a l298d h-bridge.
the h-bridge has an 12v input and ground and i have connected one ground to the esp8266 en one ground to the 12volt battery and the 12volt input also to the 12-volt battery. the h-bridge has also an input 1 and input 2: that is for clockwise turn and counter clockwise turn. next to the input 1 and 2 there is an enable pin that for enabling the l298d h-bridge. i have one motor connected to the h-bridge. i use an hc-05 bluetooth module tx to rx and rx to tx connected so the summary:
i want to controlling the car with bluetooh to go forward en backward and stop with the letter S.
here the code:
int cw = D1;
int ccw = D2;
int ENA = D3;
void setup() {
//Serial monitor begins at 115200 baud
Serial.begin(115200);
//clockwise turning:
pinMode(cw,OUTPUT);
//counter clockwise turning:
pinMode(ccw,OUTPUT);
//enables L298d pins:
pinMode(ENA,OUTPUT);
digitalWrite(ENA,HIGH);
}
void loop() {
while(Serial.available() == 0);
char val = Serial.read() ;//reads the signal from hc-05 bluetooth module
Serial.print(val); //Print recieved var in serial monitor
/*********For Forward motion*********/
if (val == 'F')
{
//car goes forward
//counter clockwise is HIGH:
digitalWrite(ccw,HIGH);
//clockwise is LOW:
digitalWrite(cw,LOW);
}
else if(val == 'B')
{
//car goes backwards
//clockwise is HIGH:
digitalWrite(cw,HIGH);
//counter clockwise is LOW
digitalWrite(ccw,LOW);
}
else if(val == 'S')
{
//car stops
//clockwise is LOW:
digitalWrite(cw,LOW);
//counter clockwise is LOW
digitalWrite(ccw,LOW);
}
If you won't answer my questions I don't see how I can help. I can't see your project so I can only rely on what you tell me.
And a diagram (a photo of a simple pencil drawing) showing all the connections will be much easier to understand than a verbal description. See this Simple Image Guide
So you've said what you want it to do. But you still haven't said exactly what it is doing now or what results you get from all those Serial.printlns. If you won't provide any useful information we can't help.