How To Control a Servo Motor With a Bluetooth Module, Arduino and Android

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.

You may be interested in the following related posts:

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.

Probably the best four books about Arduino and Bluetooth connections:

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:

  • 1 X Arduino UNO (Amazon) – the Bluetooth module is compatible with almost any Arduino model, but all the code and schematics in this tutorial are for UNO.
  • 1 X HC-06 (Amazon) – this is a slave Bluetooth module very easy to use with Arduino using serial communication.
  • 1 X SG90 Servo Motor (Amazon) – this is probably the most popular servo motor in the DIY community.
  • 7 X male to male jumper wires (Amazon).
  • 1 X breadboard (Amazon).
  • 1 X Android smartphone (Amazon).

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.

How to setup the SG90 servo motor with Arduino UNO and the HC-06 Bluetooth module

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.

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.

For this tutorial, I use “Controller Mode”

The interface layout provides 10 buttons specifically designed to send continuously commands while pressed. For now, we only use two of the buttons: one button to send “1”, and another to send “2”. So, use the settings of the application to set the value “1” and value “2” for two of the buttons. These values will be received by the Bluetooth module and used in the Arduino sketch to control the servo motor.

I use these two buttons to send the commands to the Bluetooth module

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.

If you follow the above steps, things just work!

Conclusion

The key piece of this tutorial is the Bluetooth module. These modules are found under various names and features. Only a servo motor connected to an Arduino board is not interested enough to keep you interested for a long time. But, thinking forward, you can do a lot of brilliant things only starting from this tutorial. You can control a robot arm with a twist of the smartphone, control a camera attached to a pan and tilt system, and more.

Related Articles

1 comment » Write a comment

Leave a Reply

Required fields are marked *.