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.

Arduino Servo Motor Bluetooth

Hardware Required

1×Arduino UNO or Genuino UNO
1×USB 2.0 cable type A/B
1×HC-05 Bluetooth Module
1×(Alternative) HM-10 BLE Module
1×Servo Motor
1×Jumper Wires
1×(Optional) 9V Power Adapter for Arduino
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.
Arduino Servo Motor Bluetooth Wiring Diagram

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.
Arduino Servo Motor BLE Wiring Diagram

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

  • Install Bluetooth Serial Monitor App on your smartphone
  • Copy the provided code and open it with the Arduino IDE, then upload it to your Arduino board.
  • 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.
Bluetooth Serial Monitor App
  • Pair the app with the HC-05 Bluetooth module or HM-10 BLE module.
Bluetooth Serial Monitor pairing
  • Type in an angle value (e.g. 45 or 90) and click the Send button.
Bluetooth Serial Monitor App
  • You should see the Servo Motor's angle change.
  • Observe the results on the Android App.
Bluetooth Serial Monitor App

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.

Function References

The Best Arduino Starter Kit

※ OUR MESSAGES