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:

  1. Battery powered toy car (our subject).
  2. Arduino Uno (or any other microcontroller available)
  3. Motor driver (here I am using 4 motors and 16 servo Arduino Uno shield of doit.am)
  4. HC-06 Bluetooth module
  5. 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:

  1. https://techtotinker.com
  2. techtotinker Youtube Channel

Thank you. Happy tinkering.



Posts in this series



No comments yet!

GitHub-flavored Markdown & a sane subset of HTML is supported.