Introduction: How to Control a Servo Motor With a Bluetooth Module, Arduino and Android

About: I write about autonomous, outdoor and Internet connected robots. Also, I build some of them.

Servo motors are largely used in robotics for precise control. Anyone – well, almost anyone – has mobile devices with Bluetooth connection capabilities. In this tutorial, you will find how to wirelessly control a servo motor with an Arduino UNO and an Android device via a Bluetooth connection. In the end, you will be more connected, you will make things easier and control servo motors at the touch of a touchscreen.

In this article, I will introduce you to Bluetooth connections with the HC-06 Bluetooth module, Arduino UNO, and the SG90 servo motor. Also, you need extra resources for this tutorial such as an Android smartphone with Bluetooth capabilities and an application to send commands from smartphone to the Bluetooth module.

In the first part of the tutorial, I will show you how to hook up the HC-06 Bluetooth module to the Arduino. In the second part, you can find the source code to enter in AT command mode of the HC-06 Bluetooth module. Here you’ll set the name of your device, password, and the baud rate of the HC-06 module. Finally, in the last part, you will see how to setup the Android application and how to program Arduino to turn the servo motor at the touch of a button.

Step 1: Requirements

Connect the right pieces and make them communicate with each other. This is the plan of this project. If you already have all the below parts or a part of them, you are lucky. The whole project will cost you nothing, or a few dollars in case you will buy only the missing parts. Otherwise, you have to spend tens of dollars to buy the servo motor, the Bluetooth module, the development board and few other accessories. To have a clear view of the costs, in the right side of each part and accessory used in this project is a link to an online store. Here are the parts:

Step 2: Setting Up the Hardware

In this section, I will show you how to wire the Arduino UNO and the HC-06 Bluetooth module.

To use the HC-06 module, simply connect the VCC pin to the 3.3V output on the Arduino, the GND pin to any of Arduino GND pins, then connect the TX pin of the Bluetooth module to pin 10 of Arduino UNO and RX pin of Bluetooth to pin 11 of Arduino.

For servo motor, connect the brown wire to any of Arduino GND pins, the red wire from the SG90 servo to the 5V output of the Arduino, and the orange wire from the servo motor to digital pin 9 of Arduino.

Step 3: Arduino Sketch and AT Commands

If the Bluetooth module is being used for the first time, you have to interrogate it to change some of the settings. The settings are changed with so-called AT commands.

The HC-06 module allows you to change a limited number of settings. You can change the name of the device, the PIN, and the baud rate. You have to run the below AT commands in the IDE used with Arduino. These commands show you the version of firmware installed on the HC Bluetooth module, change the PIN, change the name of the module, and set the baud rate at 9600.

Please check the "Setup the HC-06 Bluetooth module" file.

Step 4: The Android Application and the Arduino Sketch

We’re very close to wirelessly control the SG90 servo motor with an Android smartphone. This is usually done by using an Android application that enables the Bluetooth features of the device.

From many applications that enable the Bluetooth features on Android devices, I choose the Arduino Bluetooth Controller application because is free and easy to use.

Before running the Android application, you make sure that the HC-06 Bluetooth module is up and running.

After the application is installed on your device, you have to scan for devices, enter the PIN number set with the script above, and connect the Bluetooth module.

For this tutorial, I use the “Controller Mode” for commands.

After the Android application setup is finished, we have to turn back to the Arduino and upload the code to control the servo motor. Below is the Arduino sketch to turn the servo motor at a specific position.

Please check the "Arduino sketch to control the servo motor SG90 with the Bluetooth module HC-06 and the Arduino Bluetooth Controller application" file.

If you follow the above steps, things just work!