rc car using arduino uno, joystick and bluetooth

i want to make rc car using joystick. so i programmed like this but slave arduino doesn't recieve the data. Two bluetooth module is pairing and master arduino has accurate joystick's data. i don't know why it doesn't work. please help me.

MASTER PROGRAM

#include<SoftwareSerial.h>
SoftwareSerial btSerial(2,3);
const int udlow = 300;
const int udhigh = 450;
int ud;
int lr;
char lrdirection;
void setup() {
  // put your setup code here, to run once:
btSerial.begin(9600);
Serial.begin(9600);
}

void loop() {
  lrdirection = 0;
  uddirection = 0;
  ud=analogRead(0);
  lr=analogRead(1);
    if(ud>udhigh){
      lrdirection='1';
      Serial.println(lrdirection);
          delay(100);
            btSerial.write(lrdirection);
    }
    else if(ud<udlow){
      lrdirection='2';
            Serial.println(lrdirection);
            btSerial.write('lrdirection');
    delay(100);
    }
      else {
        uddirection='3';
              btSerial.write(lrdirection);
      Serial.println(lrdirection);
      delay(100);
      }
    }

SLAVE PROGRAM

#include<SoftwareSerial.h>
SoftwareSerial btSerial(2,3);
int in1x = 10;  
int in2x = 4;  
int in3x = 5;
int in4x = 6;
int enAx = 11;
int enBx = 7;
char buffer[20];
char bufferindex=0; 
void setup() {
  pinMode(in1x, OUTPUT); 
  pinMode(in2x, OUTPUT); //각 포트 출력으로 사용
  pinMode(in3x, OUTPUT);
  pinMode(in4x, OUTPUT);
  btSerial.begin(9600); 
 Serial.begin(9600);//시리얼모니터 사용
  // put your setup code here, to run once:

}

void loop() {
  while(btSerial.available()){
      buffer[bufferindex]=btSerial.read();
      bufferindex++;}
     int indata=atoi(buffer); 
    //입력된 데이터 in_data에 저장
    if(indata!=0) { 
     Serial.println(indata);}
    delay(100);
    for(int a=0; a<21;a++){
      buffer[a]=NULL;
    }
    bufferindex=0;
    if(indata == '1')    //입력된 데이터가 '1'이라면x축 앞으로(FORWARD)
    { 
      digitalWrite(in1x, HIGH);
      digitalWrite(in2x, LOW);
      digitalWrite(in3x, HIGH);
      digitalWrite(in4x, LOW);
     analogWrite(enAx,255);
     analogWrite(enBx,255);//앞으로 회전
    }
    else if(indata == '2') //입력된 데이터가 '2'라면x축 뒤로(BACK)
    { 
      digitalWrite(in1x, LOW);
      digitalWrite(in2x, HIGH);
      digitalWrite(in3x, LOW);
      digitalWrite(in4x, HIGH);
     analogWrite(enAx,255);
      analogWrite(enBx,255);//뒤로 회전 (어떤 방향으로 꽂았느냐에 따라서 방향 반대)
    }
 else if(indata == '3')//정지(STOP)
   {
    digitalWrite(in1x, LOW);
    digitalWrite(in2x, LOW);
    digitalWrite(in3x, LOW);
    digitalWrite(in4x, LOW);
  // put your main code here, to run repeatedly:

}}

What IS the transmitter sending? What IS the receiver receiving?

i change the analogdata of joystick to digital data. so i send this digital data like 1,2,3. and slave recieve this data if the data is 1, the rc car move forward.

Pairing is not enough. You also need to bind the modules together using AT commands and the address of the slave BT module. I’ve done this for a remote control Arduino tank - it is possible.

Also, do you have BOTH an HC-05 (master) and HC-06 (slave)?

Google “Martyn Curry Bluetooth” for some really good tutorials.

arduino uno sends the data which can get joystick for example if x axis>500, uno sends the number1 and arduino mega 2560 receives data. but it doesn't receive data. Serial monitor comes out only -1. i don't know why arduino mega doesn't receive data .

master(uno)

#include<SoftwareSerial.h>
SoftwareSerial btSerial(2,3);
const int udlow = 300;
const int udhigh = 450;
const int lrlow = 300;
const int lrhigh = 450;
int ud;
int lr;
void setup() {
  // put your setup code here, to run once:
btSerial.begin(9600);
Serial.begin(9600);
}

void loop() {
  ud=analogRead(0);
  lr=analogRead(1);
    if(ud>udhigh){
          delay(100);
            btSerial.write('1');
    }
    else if(ud<udlow){
      btSerial.write('2');
    delay(100);
    }
   else if(lr>lrhigh){
         btSerial.write('3');
    delay(100);
    }
    else if(lr<lrlow){
          btSerial.write('4');
      delay(100);}
      else {
        btSerial.write('5');
           delay(100);
      }
    }

slave(mega)

#include<SoftwareSerial.h>
SoftwareSerial btSerial(10,11);
void setup() {
  Serial.begin(9600);
  btSerial.begin(9600);
  // put your setup code here, to run once:

}

void loop() {Serial.println(btSerial.read());
delay(100);
  // put your main code here, to run repeatedly:

}

i don't use hardware Serial. because it doesn't work well. so i use softwareSerial

Hi, I recently had a problem like no communication with Bluetooth module and found my Bluetooth module, instead of the usual 9600bps, came from the supplier rated 38400bps.

After trying everything I decided to check data rate, just in case, and found this was the case.

Hope it helps

Paulo

i change bps but it doesn't work too...

Hi,

I have tried each one of the possible serial bps speeds to find the one I mentioned.
I also had problems with the BT terminal software, I had to try a couple before I found a good one.
Do not mind the text, it is just a test to see if things work, focus on the LED connected to Pin10. (3 will switch the led ON 0 will turn it off)

My test code was as follow:

#define Led3Pin 10

String readString;
char c;

void setup() {
Serial.begin(9600);
Serial.println("OK then, you first, say something.....");
Serial.println("");
pinMode(Led3Pin, OUTPUT);
Serial3.begin(38400);
}

void loop() {
//String val;
char charBuf[1];
int val;

while (Serial3.available()) {
delay(3);
c = Serial3.read();
readString += c;
}

if(readString.substring(4,0) == "HELP" || readString.substring(4,0) == "help"){
Serial3.println("Help selected:");
Serial3.println("1- Acertar a data: setdate=DD/MM/AAAA,HH:MM,W");
Serial3.println("2- Consumo: MM/AAAA");
Serial3.println("3- Limpa arquivos CSV da memória: clearcsv");
Serial3.println(" ");
} else {

if (readString.length() >0) {
readString = readString.substring(1,0);

switch (readString.toInt()) {
case 3:
digitalWrite(Led3Pin, HIGH);
break;
case 0:
digitalWrite(Led3Pin, LOW);
break;
}

Serial3.println(readString);

}

}
readString="";
}

It works fine for my test.
Hope it helps.
Paulo

haeyoung:
i don't use hardware Serial. because it doesn't work well. so i use softwareSerial

Really. And he does it on a Mega too.....

@haeyoung, do not cross-post. Threads merged.

i'm sorry but the problem and question is generated one by one. so i don't think i do cross post. i'm sorry and care caution