Servo motors are commonly used for precise rotational motion. The rotational motion can be directly utilized like in the speed dials of cars or converted to linear or translational motion with the help of gears. However, the servos may be used in a project, their precision of motion is their prime advantage. The angle of rotation of a servo can be acutely controlled to single degree of rotation. The servos are controlled by pulse width modulation technique. Usually, servos can rotate between angle 0° and 180°. Like if the pulse width applied to the control terminal of a servo be 2 milliseconds for which it rotates to 180°, then for a pulse width of 1 millisecond, it will rotate by 90°.
In lots of previous projects, servos have been controlled wirelessly through RF modules or other similar radio frequency modules. In this project, two servo motors will be controlled independently through Bluetooth interface. The control command will be passed from an android phone. The android phone will have Bluetooth Serial Control app which will transmit control characters to a receiver circuit. The receiver circuit has HC-05 Bluetooth module which will receive control characters serially through Bluetooth. The Bluetooth module and the android phone needs to be paired on the Bluetooth interface. The serially received characters will be read by a microcontroller board which will in turn generate PWM signal to control the servos.
The microcontroller board used in the project is Arduino Pro Mini. The Servos and the Bluetooth module are interfaced to the Arduino board. The Arduino sketch is written on the Arduino IDE and burnt to the board using AVR Dude.
Components Required –
1. Arduino Pro Mini
2. Servos – 2
3. HC-05 Bluetooth Module
4. Android Phone
Software Tools Required –
1. Arduino IDE
2. AVR Dude
3. Bluetooth Serial Control App
Circuit Connections –
Fig. 1: Prototype of Arduino and HC-05 Bluetooth Module based Wireless Servo Motor Controller
The entire circuit is built around the Arduino Pro Mini. The servos and the HC-05 Bluetooth module are interfaced to the Arduino in the following manner –
Power Supply – The circuit is powered by a battery which directly supplies to the Arduino board and the other modules.
HC-05 Bluetooth Module – HC-05 Bluetooth module is serial port protocol module. It operates on ISM band 2.4GHz with V2.0+EDR (enhanced data date). It can work in both Master and slave modes. The Bluetooth module has six pins – Enable, VCC, Ground, Transmit Data (TxD), Receive Data (RxD) and State. The Enable and State pin are unused and so not connected in the circuit. The VCC and Ground pins are connected to the common VCC and Ground. The TxD and RxD pins of the module are connected to the Rxd and Txd pins of the Arduino Pro Mini respectively. These connections are summarized in the table below –
Fig. 2: Table listing circuit connections between HC-05 Bluetooth Module and Arduino Pro Mini
Servos – The servo motors have three terminals – 1) VCC, 2) Ground and 3) Signal. These terminals are identified by colour codes. The VCC terminal is usually red or dark red colour, Ground terminal has Black wire out and Signal has white, yellow, orange or brown colour wire. This colour coding is summarized in the table below –
Fig. 3: Table listing color coding for terminals of servo motor
The VCC and Ground wires of the Servos are connected to the common VCC and Ground. The signal wire of one servo is connected to pin 9 of the Arduino Pro Mini and signal wire of the other Servo is connected to the pin 11 of the Arduino.
Android phone – The android phone connects with the circuit on Bluetooth. It should be paired with the Bluetooth module. The Bluetooth module used in this project had a Mac address of 05 20:15:01:30:17:25 for its unique identification and had a password 1234 for pairing. The other Bluetooth modules can have different unique Mac address and password. The Bluetooth Serial Control app should be installed and launched on the Android phone to pass serial commands to the receiver circuit.
How the circuit works –
Fig. 4: Image showing demonstration of Arduino and HC-05 Bluetooth Module based Wireless Servo Motor Controller
As the circuit is powered on, the Arduino sketch loads the required libraries and wait to get the command characters serially from the Bluetooth module. The Bluetooth module receive the command characters from the android phone which should be paired with the module. The command characters can be sent by typing them on the main activity of the Bluetooth Serial Monitor app. The Bluetooth module acts as a slave after pairing with the android phone. There are four pre-determined command characters to control the servos. If a user sends ‘A’, the first servo connected at the pin 9 of the Arduino rotates from 0° to 180° with the increment of 1° steps. If the user sends ‘B’, the servo connected at pin 9 of the Arduino rotates from 180° to 0° with the decrement of 1° steps. If a user sends ‘C’, the second servo connected at the pin 11 of the Arduino rotates from 0° to 180° with the increment of 1° steps. If the user sends ‘D’, the servo connected at pin 11 of the Arduino rotates from 180° to 0° with the decrement of 1° steps.
The one degree long steps of the servo are realized through appropriate PWM signal which is generated by the standard library functions of the Arduino. The Arduino sketch reads the serially transferred characters and execute the increment or decrement of servo angles for the two motors independently in while loops.
Check out the project code to learn how serial data is fetched from the Bluetooth module and used to control servos programmatically.
Programming Guide –
The Arduino sketch imports the Servo.h to include standard functions and methods for controlling servo motors. For controlling two servos, two objects of Servo class are instantiated and a variable to hold servo angle is declared.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
Servo servo; // a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
The setup() function is called in which the baud rate for serial communication with the Bluetooth module is set to the 9600 bits per second.
The servo objects are assigned to the pins connecting servo motors using the attach() method on the respective objects.
The loop() function is called in which a variable of character type is declared to hold the serially received command character. The serial port is checked if any character is received and if it is available, it is stored in the variable Data. The serially received control character is compared with the characters ‘A’, ‘B’, ‘C’ and ‘D’. According to the character received, the servo steps are incremented or decremented by one and executed using the write() method on either of the servo object. The loop is exited by calling break statement when the maximum or minimum rotational angle is reached.
Note: Refer to the Code section for the complete programming details.
This completes the Arduino sketch for the Bluetooth Controlled Servo Motors Project.
Project Source Code
###//Program to
#include <Servo.h> Servo myservo; // create servo object to control a servo Servo servo; // a maximum of eight servo objects can be created int pos = 0; // variable to store the servo position void setup() { Serial.begin(9600); myservo.attach(9); // attaches the servo on pin 9 to the servo object servo.attach(11); pinMode(12,INPUT); //myservo.write(0); //servo.write(0); } void loop(){ int trigger = digitalWrite(12); //serial port initilization. char Data; if (Serial.available()) { Data = Serial.read(); Serial.println(Data); while(Data == 'A') { pos +=1; Data = Serial.read(); myservo.write(pos); if(pos == 180) { break; } } while(Data == 'B') { pos -=1; Data = Serial.read(); myservo.write(pos); if(pos == 0) { break; } } while(Data == 'C') { pos +=1; Data = Serial.read(); servo.write(pos); if(pos == 180) { break; } } while(Data == 'D') { pos -=1; Data = Serial.read(); servo.write(pos); if(pos == 0) { break; } } } }###
Project Video
Filed Under: Electronic Projects
Filed Under: Electronic Projects
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.