I am making an RC car with hc-05 but hc-05 doesn't always take input so motors don't turn on. The problem isn't with the circuit because the motors turn on when I don't use if(). in Serial Monitor I see the number I sent from my phone but there is no text "forward".
here is my code:
#include <SoftwareSerial.h>
SoftwareSerial EEBlue(2, 3); // RX | TX
const int forwardPin = 8; //motor1_m
const int backwardPin = 12; //motor1_p
void setup()
{
Serial.begin(9600);
EEBlue.begin(9600); //Default Baud for comm, it may be different for your Module.
Serial.println("The bluetooth gates are open.");
pinMode(forwardPin,OUTPUT);
pinMode(backwardPin,OUTPUT);
pinMode(forwardPin2,OUTPUT);
pinMode(backwardPin2,OUTPUT);
}
void loop()
{
// Feed any data from bluetooth to Terminal.
if (EEBlue.available()){
Serial.write(EEBlue.read());
if(EEBlue.read() == 1){
Serial.println("forward");
digitalWrite(8, HIGH);
digitalWrite(12, LOW);
}
}
// Feed all data from termial to bluetooth
if (Serial.available()){
EEBlue.write(Serial.read());
}
}
I found most of this code online and do not claim it as my own.