Today we will attempt to take over the world by building a smartphone Bluetooth controlled pan and tilt platform.
Check us out on Facebook!
The APP:
Click Here to download the APP
ARDUINO Code:
#include <Servo.h>
Servo servo1;
Servo servo2;
void setup() {
Serial.begin(9600);
servo1.attach(3); //servo 1
servo1.write(90);
servo2.attach(5); //servo 2
servo2.write(90);
}
void loop() {
if (Serial.available() >= 2 )
{
unsigned int a = Serial.read();
unsigned int b = Serial.read();
unsigned int val = (b * 256) + a;
if (val >= 0 && val <= 180) // servo 1
{
val=map(val,0,180,180,0);
servo1.write(val);
}
else if (val >= 1000 && val <= 1180) // servo 2
{
val=map(val,1000,1180,1180,1000);
servo2.write(val-1000);
}
}
}