How to make a Remote Control RC car using Arduino and HC-06 bluetooth module
Introduction
Growing up in a poor family, I was amazed by remote control toys, robots, and transistor radios. I was curious about how those things worked.
One time, when I was a kid, I found an old, rusty but still functional DC motor typically found in battery-powered toy cars. When I got home, I connected it to a battery, and I spent the rest of my day thinking and planning how to use it for my next toy boat project.
My fascination with how things work, especially in the field of electronics, is my burning passion, which is why I continue to tinker. So today, we are going to convert a battery-powered toy car into a remote control car. The subject toy car has three DC motors inside: one motor controls the right-side front and rear wheels, another motor controls the left-side front and rear wheels, and the third motor controls the shovel arm, raising and lowering it.
Materials:
- Battery powered toy car (our subject).
- Arduino Uno (or any other microcontroller available)
- Motor driver (here I am using 4 motors and 16 servo Arduino Uno shield of doit.am)
- HC-06 Bluetooth module
- Some jumper wires
Video Demonstration:
Source Code
1#include <softwareserial.h>
2
3// Arduino UNO Rx, Tx
4SoftwareSerial hc06(13,12);
5String cmd="";
6
7//Motor A or MOTOR 1
8int PWMA = 9; //Speed control
9int DIRA = 8; //Direction
10//Motor B or MOTOR 2
11int PWMB = 6; //Speed control
12int DIRB = 7; //Direction
13//Motor C or MOTOR 3
14int PWMC = 5; //Speed control
15int DIRC = 4; //Direction
16//Motor D or MOTOR 4gggjh
17int PWMD = 3; //Speed control
18int DIRD = 2; //Direction
19
20
21void setup() {
22 //Initialize Serial Monitor
23 Serial.begin(9600);
24 //Initialize Bluetooth Serial Port
25 hc06.begin(9600);
26
27 pinMode(PWMA, OUTPUT);
28 pinMode(DIRA, OUTPUT);
29 pinMode(PWMB, OUTPUT);
30 pinMode(DIRB, OUTPUT);
31 pinMode(PWMC, OUTPUT);
32 pinMode(DIRC, OUTPUT);
33 pinMode(PWMD, OUTPUT);
34 pinMode(DIRD, OUTPUT);
35
36 // Set default at full stop
37 stopped();
38 movehalt();
39 Serial.print("Setup DONE.");
40}
41
42
43void loop() {
44 //Read data from HC06
45 while(hc06.available()>0){
46 cmd+=(char)hc06.read();
47 }
48
49 //Select function with cmd
50 if(cmd!=""){
51 cmd.trim(); // Remove added LF in transmit
52 // We expect Command from bluetooth
53 if (cmd.equals("F")) {
54 Serial.println("Vehicle Forward");
55 forward();
56 }else if (cmd.equals("B")){
57 Serial.println("Vehicle Backward");
58 backward();
59 }else if(cmd.equals("L")){
60 Serial.println("Vehicle Turn Left");
61 turnleft();
62 }else if(cmd.equals("R")){
63 Serial.println("Vehicle Turn Right");
64 turnright();
65 }else if(cmd.equals("S")){
66 Serial.println("Vehicle Stop");
67 stopped();
68 }else if(cmd.equals("U")){
69 Serial.println("Crane UP");
70 moveup();
71 }else if(cmd.equals("D")){
72 Serial.println("Crane DOWN");
73 movedown();
74 }else if(cmd.equals("H")){
75 Serial.println("Crane HALT");
76 movehalt();
77 }else{
78 Serial.println("Command UNKNOWN");
79 stopped();
80 movehalt();
81 }
82
83 Serial.print("Command recieved:");
84 Serial.println(cmd);
85 cmd=""; //reset cmd
86 }
87
88 delay(100);
89}
90
91// Function for the vehicle to move FORWARD
92void forward() {
93 analogWrite(PWMA, 255);
94 digitalWrite (DIRA, HIGH);
95 analogWrite(PWMB, 255);
96 digitalWrite (DIRB, HIGH);
97}
98
99// Function for the vehicle to move BACKWARD
100void backward() {
101 analogWrite(PWMA, 255);
102 digitalWrite (DIRA, LOW);
103 analogWrite(PWMB, 255);
104 digitalWrite (DIRB, LOW);
105}
106
107// Function for the vehicle to turn RIGHT
108void turnright() {
109 analogWrite(PWMA, 255);
110 digitalWrite (DIRA, HIGH);
111 analogWrite(PWMB, 0);
112 digitalWrite (DIRB, HIGH);
113}
114
115// Function for the vehicle to turn LEFT
116void turnleft() {
117 analogWrite(PWMA, 0);
118 digitalWrite (DIRA, HIGH);
119 analogWrite(PWMB, 255);
120 digitalWrite (DIRB, HIGH);
121}
122
123// Function for the vehicle to STOP
124void stopped() {
125 analogWrite(PWMA, 0);
126 digitalWrite (DIRA, HIGH);
127 analogWrite(PWMB, 0);
128 digitalWrite (DIRB, HIGH);
129}
130
131// Function for the crane to move UP
132void moveup() {
133 analogWrite(PWMC, 255);
134 digitalWrite (DIRC, HIGH);
135}
136
137// Function for the crane to move DOWN
138void movedown() {
139 analogWrite(PWMC, 255);
140 digitalWrite (DIRC, LOW);
141}
142
143// Function for the crane to HALT
144void movehalt() {
145 analogWrite(PWMC, 0);
146 digitalWrite (DIRC, HIGH);
147}
Call To Action
If you find this lesson useful, please consider visiting my website and Youtube channel:
Thank you. Happy tinkering.
Posts in this series
- How to Get Started with ATTiny85 in Arduino IDE
- Tutorial: How to use MFRC522 RFID module using Arduino
- SOS Flasher Using Millis Function with Enable Switch
- Tutorial: How to use DS3231 RTC in Arduino
- Tutorial: How to use 0.96 OLED - a small and cute display
- Tutorial: Getting Started with the NRF24L01 | How to use | Arduino
- Tutorial: How to use SIM800L GSM Module for Controlling Anything | Arduino
- Tutorial: How to use Keypad | Text Entry Mode | Arduino
- Tutorial: How to use 4x4 Keypad | Arduino
- Project Idea: Arduino Voltmeter
- Project Idea: Door Lock Security | Arduino
- Multitasking with Arduino | Relay Timer Controller | using millis
- Tutorial Understanding Blink Without Delay | How to millis
- Arduino Simple LCD Menu
- How to use SIM800L GSM Module using Arduino | Make or Answer Voice Calls
- Tutorial: How to Use Arduino Uno as HID | Part 2: Arduino Mouse Emulation
- Tutorial: How to Use Arduino Uno as HID | Part 1: Arduino Keyboard Emulation
- Tutorial: How to use SIM800L DTMF to Control Anything | Arduino
- Tutorial: Arduino EEPROM
- How to use SIM800L GSM Module | Arduino | Send and Receive SMS
- 16x2 LCD Menu for Arduino
- Tutorial: Arduino GPIO | How to use Arduino Pins
- MIT App Inventor for Arduino
- RC Car using L298N, HC-06, and Arduino Uno
- How to Use LCD Keypad Shield for Arduino
- How to Use Arduino Interrupts
- Project: Automatic Alcohol Dispenser
- TUTORIAL: How to use HC-SR04 Ultrasonic Sensor with Arduino
- Source Code: Astronomia Meme and Funeral Dance | melodies the Arduino way
- How to Get Started with L293D Motor Driver Shield with Arduino
- How to Get Started with L298N Motor Driver module using Arduino
- Part 2: Wav Music Player with Lyrics Using Arduino and SD Card
- Interfacing Infrared to Arduino Uno
- Part 1: Wav Music Player Using Arduino Uno and SD Card
- How to Interface Stepper Motor to Arduino Uno
- How To Play MP3 Files on Arduino from SD Card
- What is Arduino Software Serial
- How to Interface SD card to Arduino (without SD card shield)?
- Playing Melodies Using Arduino
- 8 Degrees Of Freedom (DOF) Robot Using Arduino Uno
- How to Interface PS2 Controller to Arduino Uno
- Part 3: DF Player Mini Tinkering with Arduino Nano and LCD
- How to Interface HC-06 to Arduino
- Part 2: DF Player Mini Tinkering with Arduino Nano
- Part 1: DF Player Mini - a mini cheap mp3 player
No comments yet!