bluetooth communication between two arduino boards

I need to control a BLDC motor using bluetooth communication between two arduino boards.

In Master side Joystick and one switch (for brake) connected to arduino uno

At Slave side i need to have 0-5Volts to motor controller according to joystick movement and at the brake button should provide on /off signal to brake of the motor during joystick movement.

joystick information and switch state should transfer simultaneously to slave through Bluetooth module.

In slave side I connected Arduino Due for DAC output and LED to know the brake status. If the program is success then I will connect the LED pin output to relay.

Now Iam receiving the variable output in DAC according to Joystick movement.
But brake status not receiving in slave side.

Can you pl. guide me how to get the information of the brake status and joystick info to slave simulataneously.

[code]for MASTER

#include <SoftwareSerial.h>
#define brake 9

SoftwareSerial BTSerial(10, 11);
int potValue = 0;
int brakeState=0;

void setup()
{ 
  pinMode(brake,INPUT);
  Serial.begin(38400);
  BTSerial.begin(38400);
}
void loop() {
 
 brakeState=digitalRead(brake);
 
 if(brake==HIGH)
 BTSerial.write('1');
 else
 BTSerial.write('0');
  int potValue = analogRead(A0);
  BTSerial.println(potValue);
 
  delay(100);
}

[/code]

[code] for SLAVE

#define BTSerial Serial3
#define led 12
int brakestate =0;

void setup() {
  pinMode(led,OUTPUT);
  digitalWrite(led,LOW);
  Serial.begin(38400);
  analogWriteResolution(10);
  analogReadResolution(10);
  Serial.println("Enter your commands:");
  BTSerial.begin(38400);
}


void loop() {
  if(BTSerial.available()>0)
  brakestate= BTSerial.read();
  if(brakestate=='1')
  digitalWrite(led,HIGH);
  
  if(brakestate=='0')
   digitalWrite(led,LOW);
  
 int output=BTSerial.parseInt();
  analogWrite(DAC0, output);
}

[/code]

send and receive can't be synchronised. So your receiver-code might be at parseint while your sender code is sending the brake-byte

You have to use start and endmarkers and an indicating byte so your receiver-code can identify and distinguis if the received byte is for brake or for throttle.

indicating byte "B" (like brake) and may "P" like PotValue

so the commands you send look like
for brake

and etc. for the potvalue

read the serial input basics how to do that
https://forum.arduino.cc/index.php?topic=396450

best regards Stefan

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.