In this tutorial, you will be able to create an application for controlling the direction of a servo motor. Using the slider in this application and move to servo motor from 0 degrees to-180 degree.
Digital pins 10 and 11 on your Arduino or Genuino boards are used as virtual RX and TX serial lines. The virtual RX pin is set up to listen for anything coming in on via the main serial line, and to then echo that data out the virtual TX line. Conversely, anything received on the virtual RX is sent out over the hardware TX.
Link for App: https://drive.google.com/open?id=186oV8xNKB57Vqw5C5E4YvYv7X2plCF0y
Link for Code: https://drive.google.com/open?id=186oV8xNKB57Vqw5C5E4YvYv7X2plCF0y
Link for aia: https://drive.google.com/open?id=186oV8xNKB57Vqw5C5E4YvYv7X2plCF0y
Link for Fritzing: https://drive.google.com/open?id=186oV8xNKB57Vqw5C5E4YvYv7X2plCF0y
Arduino Code:
#include <SoftwareSerial.h> // TX RX software library for bluetooth
#include <Servo.h> // servo library
Servo myservo; // servo name
int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
myservo.attach(9); // attach servo signal wire to pin 9
//Setup usb serial connection to computer
Serial.begin(9600);
//Setup Bluetooth serial connection to android
bluetooth.begin(9600);
}
void loop()
{
//Read from bluetooth and write to usb serial
if(bluetooth.available()> 0 ) // receive number from bluetooth
{
int servopos = bluetooth.read(); // save the received number to servopos
Serial.println(servopos); // serial print servopos current number received from bluetooth
myservo.write(servopos); // roate the servo the angle received from the android app
}
}