Hello all and thanks in advance.
If someone could help me with this I would be ecstatic. I just cant see what is wrong with my setup. As the title states. bluetooth servo... most of you are familiar with this and know how to set this up and maybe like me can make the apps thanks too MIT. Well I am trying to get servo's and control of a few output pins for simple stuff like led on/off. well, Ardudroid seems close. however if my limited knowledge serves me thats analog not pwm digital like i would need for a servo. Just pwm buttons, no slider and, would fry a servo.(pretty sure I have done this once already). I found his code too confusing to try to adapt to my needs. Found a few multi-servo apps w/code. None with additional options. I keep trying to merge a multi-servo bluetooth sketch with a simple bluetooth blink led sketch. I know its going to be something in the code. We can go over all my other setup options. readings and whatever else but, I know its the code. Im smart enough to know that. Just too stupid to fix it. I have been trying believe me. I just simply cannot find it!
heres the code:
#include <SoftwareSerial.h>
#include <Servo.h>
Servo myservo1, myservo2, myservo3, myservo4, myservo5, myservo6;
int bluetoothTx = 7;
int bluetoothRx = 8;
char junk;
String inputString="";
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{ myservo1.attach(9);
myservo2.attach(10);
myservo3.attach(11);
myservo4.attach(3);
myservo5.attach(5);
myservo6.attach(6);
Serial.begin(9600);
pinMode(13, OUTPUT);
bluetooth.begin(9600); }
void loop()
{ if(bluetooth.available()>= 2 )
{ unsigned int servopos = bluetooth.read();
unsigned int servopos1 = bluetooth.read();
unsigned int realservo = (servopos1 *256) + servopos;
Serial.println(realservo);
if (realservo >= 1000 && realservo <1180)
{ int servo1 = realservo;
servo1 = map(servo1, 1000,1180,0,180);
myservo1.write(servo1);
Serial.println("servo 1 ON");
delay(10); }
if (realservo >=2000 && realservo <2180)
{ int servo2 = realservo;
servo2 = map(servo2,2000,2180,0,180);
myservo2.write(servo2);
Serial.println("servo 2 On");
delay(10); }
if (realservo >=3000 && realservo < 3180)
{ int servo3 = realservo;
servo3 = map(servo3, 3000, 3180,0,180);
myservo3.write(servo3);
Serial.println("servo 3 On");
delay(10); }
if (realservo >=4000 && realservo < 4180)
{ int servo4 = realservo;
servo4 = map(servo4, 4000, 4180,0,180);
myservo4.write(servo4);
Serial.println("servo 4 On");
delay(10); }
if (realservo >=5000 && realservo < 5180)
{ int servo5 = realservo;
servo5 = map(servo5, 5000, 5180,0,180);
myservo5.write(servo5);
Serial.println("servo 5 On");
delay(10); }
if (realservo >=6000 && realservo < 6180)
{ int servo6 = realservo;
servo6 = map(servo6, 6000, 6180,0,180);
myservo6.write(servo6);
Serial.println("servo 6 On");
delay(10); }
if(Serial.available())
{ while(Serial.available())
{ char inChar = (char)Serial.read();
inputString += inChar; }
Serial.println(inputString);
while (Serial.available() > 0)
{ junk = Serial.read() ; }
if(inputString == "1")
{digitalWrite(13, HIGH); }
else if(inputString == "0")
{digitalWrite(13, LOW); }
inputString = "";
}
}
}
sure hope someone gets it... thanks.
If someone could help me with this I would be ecstatic. I just cant see what is wrong with my setup. As the title states. bluetooth servo... most of you are familiar with this and know how to set this up and maybe like me can make the apps thanks too MIT. Well I am trying to get servo's and control of a few output pins for simple stuff like led on/off. well, Ardudroid seems close. however if my limited knowledge serves me thats analog not pwm digital like i would need for a servo. Just pwm buttons, no slider and, would fry a servo.(pretty sure I have done this once already). I found his code too confusing to try to adapt to my needs. Found a few multi-servo apps w/code. None with additional options. I keep trying to merge a multi-servo bluetooth sketch with a simple bluetooth blink led sketch. I know its going to be something in the code. We can go over all my other setup options. readings and whatever else but, I know its the code. Im smart enough to know that. Just too stupid to fix it. I have been trying believe me. I just simply cannot find it!
heres the code:
#include <SoftwareSerial.h>
#include <Servo.h>
Servo myservo1, myservo2, myservo3, myservo4, myservo5, myservo6;
int bluetoothTx = 7;
int bluetoothRx = 8;
char junk;
String inputString="";
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{ myservo1.attach(9);
myservo2.attach(10);
myservo3.attach(11);
myservo4.attach(3);
myservo5.attach(5);
myservo6.attach(6);
Serial.begin(9600);
pinMode(13, OUTPUT);
bluetooth.begin(9600); }
void loop()
{ if(bluetooth.available()>= 2 )
{ unsigned int servopos = bluetooth.read();
unsigned int servopos1 = bluetooth.read();
unsigned int realservo = (servopos1 *256) + servopos;
Serial.println(realservo);
if (realservo >= 1000 && realservo <1180)
{ int servo1 = realservo;
servo1 = map(servo1, 1000,1180,0,180);
myservo1.write(servo1);
Serial.println("servo 1 ON");
delay(10); }
if (realservo >=2000 && realservo <2180)
{ int servo2 = realservo;
servo2 = map(servo2,2000,2180,0,180);
myservo2.write(servo2);
Serial.println("servo 2 On");
delay(10); }
if (realservo >=3000 && realservo < 3180)
{ int servo3 = realservo;
servo3 = map(servo3, 3000, 3180,0,180);
myservo3.write(servo3);
Serial.println("servo 3 On");
delay(10); }
if (realservo >=4000 && realservo < 4180)
{ int servo4 = realservo;
servo4 = map(servo4, 4000, 4180,0,180);
myservo4.write(servo4);
Serial.println("servo 4 On");
delay(10); }
if (realservo >=5000 && realservo < 5180)
{ int servo5 = realservo;
servo5 = map(servo5, 5000, 5180,0,180);
myservo5.write(servo5);
Serial.println("servo 5 On");
delay(10); }
if (realservo >=6000 && realservo < 6180)
{ int servo6 = realservo;
servo6 = map(servo6, 6000, 6180,0,180);
myservo6.write(servo6);
Serial.println("servo 6 On");
delay(10); }
if(Serial.available())
{ while(Serial.available())
{ char inChar = (char)Serial.read();
inputString += inChar; }
Serial.println(inputString);
while (Serial.available() > 0)
{ junk = Serial.read() ; }
if(inputString == "1")
{digitalWrite(13, HIGH); }
else if(inputString == "0")
{digitalWrite(13, LOW); }
inputString = "";
}
}
}
sure hope someone gets it... thanks.
Last edited: