I send a command to move the servo through Android, then the servo sends the position to Android via Bluetooth. How to read the servo position and send it to Android for a TextView?
This is the code I use. Value 100 to turn on and 150 to turn off the led because 1-90 is used for servo. How to post servo position when first connected with Android?
#include <SoftwareSerial.h>
#include <Servo.h>
Servo servo;
int bluetoothTx = 10;
int bluetoothRx = 11;
int data ;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
pinMode(13, OUTPUT);
servo.attach(9);
bluetooth.begin(9600);
delay(100);
}
void loop()
{
if(bluetooth.available() > 0)
{
data = bluetooth.read();
int servopos;
int servopos1;
servopos = data;
servopos1 = data + 9;
if(data == 100){
digitalWrite(13, HIGH);
}else if(data == 150){
digitalWrite(13, LOW);
}else if (data > 100){
Serial.println(servopos);
servo.write(' ');
}else if (data < 100){
Serial.println(servopos);
servo.write(servopos1);
}
}
}