Create a Bluetooth Controlled Car Using Arduino
How to build a Bluetooth Controlled Car using Arduino
Introduction
Building your own Bluetooth controlled car is an exciting way to explore the power of Arduino and Bluetooth technology. Arduino is an open-source microcontroller development platform, and is a great way for makers to gather experience and learn about programming and electronics. With Bluetooth communication, you can design a vehicle that is wirelessly controlled by a smartphone, tablet, or laptop - no wires required.
Things You'll Need
- Arduino Uno
- HC-05 Bluetooth Module
- L293D Motor Drive Shield
- 2 DC Motors
- Wheels
- Aluminium Chassis
- 9V Battery
- Jumper Wires
Steps to Build the Car
Step 1: Assemble the Chassis
To start, assemble the aluminium chassis by following the instructions included with the kit. The chassis will form the base for the car and the motors will be mounted on it.
Step 2: Connect the Motors and Arduino
After assembling the chassis, the next step is to mount the DC motors on it. Connect the two motors to the L293D motor driver shield and then connect the shield to the Arduino Uno board.
Step 3: Connect the Bluetooth Module
Now that the hardware components are connected, it’s time to connect the HC-05 Bluetooth module to the Arduino Uno. The incoming serial data from the Bluetooth module will be used to control the speed and direction of the motors.
Step 4: Write the Arduino Code
The last step is to write the Arduino code that will interpret the incoming serial data and control the speed and direction of the motors. The full code can be found in the tutorial.
Step 5: Put It All Together
Once the code has been uploaded to the Arduino, you can now power up the car and use a Bluetooth capable device to control it! You can also design and 3D print your own custom casing for the car to make it look more aesthetically pleasing.
Here is a sample Arduino code for creating a Bluetooth-controlled car using Arduino
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(10, 11); // TX, RX
int motor1Pin1 = 2;
int motor1Pin2 = 3;
int motor2Pin1 = 4;
int motor2Pin2 = 5;
void setup() {
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
bluetooth.begin(9600); // Set Bluetooth baud rate
}
void loop() {
if (bluetooth.available() > 0) { // Check for incoming Bluetooth data
char data = bluetooth.read(); // Read the incoming data
if (data == 'F') { // Move forward
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, HIGH);
digitalWrite(motor2Pin2, LOW);
} else if (data == 'B') { // Move backward
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, HIGH);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, HIGH);
} else if (data == 'L') { // Turn left
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, HIGH);
} else if (data == 'R') { // Turn right
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, HIGH);
digitalWrite(motor2Pin1, HIGH);
digitalWrite(motor2Pin2, LOW);
} else if (data == 'S') { // Stop
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, LOW);
}
}
}
Conclusion
This code uses the SoftwareSerial library to set up a serial communication channel between the Arduino and a Bluetooth module. The Bluetooth module is connected to the Arduino's pins 10 and 11 (TX and RX), and the motor driver is connected to pins 2, 3, 4, and 5.
In the setup() function, the motor pins are set as output pins, and the Bluetooth baud rate is set to 9600.
In the loop() function, the code checks for incoming Bluetooth data using the bluetooth.available() function. If data is available, it is read using the bluetooth.read() function.
Based on the received data, the code controls the motors by setting the appropriate pins high or low. For example, if the data is 'F', the code sets pins 2 and 4 high and pins 3 and 5 low, causing the car to move forward.
The code also includes options for moving the car backward, turning left or right, and stopping the car.
Note that this is just a sample code, and it may need to be modified based on the specific hardware and requirements of your project.
Creating your own Bluetooth controlled car is a great project for anyone interested in learning about Arduino and Bluetooth technology. It’s an easy and fun way to gain experience with programming and electronics, and the possibilities are endless when it comes to customization and features. Happy building!