In this project, we’ll show you how to control a DC motor using your smartphone through Bluetooth. It’s an excellent opportunity to learn about DC motors, connecting Arduino to your phone, and Bluetooth communication.
Required Components:
- Arduino UNO (Check out our recommended Arduino Starter Kits)
- Bluetooth Module (e.g., HC-05 or HC-06)
- Smartphone (Any Android device will work)
- BlueTerm Application (Free on Play Store)
- L293D IC
- DC Motor
- Breadboard
- Jumper Cables
You can find all these components on Amazon.com for the best prices.
Wiring the Circuit:
To set up the circuit, connect the TX and RX cables after uploading the Arduino code. Remember to remove the RX and TX cables when uploading the sketch to your Arduino.
Uploading the Code:
Upload the following Arduino code to your board. Ensure that you’ve disconnected the wires from RX and TX while uploading.
int motorPin1 = 3; // Connect to pin 2 on the L293D IC
int motorPin2 = 4; // Connect to pin 7 on the L293D IC
int enablePin = 5; // Connect to pin 1 on the L293D IC
int state;
int flag = 0; // Ensures that the serial output prints only once
void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, HIGH); // Enable the motor
Serial.begin(9600); // Initialize serial communication
}
void loop() {
if (Serial.available() > 0) {
state = Serial.read();
flag = 0;
}
if (state == '0') {
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
if (flag == 0) {
Serial.println("Motor: Off");
flag = 1;
}
} else if (state == '1') {
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
if (flag == 0) {
Serial.println("Motor: Right");
flag = 1;
}
} else if (state == '2') {
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
if (flag == 0) {
Serial.println("Motor: Left");
flag = 1;
}
}
}
Using the BlueTerm App:
For Android communication with the Bluetooth module, we recommend using the free BlueTerm app available on the Play Store. Simply download and install the app. Connect your smartphone to the Bluetooth module, ensuring that you’ve removed the TX and RX cables.
Controlling the DC Motor:
You can control the DC motor with these simple commands:
- ‘0’ – Turns off the DC motor
- ‘1’ – Rotates the DC motor to the right
- ‘2’ – Rotates the DC motor to the left
Troubleshooting Tips:
Frequently Asked Questions:
That’s it! You can now control a DC motor with your smartphone via Bluetooth. Enjoy experimenting with this project, and if you have any questions, feel free to leave a comment. Don’t forget to subscribe to our blog and Facebook Page for more exciting projects.
Leave a Reply