How To Build A ARDUINO Bluetooth Joystick to control your robot Part 1

This tutorial will show you how to build a Bluetooth joystick to control your robot or other ARDUINO projects..

click on video below for full tutorial…

https://youtu.be/9OlceW1W1yU://

 

Arduino code for master board:

int joy1;
//int joy2;
int val;
#define button 3
void setup() {
Serial.begin(9600);
pinMode(button, INPUT);
}

void loop() {
val = digitalRead(button);
if (val == HIGH)
{
Serial.write(200);
delay(500);
}
joy1 = analogRead(A2);
joy1 = map(joy1,0,1023,5,175);
Serial.write(joy1);
delay(10);

//Serial.println(joy1); // for testing
}

 

Arduino code for slaveĀ board:

 

#include <Servo.h>
Servo s1; // name servo 1

#define led 2 // led on pin D2
int pos = 0; // button pos
int val; //val from bluetooth
void setup() {
Serial.begin(9600);
s1.attach(3); // attach servo to pin D3

pinMode(led, OUTPUT);

}

void loop() {
if (Serial.available() > 0)
{
val = Serial.read();
if (val == 200 && pos == 0)
{
digitalWrite(led, HIGH);
pos = 1;
}
else if (val == 200 && pos == 1)
{
digitalWrite(led, LOW);
pos = 0;
}
else if (val >= 0 && val <= 175)
{
s1.write(val);

}
}

}