Introduction: Arduino+Car+Android=RC

Hi friends,

Its first time for this 17 year old boy in here so please excuse me if there are any Mistakes
Your suggestion and comments are greatly appreciated

Here I am to share my experience-to add few components to your remote control car to control it using Any Android that can download apps and has bluetooth.

Here we are going to create a car that can be controlled using using Your android device

Requirements are the following ,

A very little knowledge about Arduino IDE software and coding + PC or Android device +

(everything is available in Amazon),

A remote control car (In this case two wheel drive car) =7$

(you can use any '6' AA 1.5v batteries) '6' Rechargeable batteries+charger=24$

HC05 bluetooth =8$

Arduino UNO R3 =25$

(H bridge) IC L293D =3$

USB cable (to connect from computer to arduino)=3$

Otg(if u wish to use android to upload sketches)=3$

LED's+wire(in this case some" female to male "and "male to male" wires)=10$




Step 1: Why We Need This IC?

Two reasons;

1) The supply current of Arduino UNO board is low to run motors

2) you cannot reverse the direction of rotation of motor

I tried using NPN transistors as electronic switch to reverse the direction of current in motors but it couldn't bear the current and it screwed up (BAM !)

This IC can control 2 motors

So IC L293D has 16 pins ,the Vss pin is connected to 5v of arduino( condition Vss input min 4.5v)

Vs pin to the + terminal of battery powering motors (condition 36v>Vs input>Vss input )

(It can hold upto 600amps)

the GND pins are connected to the - terminal of the battery and the gnd pin of arduino are connected together to these pins

Pins 3,6 to terminals of one motor 14,11 to terminals of another motor

Pin 2,9 called enable pins .By varying the voltage between 0 to Vss you can control the speed of motor

so connect it to PWM output pins in arduino (ex. pin 2 for motor in PIN 3,6 )

Giving high input to pin 2 rotates the 3,6 motor in one direction and giving high input to pin 7 rotates it in other direction so simply connect it to digital output pins

Giving high input to pin 15 rotates the 14,11 motor in one direction and giving high input to pin 10 rotates it in other direction so simply connect it to digital output pins

YOU can use one battery source for running both Arduino board and IC L293D

I bought a IC with adapter as its easy to use .

Step 2: Programming Your Arduino UNO

Now ur ready to go but u need to setup your arduino to perform tricks

In this case i used an app called Bluetooth commander available in google play.The demo sketch is available in description column.

Another app called Android Bluetooth google play is very easy to use as u can use it directly only difference is that the former can control speed of car .So I prefer to the first one,

Download the app and the demo sketch

it looks like this

#define VERSION "\n\nAndroTest V2.0 - @kas2014\ndemo for V5.X App (6 button version)"

// V2.0 changed to pure ASCII Communication Protocol ** not backward compatible ** // V1.4 improved communication errors handling // V1.3 renamed for publishing, posted on 09/05/2014 // V1.2 Text display ** not backward compatible ** // V1.1 Integer display // V1.0 6 buttons + 4 data char implemented

// Demo setup: // Button #1 controls pin #13 LED // Button #4 toggle datafield display rate // Button #5 configured as "push" button (momentary) // Other buttons display demo message

// Arduino pin#2 to TX BlueTooth module // Arduino pin#3 to RX BlueTooth module // make sure your BT board is set @57600 bps // better remove SoftSerial for PWM based projects

// For Mega 2560: // remove #include "SoftwareSerial.h", SoftwareSerial mySerial(2,3); // search/replace mySerial >> Serial1 // pin#18 to RX bluetooth module, pin#19 to TX bluetooth module

#include "SoftwareSerial.h"

#define STX 0x02 #define ETX 0x03 #define ledPin 13 #define SLOW 750 // Datafields refresh rate (ms) #define FAST 250 // Datafields refresh rate (ms)

SoftwareSerial mySerial(2,3); // BlueTooth module: pin#2=TX pin#3=RX byte cmd[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // bytes received byte buttonStatus = 0; // first Byte sent to Android device long previousMillis = 0; // will store last time Buttons status was updated long sendInterval = SLOW; // interval between Buttons status transmission (milliseconds) String displayStatus = "xxxx"; // message to Android device

void setup() { Serial.begin(57600); mySerial.begin(57600); // 57600 = max value for softserial pinMode(ledPin, OUTPUT); Serial.println(VERSION); while(mySerial.available()); // empty RX buffer }

void loop() { if(mySerial.available()) { // data received from smartphone delay(2); cmd[0] =; if(cmd[0] == STX) { int i=1; while(mySerial.available()) { delay(1); cmd[i] =; if(cmd[i]>127 || i>7) break; // Communication error if((cmd[i]==ETX) && (i==2 || i==7)) break; // Button or Joystick data i++; } if (i==2) getButtonState(cmd[1]); // 3 Bytes ex: < STX "C" ETX > else if(i==7) getJoystickState(cmd); // 6 Bytes ex: < STX "200" "180" ETX > } } sendBlueToothData(); }

void sendBlueToothData() { static long previousMillis = 0; long currentMillis = millis(); if(currentMillis - previousMillis > sendInterval) { // send data back to smartphone previousMillis = currentMillis;

// Data frame transmitted back from Arduino to Android device: // < 0X02 Buttons state 0X01 DataField#1 0x04 DataField#2 0x05 DataField#3 0x03 > // < 0X02 "01011" 0X01 "120.00" 0x04 "-4500" 0x05 "Motor enabled" 0x03 > // example

mySerial.print((char)STX); // Start of Transmission mySerial.print(getButtonStatusString()); mySerial.print((char)0x1); // buttons status feedback mySerial.print(GetdataInt1()); mySerial.print((char)0x4); // datafield #1 mySerial.print(GetdataFloat2()); mySerial.print((char)0x5); // datafield #2 mySerial.print(displayStatus); // datafield #3 mySerial.print((char)ETX); // End of Transmission } }

String getButtonStatusString() { String bStatus = ""; for(int i=0; i<6; i++) { if(buttonStatus & (B100000 >>i)) bStatus += "1"; else bStatus += "0"; } return bStatus; }

int GetdataInt1() { // Data dummy values sent to Android device for demo purpose static int i= -30; // Replace with your own code i ++; if(i >0) i = -30; return i; }

float GetdataFloat2() { // Data dummy values sent to Android device for demo purpose static float i=50; // Replace with your own code i-=.5; if(i <-50) i = 50; return i; }

void getJoystickState(byte data[8]) { int joyX = (data[1]-48)*100 + (data[2]-48)*10 + (data[3]-48); // obtain the Int from the ASCII representation int joyY = (data[4]-48)*100 + (data[5]-48)*10 + (data[6]-48); joyX = joyX - 200; // Offset to avoid joyY = joyY - 200; // transmitting negative numbers

if(joyX<-100 || joyX>100 || joyY<-100 || joyY>100) return; // commmunication error // Your code here ... Serial.print("Joystick position: "); Serial.print(joyX); Serial.print(", "); Serial.println(joyY); }

void getButtonState(int bStatus) { switch (bStatus) { // ----------------- BUTTON #1 ----------------------- case 'A': buttonStatus |= B000001; // ON Serial.println("\n** Button_1: ON **"); // your code... displayStatus = "LED "; Serial.println(displayStatus); digitalWrite(ledPin, HIGH); break; case 'B': buttonStatus &= B111110; // OFF Serial.println("\n** Button_1: OFF **"); // your code... displayStatus = "LED "; Serial.println(displayStatus); digitalWrite(ledPin, LOW); break;

// ----------------- BUTTON #2 ----------------------- case 'C': buttonStatus |= B000010; // ON Serial.println("\n** Button_2: ON **"); // your code... displayStatus = "Button2 "; Serial.println(displayStatus); break; case 'D': buttonStatus &= B111101; // OFF Serial.println("\n** Button_2: OFF **"); // your code... displayStatus = "Button2 "; Serial.println(displayStatus); break;

// ----------------- BUTTON #3 ----------------------- case 'E': buttonStatus |= B000100; // ON Serial.println("\n** Button_3: ON **"); // your code... displayStatus = "Motor #1 enabled"; // Demo text message Serial.println(displayStatus); break; case 'F': buttonStatus &= B111011; // OFF Serial.println("\n** Button_3: OFF **"); // your code... displayStatus = "Motor #1 stopped"; Serial.println(displayStatus); break;

// ----------------- BUTTON #4 ----------------------- case 'G': buttonStatus |= B001000; // ON Serial.println("\n** Button_4: ON **"); // your code... displayStatus = "Datafield update "; Serial.println(displayStatus); sendInterval = FAST; break; case 'H': buttonStatus &= B110111; // OFF Serial.println("\n** Button_4: OFF **"); // your code... displayStatus = "Datafield update "; Serial.println(displayStatus); sendInterval = SLOW; break;

// ----------------- BUTTON #5 ----------------------- case 'I': // configured as momentary button // buttonStatus |= B010000; // ON Serial.println("\n** Button_5: ++ pushed ++ **"); // your code... displayStatus = "Button5: "; break; // case 'J': // buttonStatus &= B101111; // OFF // // your code... // break;

// ----------------- BUTTON #6 ----------------------- case 'K': buttonStatus |= B100000; // ON Serial.println("\n** Button_6: ON **"); // your code... displayStatus = "Button6 "; // Demo text message break; case 'L': buttonStatus &= B011111; // OFF Serial.println("\n** Button_6: OFF **"); // your code... displayStatus = "Button6 "; break; } // --------------------------------------------------------------- }

Step 3: Bluetooth Module

HC05 is an apt bluetooth module but its range is any way not much greater

  • The Vcc and GND pin is connected to 5v and gnd of arduino
  • The Tx pin (transmitter)in of bluetooth should be connected to Rx(receiver) of arduino and Rx of bluetooth to Tx pin of arduino
  • No need to worry about other pins.
  • You can configure the Tx and Rx pin to your comfortability using SoftwareSerial library in arduino

int Tx=3;
int Rx=4;
SoftwareSerial mySerial(Tx,Rx);

// so in this case the Tx of bluetooth connected to pin 4 and Rx to pin 3

Step 4: Configuring Bluetooth

You can put your bluetooth to AT command mode by putting the pin 34 of bluetooth to high

#include <softwareserial.h>
SoftwareSerial BTSerial(4, 3); //RX|| TX
void setup() { pinMode(9, OUTPUT); // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode digitalWrite(9, HIGH); Serial.begin(9600); Serial.println("Enter AT commands:"); BTSerial.begin(38400); // HC-05 default speed in AT command more }void loop() { // Keep reading from HC-05 and send to Arduino Serial Monitor if (BTSerial.available()) Serial.write(; // Keep reading from Arduino Serial Monitor and send to HC-05 if (Serial.available()) BTSerial.write(; } //upload the sketch //Then open the serial port select baud rate to 9600 and select NL&CR mode //Connect Tx and Rx of bluetooth pin to to 4,3 respectively // You can touch the pin 34 of bluetooth to pin 9 of arduino using a wire // disconnect the bluetooth while uploading the sketch as it will interrupt the uploading //now u can configure the baud rate of bluetooth ,give name to bluetooth ,set password to bluetooth.... //The file HC05 at command has codes to configure the bluetooth //In order to check ur connection Enter AT in Serial port it will reply OK
//Enter " AT+UART=57600,0,0 " in serial port to change the baud rate of bluetooth

Step 5: Programming Still Continues.....The END

The demo sketch i posted before there are places which say "type your code" where u can type your codes to control the Digital output and PWM pins

Suggestion : Joy X and Joy Y to control PWM pins --->Enable pin----->controll speed

Now open the App - pair it with your bluetooth - Enjoy!