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]