Control a Servo Motor with your Smartphone or Tablet Using Arduino and Bluetooth

13 May 2023 Balmiki Mandal 0 µC - µP

Introduction to Bluetooth Controlled Servo Using Arduino

Servos are becoming increasingly popular in robotics and automation projects, due to their ability to precisely control the position of an object. With the use of Arduino, servos can now be controlled over Bluetooth, allowing for remote operation with the use of a smartphone or other Bluetooth enabled device. In this article, we will discuss the basics of using an Arduino, a Bluetooth module, and a servo motor to create a Bluetooth controlled servo.

What is a Servo Motor?

A servo motor is a type of motor that is used to accurately control angular or linear motion. The motor output shaft is connected to a gearbox that is used to drive the output shaft (usually in a rotary direction) and the shaft can be driven to a specific angle or position, based on the input signal from a control source. This makes servo motors ideal for applications such as driving robotic arms and other robotic systems.

How Does an Arduino Control a Servo?

Arduino is a popular microcontroller platform that is used to build all sorts of electronic projects. The Arduino can be used to control servo motors by reading information from digital inputs and sending out PWM signals to the motor. A PWM signal is a pulse-width modulated signal that is used in most types of motor control systems. By modifying the duty cycle of this signal, the speed and position of a servo motor can be accurately controlled.

What is Bluetooth?

Bluetooth is a wireless technology used to enable communication between two or more devices. It is built on top of the IEEE 802.15.1 standard. The main advantage of using Bluetooth is that it enables communication over short ranges without the need for physical cables or wires. By using a Bluetooth module connected to an Arduino, a servo motor can be controlled wirelessly from a compatible Bluetooth device.

Using Bluetooth to Control a Servo Motor with Arduino

In order to use Bluetooth to control a servo motor, we need to connect a Bluetooth module to the Arduino. The most common type of Bluetooth module used for this application is the HC-05. This module can be connected to the Arduino through RX and TX pins. After connecting the Bluetooth module to the Arduino, we can connect the servo motor to one of the PWM pins of the Arduino. Once the connections are made, we can program the Arduino to receive commands over Bluetooth and then send the corresponding PWM signal to the servo motor. This allows us to control the position of the servo motor remotely, with the help of a compatible Bluetooth device.

Here is an example source code for a Bluetooth controlled servo using Arduino:

#include <SoftwareSerial.h>
#include <Servo.h>

SoftwareSerial bluetooth(10, 11); // RX, TX pins for Bluetooth module
Servo servoMotor; // create a servo object

void setup() {
  bluetooth.begin(9600); // initialize Bluetooth communication at 9600 baud rate
  servoMotor.attach(9); // attach the servo to pin 9
}

void loop() {
  if (bluetooth.available()) { // if data is available from the Bluetooth module
    char command = bluetooth.read(); // read the data from the Bluetooth module

    if (command == 'O') { // if the character 'O' is received
      servoMotor.write(0); // set the servo position to 0 degrees (fully left)
    } else if (command == 'C') { // if the character 'C' is received
      servoMotor.write(180); // set the servo position to 180 degrees (fully right)
    }
  }
}

In this example, a Bluetooth module is used to control the position of a servo motor. The Bluetooth module is connected to digital pins 10 and 11 for serial communication, and the servo motor is connected to pin 9.

In the setup() function, the Bluetooth communication is initialized at a baud rate of 9600, and the servo motor is attached to pin 9 using the attach() function.

In the loop() function, the available() function is used to check if data is available from the Bluetooth module. If data is available, the read() function is used to read the data and store it in the command variable.

If the character 'O' is received, the write() function is used to set the servo position to 0 degrees (fully left). If the character 'C' is received, the write() function is used to set the servo position to 180 degrees (fully right).

Note that the servo motor can be adjusted to different positions by changing the input values in the write() function. For example, a position of 90 degrees will set the servo to the middle position.

Conclusion

Bluetooth Controlled Servo Motors are becoming increasingly popular in robotic projects and automation projects as it allows for precise control over the position of an object. In this article, we discussed the basics of using an Arduino, a Bluetooth module, and a servo motor to create a Bluetooth controlled servo. We also discussed how to connect the components together and how to program the Arduino to receive commands over Bluetooth and send them to the servo motor.

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.