In this tutorial, we will control a Servo Motor with an Android device through Bluetooth Module HC-05. The instructions from the app of Android device will be sent to Bluetooth Module HC-05 which in turn will rotate the Servo Motor 0-180 degrees upon the instructions given to it from the App of Android Phone.
What is a Servo Motor?A Servo is a small device that has an output shaft. This shaft can be positioned to specific angular positions by sending the servo a coded signal. As long as the coded signal exists on the input line, the servo will maintain the angular position of the shaft. As the coded signal changes, the angular position of the shaft changes.
In practice, servos are used in radio controlled airplanes to position control surfaces like the elevators and rudders. They are also used in radio controlled cars, puppets, and of course, robots.
What Is an HC-05 Bluetooth Module?Bluetooth can operate in the following two modes:
- Command Mode
- Operating Mode
In Command Mode, we will be able to configure the Bluetooth properties like the name of the Bluetooth signal, its password, the operating baud rate, etc.
The Operating Mode is the one in which we will be able to send and receive data between the PIC microcontroller and the Bluetooth module.The module works on 5V supply and the signal pins operate on 3.3V, hence a 3.3V regulator is present in the module itself.
The standard HC-05 Bluetooth module has six pins. However, we will only be using only four pins in this project. The pins we will be using are the VCC pin, the GND pin, the TXD pin, and the RXD pin.
1. SURILLI GSM.
2. BLUETOOTH MODULE HC-05.
3. SERVO MOTOR.
4. CONNECTING WIRES.
5. ARDUINO IDE.
6. ANDROID DEVICE.
7. APP (SERVO CONTROL).
CONNECTIONS BETWEEN SURILLI GSM, BLUETOOTH MODULE HC-05 AND SERVO MOTOR:RED +5V PIN (SERVO MOTOR) ---> USB PIN (SURILLI GSM).
BROWN GND PIN (SERVO MOTOR) ---> GND PIN (SURILLI GSM).
ORANGE PWM PIN (SERVO MOTOR) ---> PIN 9 (SURILLI GSM).
+5V PIN (BLUETOOTH MODULE HC-05) ---> USB PIN (SURILLI GSM).
GND PIN (BLUETOOTH MODULE HC-05) ---> GND PIN (SURILLI GSM).
TX PIN (BLUETOOTH MODULE HC-05) ---> PIN 10 (SURILLI GSM).
RX PIN (BLUETOOTH MODULE HC-05) ---> PIN 11 (SURILLI GSM).
STEP 1: Setup Arduino IDE for SurilliMake sure you have selected the right port, board and processor for the Surilli as shown in the picture below and it is programmable (compile and upload “Blink” from File>Examples>Digital>Blink onto your Surilli to check if everything is working fine).
STEP 2: The circuitry:The circuitry is very simple. It's mostly the programming and your logic behind a servo that matters. Still, follow the figure below to setup your hardware.
Now you have completed setting up your hardware and Arduino IDE. Copy and paste the Arduino sketch given below into your Arduino IDE and hit upload.
Digital pins 10 and 11 on Surilli GSM 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.
Important Instructions:- Before uploading the code, remove the VCC cable from bluetooth module.
- If you use HC-05 bluetooth module, it will ask the PIN to you. Usually 1234.
- If you get an error similar to (ERROR 507 or 516 broken pipe) please try to connect a few times. Sometimes connection will be broken.
- Make sure that your Surilli GSM is attached to your computer via USB to enable serial communication through the serial monitor window of the Arduino Software (IDE).
- Include SoftwareSerial library: (The SoftwareSerial library has been developed to allow serial communication on other digital pins of the Arduino, using software to replicate the functionality (hence the name "SoftwareSerial").
#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); // rotate the servo the angle received from the android app
}
}
ANDROID APPLICATIONCREATION:
- Create your application with MIT App inventor.
- The link for downloading MIT App Inventor software for creating android apps is as follows:
http://appinventor.mit.edu/explore/
- After completing the Program in MIT app inventor, go to Build and select App( save.apk to my computer)
- Transfer the file to your android mobile phone or tablet.
- Go to setting in your android mobile; select security and device administration and give access to allow install application from unknown sources.
Play with the program to see how it reacts to different values and logic. This will develop your understanding about servos so you can use them in your practical application.
If you make something fun and interesting do share it with our community :)
That’s all for now. If you have any queries, visit surilli.io or contact our support. Stay connected with Surilli family for more amazing stuff :)
Comments