I'm trying to build Bluetooth RC car, but I can't run only one DC motor.. only both of them. Everything works fine, the bluetooth, the app but when i try to go forward/backward/left/right nothing happens, only when i run both of them. I'm running the Arduino Nano with usb cable. The bluetooth connection is stable, The DC motors are working. I don't know what I'm doing wrong. Thanks!
const int AIA = 2;
const int AIB = 3;
const int BIA = 4;
const int BIB = 5;
byte vSpeed = 255;
int state;
void setup() {
pinMode(AIA, OUTPUT);
pinMode(AIB, OUTPUT);
pinMode(BIA, OUTPUT);
pinMode(BIB, OUTPUT);
// Initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop() {
//Save income data to variable 'state'
if(Serial.available() > 0){
state = Serial.read();
}
/***********************Forward****************************/
//If state is equal with letter 'F', car will go forward!
if (state == 'F') {
analogWrite(AIA, vSpeed);
analogWrite(AIB, 0);
analogWrite(BIA, 0);
analogWrite(BIB, 0);
}
/**********************Forward Left************************/
//If state is equal with letter 'G', car will go forward left
else if (state == 'G') {
analogWrite(AIA, vSpeed);
analogWrite(AIB, 0);
analogWrite(BIA, vSpeed);
analogWrite(BIB, 0);
}
/**********************Forward Right************************/
//If state is equal with letter 'I', car will go forward right
else if (state == 'I') {
analogWrite(AIA, vSpeed);
analogWrite(AIB, 0);
analogWrite(BIA, 0);
analogWrite(BIB, vSpeed);
}
/***********************Backward****************************/
//If state is equal with letter 'B', car will go backward
else if (state == 'B') {
analogWrite(AIA, 0);
analogWrite(AIB, vSpeed);
}
/**********************Backward Left************************/
//If state is equal with letter 'H', car will go backward left
else if (state == 'H') {
analogWrite(AIA, 0);
analogWrite(AIB, vSpeed);
analogWrite(BIA, vSpeed);
analogWrite(BIB, 0);
}
/**********************Backward Right************************/
//If state is equal with letter 'J', car will go backward right
else if (state == 'J') {
analogWrite(AIA, 0);
analogWrite(AIB, vSpeed);
analogWrite(BIA, 0);
analogWrite(BIB, vSpeed);
}
/***************************Left*****************************/
//If state is equal with letter 'L', wheels will turn left
else if (state == 'L') {
analogWrite(BIA, vSpeed);
analogWrite(BIB, 0);
}
/***************************Right*****************************/
//If state is equal with letter 'R', wheels will turn right
else if (state == 'R') {
analogWrite(BIA, 0);
analogWrite(BIB, vSpeed);
}
/************************Stop*****************************/
//If state is equal with letter 'S', stop the car
else if (state == 'S'){
analogWrite(AIA, 0);
analogWrite(AIB, 0);
analogWrite(BIA, 0);
analogWrite(BIB, 0);
}
}
analogWrite()
calls ? – J. Piquard Nov 27 '16 at 19:19