PCBWay 3rd PCB Design Contest

Bluetooth RC Car

1.Parts needed and the Arduino motor shield

The parts you need are:

- Arduino Uno

- Arduino Motor Shield R3

- TTL Bluetooth Module (Slave or Master-Slave)

- 9V battery

- Car's battery (needs to be greater than 5V)

- 4 LEDs

- 2 NPN transistors (2N2222)

- 2 1kΩ resistors

- 2 120Ω resistors

- 1 SPST switch

- An RC car with two DC motors. One for steering and one for moving forward/back

- Jumper wires (all lengths and rigidity)

- Solder and Soldering Iron

Disclaimer: Even though the RC car's original circuit can be placed back on the car and function as before, do this modifications at your own risk. Please make sure that the car's motors do not use more than the 2 Amps rated for the motor shield.

FrontRCLook


First of all, the original control circuit needs to be removed. With this car the motor connectors have headers, which made it easier to extend the wires.




Putting the new control circuit together is relatively easy. The Arduino Motor Shield is made to be stacked on top of the Arduino Uno, as seen in the picture bellow.


StackedMotorShield


This allows you to use most of the pins on the Arduino Uno, except for the ones used to control the two motors. This pins are clearly identified on the Motor Shield. The picture bellow shows these pins, and what they are used for.


*NOTE

By default, the Arduino motor shield is set up so that the power supply connected to the screw terminals (Vin and GND) powers everything (the motors, the L298's logic circuit, and the Arduino). But it is much better to use one power supply for the motors, and another for all the circuitry. This can be achieved by cutting the "Vin Connect" jumper on the shield's backside. The jumper is circled in the picture below:

MotorShieldBack           PinCut



I was able to cut it using a big needle. And to make sure it was correctly cut, I used a multimeter (continuity test). Just follow the motion represented by the horizontal red line seen above. Once this jumper is cut/unsolder, the power supply connected to the screw terminals (Vin and GND) will only power the motors. Everything else (the L298's logic circuit, the Arduino, and Bluetooth module) will be powered by the other power supply (9V battery) connected to the Vin and GND headers on the motor shield.

 

The motor shield uses the L298P dual full bridge driver chip. The pictures bellow show a different package of the chip, but the circuit is the same.


L298Circuit          L298Circuit

The chip's 2 and 3 pins are connected to one motor, while pins 13 and 14 are connected to another motor. Pins 5, 6, and 7 are used to control the rotating direction, and speed of the motor connected to pins 2 and 3. These three pins (5, 6, and 7) are used for the logic control circuit. Pin 6 is used to ENABLE the motor, DISABLE the motor, or control the motor's speed with a PWM signal. When Pin 6 is HIGH, the motor can be controlled with pins 5 and 7. If pin 6 is LOW, the motor will not move despite pins 5 and 7 state. By using a PWM signal with pin 6, the motor's rotating speed can be set. This is great but as I found out, this causes the motor to make a strange sound. But it happens when using a PWM signal to control an h-bridge. Pins 5 and 7 determine the motor's rotating direction. When pin 5 is HIGH and pin 7 is LOW, the motor will rotate in one direction. When these states are inverted, the motor will rotate in the opposite direction. When these pins are either both LOW or both HIGH, the motor does not move. Pins 10 - 14 have the same function, but control a separate motor. The chip has two different input voltage supplies. The input voltage going into pin 9 powers the logic circuit, and should ideally be 5V. The input voltage going into pin 4 powers the motor/s. It can have a range of 5 - 46V. This chip can have a maximum DC current of 2 Amps, so does the Motor Shield.

The motor shield does use this chip, but its picture (motor shield) shows that it only uses one pin to control each of the two motor's rotating direction. And this can be explained by looking at the motor shield's schematic. It shows a logic circuit composed of XNOR gates. This logic circuit makes the controlling pins (DIRA and DIRA#) have an opposite state when the BRAKEA pin is LOW. And when the BRAKEA pin is HIGH, the control pins have the same state. When the controlling pins have the same state, the motor stops.

MotorShieldCircuit



2.The Front and Back LEDs

Now let us see the pretty simple LED circuit. It is composed of 4 LEDs, 2 NPN transistors, 2 1kΩ resistors, 2 120Ω resistors, jumper wires, 2 AA batteries, and a 2 AA battery holder. The circuit can be seen in the pictures below.

                   

                          

  


        

The LED circuit is very basic and simple to assemble on a breadboard. But this can pose a problem in this implementation because of the space it takes. Making it part of the RC car's cover is the challenging part. I started off by placing the LEDs in their corresponding positions, and then gluing them in place. To make things easier, I made sure that the LED's anodes (positive/longer legs) were either facing each other or facing away from each other as seen bellow. 


I then proceeded to soldering a jumper wire between the anodes, and another jumper wire between the cathodes. Soldering the ends of two wires is very difficult, so I took a different approach. I stripped one of the long and stiff jumper wire, and wrapped it around a wire that is twice the width of the jumper wire.


I then threaded both the LED's leg, and the jumper wire's end into the wrapped jumper. This made it much easier to solder the jumper wires to the LEDs, resistors, and transistors. The front part is the easiest because it is not near the transistors and resistors. The back lights were more complex as seen in the picture.


As before, the first thing I did was solder a jumper cable between the LED's anodes, and another jumper between the cathodes. After this I attached the battery holder to the car's cover with bolts and nuts. I then soldered one end of each of two 120Ω resistors to one end of  the brown jumper wires. The other ends of the brown jumper wires were solder to the battery holder's positive wire (red). I then soldered a jumper wire between the end of one of the 120Ω resistors, and the jumper wire (white) coming from the anodes (positive) on the front LEDs. I also soldered the other 120Ω resistor to the jumper cable (orange) coming from the anodes (positive) on the back LEDs. After this I soldered the two transistors' emitters to the ends of two red jumper wires. The other end of the red jumper wires were soldered to the battery holder's negative wire (black), and to the long jumper wire (light yellow) that will be connected to the Arduino UNO's ground ( to complete the circuit). Now the LEDs' cathodes needed to be soldered to the two transistors' collectors. Therefore I first soldered the jumper wire (brown) coming from the front LEDs' cathodes to one of the transistor's collectors. I then soldered the jumper wire (orange) from the back LEDs' to the other transistor's collector. The only thing left is to solder the 2 1KΩ resistors, and jumper wires to the transistors' bases. I had to make sure that the jumper wires were long enough to reach the Arduino UNO's pins 4 and 7. Since I could not solder the resistors directly to the transistors because of clearance issues, I ended up cutting the jumper wires and soldering the 1kΩ resistors into the jumper wires (dark green and light orange).

                                         

                               


                       

        

And this completed the LED circuit.

3.Bluetooth modules and Arduino code

The Bluetooth module I bought was Spark Fun's Bluetooth Mate Silver. It costs around $40 bucks. It is decent but does not always connect to the Android application successfully with either 9600 or 115200 bps. It has a transfer range of 2400-115200bps. I bought it because it was the only one I could find. It has two LEDs to indicate connection status. This module might be better for an application that needs a lot of bandwidth.

BluetoothMateSilver

http://www.sparkfun.com/products/10393

After the project was done, I tumbled upon this $14 Bluetooth module by MDFLY electronics. It has a range of up to 30ft, a 9600 baud rate, and connectors. I tested it and it performed just as well as the Bluetooth Mate. It has a slightly smaller range, specially because of wall. But unlike the Bluetooth Mate, this module always connected to the Android application. I can tell you that for this project, the MDFLY module does the job perfectly.

MDFLY

http://www.mdfly.com/index.php?main_page=product_info&cPath=&products_id=769&zenid=d7vpt46igk3b54fin3rid873c1


The Arduino Code:

NOTE:

Before uploading the program onto the Arduino, make sure the Bluetooth module is not connected to the Arduino. This may cause a sync issue. Just disconnect the wires connecting the Arduino and module's RX and TX pins.

Be aware that these two programs makes use of a library. It makes the program much cleaner. Once you download the folder with the program, you will find a folder named "MotorShieldR3". This folder needs to be placed in the Arduino's "libraries" folder. The "libraries" folder can be found in the same directory as the Arduino executable file. 

Since the application now allows you to choose between a continuous or on change data stream, there are two different versions of the Arduino code. They are not very different from one another. 

RC_Motor_Shield_Continuous.ino

The first program makes use of the continuous data stream to detect, and stop the car when it has lost connection to the phone. Because of this continuous stream of characters, it also needs to filter repeated characters. The program is called "RC_Motor_Shield_Continuous.ino". It uses the "millis()" function which returns the number of milliseconds since the Arduino's execution started. This function lets the Arduino know when 500 milliseconds have elapsed since the last command was received. Once 500 milliseconds have gone by without receiving a command, the Arduino stops the car and turns it front and back lights off:

/*

 Front Motor (Steering) => Channel A

 Back Motor => Channel B

 

 Since the motor shield hijacks 6 pins for the motors'

 control, they are declared in the MotorShieldR3 library.

*/

#include <MotorShieldR3.h>

MotorShieldR3 yellowCar;

#define pinfrontLights   7   //Pin that activates the Front lights.

#define pinbackLights    4   //Pin that activates the Back lights.  

char command = 'S';

char prevCommand = 'A';

int velocity = 0;  

unsigned long timer0 = 2000; //Stores the time (in millis since execution started)

unsigned long timer1 = 0; //Stores the time when the last command was received from the phone


void setup()

{      

 Serial.begin(9600); //Set the baud rate to that of your Bluetooth module.

 pinMode(pinfrontLights , OUTPUT);

 pinMode(pinbackLights , OUTPUT);

}


void loop(){

 if(Serial.available() > 0){

   timer1 = millis();  

   prevCommand = command;

   command = Serial.read();

   //Change pin mode only if new command is different from previous.  

   if(command!=prevCommand){

     //Serial.println(command);

     switch(command){

     case 'F': 

       yellowCar.Forward_4W(velocity);

       break;

     case 'B': 

       yellowCar.Back_4W(velocity);

       break;

     case 'L': 

       yellowCar.Left_4W();

       break;

     case 'R':

       yellowCar.Right_4W(); 

       break;

     case 'S': 

       yellowCar.Stopped_4W();

       break;

     case 'I': //FR 

       yellowCar.ForwardRight_4W(velocity);

       break;

     case 'J': //BR 

       yellowCar.BackRight_4W(velocity);

       break;       

     case 'G': //FL 

       yellowCar.ForwardLeft_4W(velocity);

       break;

     case 'H': //BL

       yellowCar.BackLeft_4W(velocity);

       break;

     case 'W': //Font ON

       digitalWrite(pinfrontLights, HIGH);

       break;

     case 'w': //Font OFF

       digitalWrite(pinfrontLights, LOW);

       break;

     case 'U': //Back ON

       digitalWrite(pinbackLights, HIGH);

       break;

     case 'u': //Back OFF

       digitalWrite(pinbackLights, LOW);

       break;

     case 'D': //Everything OFF

       digitalWrite(pinfrontLights, LOW);

       digitalWrite(pinbackLights, LOW);

       yellowCar.Stopped_4W();

       break;        

     default: //Get velocity

       if(command=='q'){

         velocity = 255; //Full velocity

         yellowCar.SetSpeed_4W(velocity);

       }

       else{

         //Chars '0' - '9' have an integer equivalence of 48 - 57, accordingly.

         if((command >= 48) && (command <= 57)){

           //Subtracting 48 changes the range from 48-57 to 0-9.

           //Multiplying by 25 changes the range from 0-9 to 0-225.

           velocity = (command - 48)*25;      

           yellowCar.SetSpeed_4W(velocity);

         }

       }

     }

   }

 }

 else{

   timer0 = millis(); //Get the current time (millis since execution started).

   //Check if it has been 500ms since we received last command.

   if((timer0 - timer1)>500){ 

     //More tan 500ms have passed since last command received, car is out of range.

     //Therefore stop the car and turn lights off.

     digitalWrite(pinfrontLights, LOW);

     digitalWrite(pinbackLights, LOW);

     yellowCar.Stopped_4W();

   }

 } 

}


RC_Motor_Shield_OnChange

The program seen bellow is a copy of the one above. The one differences you'll notice have to do with the lines of code that check for disconnection, and repeated commands. Everything else is identical:

/*

 Front Motor (Steering) => Channel A

 Back Motor => Channel B

 

 Since the motor shield hijacks 6 pins for the motors'

 control, they are declared in the MotorShieldR3 library.

 */

#include <MotorShieldR3.h>

MotorShieldR3 yellowCar;

#define pinfrontLights   7   //Pin that activates the Front lights.

#define pinbackLights    4   //Pin that activates the Back lights.  

char command = 'S';

int velocity = 0;  


void setup()

{      

 Serial.begin(115200); //Set the baud rate to that of your Bluetooth module.

 pinMode(pinfrontLights , OUTPUT);

 pinMode(pinbackLights , OUTPUT);

}


void loop(){

 if(Serial.available() > 0){

   command = Serial.read();

   //Change pin mode only if new command is different from previous.  

   //Serial.println(command);

   switch(command){

   case 'F': 

     yellowCar.Forward_4W(velocity);

     break;

   case 'B': 

     yellowCar.Back_4W(velocity);

     break;

   case 'L': 

     yellowCar.Left_4W();

     break;

   case 'R':

     yellowCar.Right_4W(); 

     break;

   case 'S': 

     yellowCar.Stopped_4W();

     break;

   case 'I': //FR 

     yellowCar.ForwardRight_4W(velocity);

     break;

   case 'J': //BR 

     yellowCar.BackRight_4W(velocity);

     break;       

   case 'G': //FL 

     yellowCar.ForwardLeft_4W(velocity);

     break;

   case 'H': //BL

     yellowCar.BackLeft_4W(velocity);

     break;

   case 'W': //Font ON

     digitalWrite(pinfrontLights, HIGH);

     break;

   case 'w': //Font OFF

     digitalWrite(pinfrontLights, LOW);

     break;

   case 'U': //Back ON

     digitalWrite(pinbackLights, HIGH);

     break;

   case 'u': //Back OFF

     digitalWrite(pinbackLights, LOW);

     break;

   case 'D': //Everything OFF

     digitalWrite(pinfrontLights, LOW);

     digitalWrite(pinbackLights, LOW);

     yellowCar.Stopped_4W();

     break;        

   default: //Get velocity

     if(command=='q'){

       velocity = 255; //Full velocity

       yellowCar.SetSpeed_4W(velocity);

     }

     else{

       //Chars '0' - '9' have an integer equivalence of 48 - 57, accordingly.

       if((command >= 48) && (command <= 57)){

         //Subtracting 48 changes the range from 48-57 to 0-9.

         //Multiplying by 25 changes the range from 0-9 to 0-225.

         velocity = (command - 48)*25;      

         yellowCar.SetSpeed_4W(velocity);

       }

     }

   }

 }

}


4.Putting it all together and the Android Application

To put it all together, the picture below shows all the components connected.


The 9 volt battery powers the Arduino Uno, the Bluetooth module, and the L298's logic circuit. The 5 AA batteries power the motors. They are connected to the screw terminals on the Motor shield. The front and back motors are also connected to these screw terminals. The jumper wires coming from the LED circuit are connected to the Arduino 's pins 4 and 7. The Bluetooth module's RX pin is connected to Arduino's TX pin. And the Arduino's RX pin is connected to the Bluetooth module's TX pin. The Bluetooth module's VCC is connected Arduino's 5V pin, and the GND pin is connected to the Arduino 's ground pin. The Bluetooth module's RTS and CTS are connected together. Remember to connect the ground jumper from the LED circuit to the Arduino's ground. And this completes the connections.


RcCarShieldSideRcCarModuleSide


CircuitCloseUp


As you can see in the pictures above, I used card board to create a platform for the circuit. I ended up using a small breadboard as well. I connected the Bluetooth module, and the ON/OFF switch to the breadboard. Since the wires I soldered to the Bluetooth module were vertical, I used a 6 hole Arduino header with bent legs. And this completed the project.

RcCar


The Android Application:


The application is based on the Bluetooth Chat API demo found on the Android API's. I first created an application that enables the use of two buttons simultaneously. I used this tutorial on multi-touch:


Buttons


I then combined this code with the Bluetooth communication part of the Bluetooth Chat demo.I used this tutorial for the colorful seek bar and this other for the animated LED. This is what I ended up with:



After this I added a couple of toggle buttons for the back and front lights, and the accelerometer control feature:


The updated version 1.6 lets you choose between streaming a character every 50ms, and streaming a character on touch. The continuous stream feature was added because it can be used to determine when the car has gone out of range.


What the application does is pretty much send an ASCII character to the Arduino. It then processes the character and controls the rc car's motors.


These are the characters used:


Forward---------------------F

Back-------------------------B

Left---------------------------L

Right-------------------------R

Forward Left--------------G

Forward Right------------I

Back Left------------------H

Back Right----------------J

Stop-------------------------S

Front Lights On---------W

Front Lights Off---------w (lower case)

Back Lights On---------U

Back Lights Off---------u (lower case)

Speed 0-------------------0

Speed 10-----------------1

Speed 20-----------------2

Speed 30-----------------3

Speed 40-----------------4

Speed 50-----------------5

Speed 60-----------------6

Speed 70-----------------7

Speed 80-----------------8

Speed 90-----------------9

Speed 100---------------q

Everything OFF--------D


You can get the application from the Google Play market:


https://play.google.com/store/apps/details?id=braulio.calle.bluetoothRCcontroller&feature=search_result


(Please don't ask for the Android code)


I have provided the code of a simple application that can communicate through Bluetooth. It is composed of a spinner and button. This is a great starting point for anyone that wants to create a similar application. It is within the zip folder called "BluetoothSendCharSpinner". It can be found at the bottom of the site. Click on the arrow pointing down to download it.


The Demonstration:



Apply for sponsorship >>
524 Projects Sponsored
Dec 24,2019
946 viewsReport item
  • Comments(0)
  • Likes(5)
You can only upload 1 files in total. Each file cannot exceed 2MB. Supports JPG, JPEG, GIF, PNG, BMP
    View More
    x
    mm
    Earn a $5 Welcome Bonus