Hello,
This is my first time here, I hope I am posting at the right place. I have searched this problem for a few weeks on internet but have not found anything like it
I am trying to build a very simple RC bluetooth car with an arduino nano, two dc motors, motor driver L9110, bluetooth HC-05 and an app created from App Inventor.
Everuthing works fine for the fist 1-2 minutes, after that for some unknow reason the serial input signal from the HC-05 gets "stock" and repeats the same value all the time no matter what the phone/app is sending. The only way to get it back to work is to turn off the phone bluetooth, turn it on and reconnect to the HC-05.
Here the copy of the code:
int lefA = 5;
int lefB = 6;
int rigA = 9;
int rigB = 10;
int vel1 = 255;
int state = 'a';
void setup() {
Serial.begin(9600);
pinMode(rigA, OUTPUT);
pinMode(rigB, OUTPUT);
pinMode(lefA, OUTPUT);
pinMode(lefB, OUTPUT);
}
void loop() {
if(Serial.available()>0){
state = Serial.read();
}
if(state=='a'){
analogWrite(rigA, 0);
analogWrite(rigB, 0);
analogWrite(lefA, 0);
analogWrite(lefB, 0);
Serial.println(state);
}
if(state=='b'){
analogWrite(rigA, vel1);
analogWrite(rigB, 0);
analogWrite(lefA, 0);
analogWrite(lefB, 0);
Serial.println(state);
}
if(state=='d'){
analogWrite(rigA, vel1);
analogWrite(rigB, 0);
analogWrite(lefA, vel1);
analogWrite(lefB, 0);
Serial.println(state);
}
if(state=='f'){
analogWrite(rigA, 0);
analogWrite(rigB, 0);
analogWrite(lefA, vel1);
analogWrite(lefB, 0);
Serial.println(state);
}
if(state=='h'){
analogWrite(rigA, 0);
analogWrite(rigB, vel1);
analogWrite(lefA, 0);
analogWrite(lefB, vel1);
Serial.println(state);
}
Thank you for your help
