Hello! This is my second post on this forum, so I wanted to thank you for the help for the previous problem. This time I'm creating a bluetooth car with hc-05 model and a motor shield l293D. I think that my code is fine because functions are working when I type through the serial monitor. However, it's not working with a bluetooth. HC-05 is successfully conected but when I send the commands, nothing happens. I tried HC-05 with a LED and it was working, but with motors it doesn't work. I also tried diffrent apps, but it's the same. Does anyone knows what could be wrong? Here's the code:
#include <AFMotor.h>
int g;
AF_DCMotor motora(1);
AF_DCMotor motorb(2);
AF_DCMotor motorc(3);
AF_DCMotor motord(4);
void setup()
{
Serial.begin(9600);
motora.setSpeed(70);
motorb.setSpeed(70);
motorc.setSpeed(70);
motord.setSpeed(70);
}
void loop() {
if(Serial.available()>0){
g = Serial.read();
if(g=='0'){
motora.run(FORWARD);
motorb.run(FORWARD);
motorc.run(FORWARD);
motord.run(FORWARD);
}
else if(g=='1'){
motora.run(BACKWARD);
motorb.run(BACKWARD);
motorc.run(BACKWARD);
motord.run(BACKWARD);
}
else if(g=='2'){
motora.run(RELEASE);
motorb.run(RELEASE);
motorc.run(RELEASE);
motord.run(RELEASE);
}
}
}