Hello young tech enthusiasts! Today, we’re going to embark on an exciting journey into the world of robotics and learn how to control a servo motor using Bluetooth technology and an Arduino board. Get ready to dive into this hands-on project that combines wireless communication with precise motor control. Let’s get started!
Introduction
What is Bluetooth?
Bluetooth is a wireless communication technology that allows devices to exchange data over short distances. It’s commonly used in our daily lives for connecting headphones, speakers, and even game controllers to our smartphones and computers. But did you know that Bluetooth can also be used to control robots and motors? That’s exactly what we’re going to do today!
Why Use a Servo Motor?
A servo motor is a special type of motor that enables precise control of angular position. It’s commonly used in robotics, RC cars, and many other projects where accurate movement is required. The servo motor consists of a small motor connected to a control circuitry that allows us to set the desired angle of rotation.
Things we Need
To begin, let’s gather the following components:
- Arduino board (such as Arduino Uno)
- Bluetooth module (e.g., HC-05 or HC-06)
- Servo motor
- Jumper wires (If you have female to male jumper cables use them without the breadboard)
- Breadboard
Circuit Diagram
Code
#include <SoftwareSerial.h>
#include <Servo.h>
const int hc05TxPin = 2; // HC-05 RX pin connected to Arduino digital pin 2
const int hc05RxPin = 3; // HC-05 TX pin connected to Arduino digital pin 3
Servo myservo;
int pos = 0;
SoftwareSerial bluetooth(hc05TxPin, hc05RxPin);
void setup() {
myservo.attach(5);
Serial.begin(9600); // Initialize serial communication with the computer
bluetooth.begin(115200); // Initialize Bluetooth communication
}
void loop() {
if (bluetooth.available()) { // Check if data is received from Bluetooth
char receivedChar = bluetooth.read();
if(receivedChar=='1'){
myservo.write(180);
delay(100);
Serial.println("I have turned 180");
}
else if(receivedChar=='0'){
myservo.write(0);
delay(100);
Serial.println("I have turned 0");
}
Serial.print(receivedChar); // Print received data to the serial monitor
}
delay(10);
if (Serial.available()) { // Check if data is sent from the serial monitor
char sendChar = Serial.read();
bluetooth.print(sendChar); // Send data to Bluetooth
//myservo.write(sendChar);
//delay(100);
}
delay(10);
}
Make sure you have installed the “Servo” library in your Arduino IDE before uploading the code. The code sets up a connection between the Bluetooth module and the servo motor. It waits for the angle value received from the Bluetooth module and then moves the servo motor accordingly.
This code establishes a connection between the Bluetooth module and the servo motor. It waits for the angle value received from the Bluetooth module and moves the servo motor accordingly.
Phone Application Pairing and Control
Now, let’s take control of the servo motor using a phone application. Follow these steps:
- Install a Bluetooth terminal app on your smartphone (e.g., “Serial Bluetooth Terminal” for Android or “Bluetooth Electronics” for iOS).
- Turn on Bluetooth on your smartphone and pair it with the Bluetooth module (The passkey is mostly 0000 or 1234).
- Open the Bluetooth terminal app and connect to the Bluetooth module from within the app.
- Once connected, you’ll see a terminal section in the app where you can send commands to the Bluetooth Module.
- These commands will be visible on the Serial Monitor
Conclusion
Congratulations, young inventors! You’ve successfully learned how to control a servo motor using Bluetooth and Arduino. This activity opens up a world of possibilities for creating wireless robotic projects. Here are a few applications where you can use this newfound knowledge:
- Remote-Controlled Robots: Build a robot that can be controlled wirelessly using a smartphone or a computer.
- Robotic Arm: Create a robotic arm that mimics your hand movements wirelessly, opening up endless possibilities for automation.
- Camera Gimbal: Develop a camera gimbal that can be remotely controlled to capture smooth and steady videos.
Remember, learning is a continuous journey, so feel free to experiment and modify the code to create your own unique projects. Stay curious, keep exploring, and let your creativity soar!
Happy tinkering, young engineers!