I made an RC car that was controlled with a phone, but I have a little problem. It was working without the ENA pins. But when I added the ENA pins is stops working. I found out that the problem is with Bluetooth. Because it connects to my phone but it doesn't send data. When I remove
pinMode(pmwa, OUTPUT);
pinMode(pmwb, OUTPUT);
It works again but I didn't come up with how I Can fix it. This is the code
#include <SoftwareSerial.h>
#define RxD 6
#define TxD 7
#define in1 9
#define in2 8
#define in3 10
#define in4 11
#define pmwa 5
#define pmwb 6
SoftwareSerial blueToothSerial(RxD,TxD);
void setup()
{
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
setupBlueToothConnection();
pinMode(pmwa, OUTPUT);
pinMode(pmwb, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
void loop()
{
char recvChar;
while(1){
if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
recvChar = blueToothSerial.read();
Serial.print(recvChar);
}
if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
recvChar = Serial.read();
blueToothSerial.print(recvChar);
}
}
if (recvChar == 'F'){
forward();
}
else if (recvChar == 'S'){
off();
}
else if (recvChar == 'L'){
left();
}
else if (recvChar == 'R'){
right();
}
else if (recvChar == 'G'){
back();
}
else if (recvChar == 'Q'){
leftfor();
}
else if (recvChar == 'E'){
rightfor();
}
else if (recvChar == 'Z'){
leftback();
}
else if (recvChar == 'C'){
rightback();
}
delay(100);
}
}
void setupBlueToothConnection()
{
blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
blueToothSerial.print("\r\n+STNA=CrowBTSlave\r\n"); //set the bluetooth name as "CrowBTSlave"
blueToothSerial.print("\r\n+STPIN=0000\r\n");//Set SLAVE pincode"0000"
blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
Serial.println("The slave bluetooth is inquirable!");
delay(2000); // This delay is required.
blueToothSerial.flush();
}
void forward(){
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(pmwa, 250);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(pmwb, 250);
}
void off(){
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
analogWrite(pmwa, 0);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
analogWrite(pmwb, 0);
}
void left(){
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(pmwa, 150);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(pmwb, 150);
}
void right(){
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
analogWrite(pmwa, 150);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(pmwb, 150);
}
void back(){
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
analogWrite(pmwa, 200);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(pmwb, 200);
}
void leftfor(){
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(pmwa, 250);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(pmwb, 150);
}
void rightfor(){
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(pmwa, 150);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(pmwb, 250);
}
void leftback(){
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
analogWrite(pmwa, 250);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(pmwb, 150);
}
void rightback(){
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
analogWrite(pmwa, 150);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(pmwb, 250);
}
Can you help me? Thanks