/** * @file How To Control a Servo Motor With a Bluetooth Module, Arduino and Android * @author Calin Dragos for intorobotics.com * @version V1.0 * @date 13.12.2016 * @description This is an Arduino sketch to control the servo motor SG90 with the Bluetooth module HC-06 and the Arduino Bluetooth Controller application */ #include #include SoftwareSerial mySerial(10, 11); // RX | TX Servo servo; int servoPin = 9; int servoAngle = 0; // servo position in degrees char command; void setup() { Serial.begin(9600); mySerial.begin(9600); Serial.println("You're connected via Bluetooth"); servo.attach(servoPin); } void loop() { if (mySerial.available()) { command=(mySerial.read()); if (command=='1') { Serial.println("Servo motor to 10 degrees"); servo.write(10); delay(500); } else if (command=='2') { Serial.println("Servo motor to 120 degrees"); servo.write(120); delay(500); } } }