- Bluetooth Controlled Servo
- This project shows how to control a servo motor with a smartphone via Bluetooth.
- Bluetooth Controlled Servo Motor using Arduino, HC-05 Bluetooth Module
- Introduction
- A Brief Note on Servo Motor and its Control
- Concept of Bluetooth Controlled Servo Motor using Arduino
- Circuit Diagram
- Components Required
- Circuit Design
- Servo Motor Control App
- Code
- Working
- Conclusion
- Arduino control Servo Motor via Bluetooth
- Hardware Required
- About Servo Motor and Bluetooth Module
- Wiring Diagram
- Arduino Code — controls Servo Motor via Bluetooth/BLE
- Quick Steps
- Video Tutorial
Bluetooth Controlled Servo
This project shows how to control a servo motor with a smartphone via Bluetooth.
Bluetooth controlled servo
this code id to uploaded on to the Arduino uno.
1#includeSoftwareSerial.h> 2#includeServo.h> 3Servo x; 4int bttx=9; //tx of bluetooth module is connected to pin 9 of arduino 5int btrx=10; //rx of bluetooth module is connected to pin 10 of arduino 6SoftwareSerial bluetooth(bttx,btrx); 7void setup() 8 9 x.attach(11); // servo is connected to pin 11 of arduino 10 Serial.begin(9600); 11 bluetooth.begin(9600); 12> 13void loop() 14 15 if(bluetooth.available()>0) //if bluetooth module is transmitting data 16 17 int pos=bluetooth.read(); // store the data in pos variable 18 Serial.println(pos); 19 x.write(pos); //move servo head to the given position 20 > 21> 22
Bluetooth controlled servo
this code id to uploaded on to the Arduino uno.
1#includeSoftwareSerial.h> 2#includeServo.h> 3Servo x; 4int bttx=9; 5 //tx of bluetooth module is connected to pin 9 of arduino 6int btrx=10; //rx 7 of bluetooth module is connected to pin 10 of arduino 8SoftwareSerial bluetooth(bttx,btrx); 9void 10 setup() 11 12 x.attach(11); // servo is connected to pin 11 of arduino 13 14 Serial.begin(9600); 15 bluetooth.begin(9600); 16> 17void loop() 18 19 if(bluetooth.available()>0) 20 //if bluetooth module is transmitting data 21 22 int pos=bluetooth.read(); 23 // store the data in pos variable 24 Serial.println(pos); 25 x.write(pos); 26 //move servo head to the given position 27 > 28> 29
Bluetooth Controlled Servo Motor using Arduino, HC-05 Bluetooth Module
In this project, I will show you how to implement a Bluetooth Controlled Servo Motor using Arduino. Using this project, you can control a servo motor like TowerPro SG90 or MG90S with the help of an App in an Android Smartphone over Bluetooth connection.
Introduction
I have used servo motors in several projects like the DIY Arduino & Bluetooth Robotic Arm, Web Controlled Servo using ESP8266, Arduino Joystick Interface to name a few. In fact, servo motors are one of the important components is projects where precise positioning is required.
In this project, as mentioned earlier, I will show you how to control a Servo Motor using Bluetooth. But before proceeding further into the details of Bluetooth Controlled Servo Motor using Arduino, there are a few important things to know like how a servo motor works and how can you control the position of the servo motor.
A Brief Note on Servo Motor and its Control
Servo Motors are basically DC Motors with additional circuitry that aid in achieving accurate positioning of the servo motor. In order to control the rotation of the servo motor’s shaft, you need a special signal called Pulse Width Modulation or PWM signal.
Based on the width of the pulse, the position of the servo motor varies. There are several ways in which you can generate the PWM Signal to control a Servo Motor. The traditional way is to use fully analog circuits like the 555 Timer IC and using a potentiometer to control the width of the pulse.
But with the help of microcontrollers like Arduino (ATmega328 to be precise), you can generate PWM Signals without any external components.
NOTE: If you want to test whether your Servo Motor is working or not, you can implement a simple design similar to the one I have used in the How to make a Simple Servo Motor Tester Circuit, where you don’t need any microcontrollers and programming to test the servo motor.
Concept of Bluetooth Controlled Servo Motor using Arduino
The main concept of the Bluetooth Controlled Servo Motor using Arduino project is very simple. Control the Servo Motor using PWM Signals generated by Arduino. The inputs to the Arduino are given from an Android Smart Phone over Bluetooth Communication.
Circuit Diagram
The circuit diagram of the project Bluetooth Controlled Servo Motor using Arduino is given below.
Components Required
- Arduino UNO
- HC-05 Bluetooth Module
- TowerPro SG90 Servo Motor
- Connecting Wires
- 5V Power Supply
- Breadboard
Circuit Design
The design of the circuit for controlling a Servo Motor using Arduino and Bluetooth is very easy. Connect the Control Pin of the Servo Motor to Pin 11 of Arduino. It is important that you connect the control pin to a PWM enabled pin of Arduino.
I will be using a Software Serial option of Arduino and hence Pins 2 and 3 of Arduino are fixed as RX and TX. So, connect the TX of the Bluetooth Module to RX (Pin 2) of Arduino.
Since the job of Bluetooth Module is to transfer data received from Phone and transmit it to Arduino, I have used only its TX Pin.
For more information on HC-05 Bluetooth Module and how to interface it with Arduino, please refer “Arduino HC-05 Bluetooth Module”.
Servo Motor Control App
I have used an App called “Servo Motor Kontrol” developed by “YSRGGS”. The layout of the app after connecting it to the Bluetooth Module is shown below.
As you can see, the app provides two ways in which you can control the servo motor: using dedicated buttons or using the slider.
Code
The code for the project Bluetooth Controlled Servo Motor using Arduino is given below.
# include |
# include |
Servo myservo; |
SoftwareSerial mySerial ( 2 , 3 ); // RX, TX |
int Position ; |
void setup () |
myservo. attach ( 11 ); |
mySerial. begin ( 9600 ); |
Serial. begin ( 9600 ); |
> |
void loop () |
if (mySerial. available ()> 0 ) |
Position = mySerial. read (); |
Position = map (Position, 0 , 180 , 180 , 0 ); |
myservo. write (Position); |
> |
> |
Working
The working of this project is very simple. Make the connections as per the circuit diagram and upload the code to Arduino. Then open the Servo Motor Kontrol App (assuming it is already installed in your Android Phone) and connect to the Bluetooth Module.
Once the connection is successful, you can control the servo motor either by adjusting the slider or by pressing any of the preset buttons.
Conclusion
A simple way to control your servo motor is demonstrated in this project. Using this project, you can control any servo motor using Arduino and a Bluetooth Module.
If you are a beginner, this project can be a beginning step towards implementing several complex Robotic Projects involving Servo Motors.
Arduino control Servo Motor via Bluetooth
In this tutorial, we will learn how to program an Arduino to control a Servo Motor using either Bluetooth (HC-05 module) or BLE (HM-10 module). Instructions for both modules are provided.
We will use the Bluetooth Serial Monitor App on smartphone to send the angle value to Arduino. Arduino will control the servo motor according to the received value.
Hardware Required
Or you can buy the following sensor kit:
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.
About Servo Motor and Bluetooth Module
If you are unfamiliar with Servo Motors and Bluetooth Modules, including their pinouts, functionality, and programming, please refer to the following tutorials for more information:
Wiring Diagram
To control a Servo Motor using Classic Bluetooth, use the HC-05 Bluetooth module, and refer to the wiring diagram provided below.
This image is created using Fritzing. Click to enlarge image
To control a Servo Motor using BLE, use the HM-10 BLE module, and refer to the wiring diagram provided below.
This image is created using Fritzing. Click to enlarge image
Arduino Code — controls Servo Motor via Bluetooth/BLE
The code provided below is compatible with both the HC-10 Bluetooth module and the HM-10 BLE module.
/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-controls-servo-motor-via-bluetooth */ // NOTE: change the Serial to other Serial/Software Serial if you connects Bluetooth module to other pins # include < Servo .h>Servo servo; // create servo object to control a servo int pos = 0; // variable to store the servo position void setup () < Serial . begin (9600); servo. attach (11); // attaches the servo on pin 11 to the servo object >void loop () < if ( Serial . available ()) < // if there is data comming int angle = Serial . parseInt (); if (angle >= 0 && angle <= 180) < servo. write (angle); // rotate servo Serial . print ( "Rotated servo to angle: " ); // reports action to smartphone app Serial . println (angle); >else < Serial . print ( "Invalid angle: " ); // reports invalid value to smartphone app Serial . println (angle); >> >=>
Quick Steps
If you have trouble uploading the code, try disconnecting the TX and RX pins from the Bluetooth module, uploading the code, and then reconnecting the RX/TX pins again.
Open the Bluetooth Serial Monitor App on your smartphone and select the Classic Bluetooth or BLE option, depending on the module you are using.
If the Bluetooth Serial Monitor app is useful for you, please give it a 5-star rating on Play Store. Thank you!
Video Tutorial
We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.