Some new stuff
  1. Arduino Park Control
  2. Arduino USB2serial programming the bare bone
  3. Arduino Projects Videos added
  4. Arduino Xbee projects
  5. Arduino dB Meter 
  6. Trying to get the IOIO going. 
  7. IOIO is going....bluetooth
  8. Attiny 2313 bluetooth bee RC car
  9. Compass and temperature added
  10. AVR programmer
  11. USB2Serial and Ethernet POE
  12. Arduino LPG Sensor
  13. Program the Arduino Mini 05
  14. Lipo Rider Pro in action
  15. EZ Robot Builder kit arrived 10 Nov 2012
  16. Arduino VA Meter!
  17. 05 Nov 2012 Project Sentry Gun.
  18. Attiny85 PIR Sensor 10 Dec 2012 
  19. 0-30VDC3A and 2-28VDC10A bench PSU's
  20. 19 Dec 2012 Arduino Voltmeter LCD
  21. 29 Dec 2012 Arduino Tachometer&Speedometer LCD
  22. 03 Jan 2013 Arduino AC Phase Control. 
  23. 18 Jan 2013 Arduino Distance Meter
  24. 22 Jan 2013 Arduino Digital Clock and Date
  25. 31 Jan 2013 Arduino Digital Clock and Date 8x2 LCD
  26. Feb 2013 LCD and Backpack
  27. Feb 2013 7 Segment Serial Clock Sparkfun. Distance Sensor with "newping" library
  28. Feb 2013 Lelo Remote
  29. 01/03/2013 Arduino Adafruit 7 Seg Digital Clock with RTC and backpack 
  30. Arduino Frequency Meter 26/03/2013
  31. Another RC  Car controlled by Arduino 06/04/2013
  32. My quadcopter project update 25 April 2013
  33. My Aqua Quad Copter Flying 26 April 2013enlightened
  34. Another monster RC truck;strong one! 11July2013cool
  35. X-Frame Quad Copter 31 July 2013cool
  36. Arduino GSM Sheild added.28/8/2013
  37. 1.8inch TFT screen 13/09/2013cool
  38. 04/11/2014 added PID Soldering Iron Control
  39. Added bluetooth servo control 04/11/2014
  40. ESP8266 first try.16/03/2015
  41. Arduino Uno Quadcopter 19 May 2015
  42. IOT WemosD1 Amp Meter

 

 


Search    

01/04/2013

Arduino, with Android application, bluetooth to control RC car. One of the best on the play market available (5 stars from me)

https://sites.google.com/site/bluetoothrccar/home/5-amorecomplexcircuit

I changed the code to accommodate the Android Application extra buttons provided. A Horn and blinking led is added.

The android application provides more control regarding the PWM speed control and the extra two outputs , which I added on the code for hazards and horn.

Code:

int dataIn = 'S';        //data coming from the phone
int pinLeft = 10;     
int pinRight = 11;       
int pinEnableLeftRight = 9;
int pinForward = 5;
int pinBack = 6;
int pinSpeedForwardBack = 3;
int pinfrontLights = 8;
int pinbackLights = 7;
int hornPin = 12;
int xtraPin = 13;
int determinant;         //used in the check function
char det;                 //used in the loop function
int velocity = 0;

void setup()  
{        
Serial.begin(9600);  // Mine is default 9600
pinMode(pinLeft, OUTPUT);
pinMode(pinRight, OUTPUT);
pinMode(pinForward, OUTPUT);
pinMode(pinBack, OUTPUT);
pinMode(pinEnableLeftRight, OUTPUT);
pinMode(pinSpeedForwardBack, OUTPUT);
pinMode(pinfrontLights, OUTPUT);
pinMode(pinbackLights, OUTPUT);
pinMode(hornPin, OUTPUT);
pinMode(xtraPin, OUTPUT);
}

void loop()
{  
    det = check();
      while (det == 'F')   //if incoming data is a F, move forward
      {      
          digitalWrite(pinEnableLeftRight, LOW);  
          analogWrite(pinSpeedForwardBack, velocity); 
          digitalWrite(pinLeft,LOW);
          digitalWrite(pinRight,LOW);   
          digitalWrite(pinForward,HIGH);
          digitalWrite(pinBack,LOW);         
          det = check();           
      }   
      while (det == 'B')   //if incoming data is a B, move back 
      {     
          digitalWrite(pinEnableLeftRight, LOW);  
          analogWrite(pinSpeedForwardBack, velocity);
          digitalWrite(pinLeft,LOW);
          digitalWrite(pinRight,LOW);   
          digitalWrite(pinForward,LOW);
          digitalWrite(pinBack,HIGH);         
          det = check();           
      }  

      while (det == 'L')   //if incoming data is a L, move wheels left
      {      
          digitalWrite(pinEnableLeftRight, HIGH);  
          analogWrite(pinSpeedForwardBack, 0);
          digitalWrite(pinLeft,HIGH);
          digitalWrite(pinRight,LOW);   
          digitalWrite(pinForward,LOW);
          digitalWrite(pinBack,LOW);        
          det = check();           
      }   
      while (det == 'R')   //if incoming data is a R, move wheels right
      {     
          digitalWrite(pinEnableLeftRight, HIGH);  
          analogWrite(pinSpeedForwardBack, 0); 
          digitalWrite(pinLeft,LOW);
          digitalWrite(pinRight,HIGH);   
          digitalWrite(pinForward,LOW);
          digitalWrite(pinBack,LOW);         
          det = check();           
      } 
      
      while (det == 'I')   //if incoming data is a I, turn right forward
      {      
          digitalWrite(pinEnableLeftRight, HIGH);  
          analogWrite(pinSpeedForwardBack, velocity);
          digitalWrite(pinLeft,LOW);
          digitalWrite(pinRight,HIGH);   
          digitalWrite(pinForward,HIGH);
          digitalWrite(pinBack,LOW);                 
          det = check();           
      }   
      while (det == 'J')   //if incoming data is a J, turn right back 
      {       
          digitalWrite(pinEnableLeftRight, HIGH);  
          analogWrite(pinSpeedForwardBack, velocity);
          digitalWrite(pinLeft,LOW);
          digitalWrite(pinRight,HIGH);   
          digitalWrite(pinForward,LOW);
          digitalWrite(pinBack,HIGH);         
          det = check();           
      }           
      while (det == 'G')   //if incoming data is a G, turn left forward
      {  
          digitalWrite(pinEnableLeftRight, HIGH);  
          analogWrite(pinSpeedForwardBack, velocity);
          digitalWrite(pinLeft,HIGH);
          digitalWrite(pinRight,LOW);   
          digitalWrite(pinForward,HIGH);
          digitalWrite(pinBack,LOW);           
          det = check();           
      }     
      while (det == 'H')   //if incoming data is a H, turn left back
      { 
          digitalWrite(pinEnableLeftRight, HIGH);  
          analogWrite(pinSpeedForwardBack, velocity);
          digitalWrite(pinLeft,HIGH);
          digitalWrite(pinRight,LOW);   
          digitalWrite(pinForward,LOW);
          digitalWrite(pinBack,HIGH);           
          det = check();                                               
      }    
      while (det == 'S')   //if incoming data is a S, stop
      { 
          digitalWrite(pinEnableLeftRight, LOW);  
          analogWrite(pinSpeedForwardBack, 0);
          digitalWrite(pinLeft,LOW);
          digitalWrite(pinRight,LOW);   
          digitalWrite(pinForward,LOW);
          digitalWrite(pinBack,LOW);        
          det = check();  
      }
      while (det == 'W')   //if incoming data is a W, turn ON back lights
      { 
          digitalWrite(pinfrontLights, HIGH);    
          det = check();  
      }
      while (det == 'w')   //if incoming data is a w, turn OFF back lights
      { 
          digitalWrite(pinfrontLights, LOW);           
          det = check();  
      }
      while (det == 'U')   //if incoming data is a U, turn ON front lights
      { 
          digitalWrite(pinbackLights, HIGH);           
          det = check();  
      }
      while (det == 'u')   //if incoming data is a u, turn OFF front lights
      { 
          digitalWrite(pinbackLights, LOW); 
          det = check();  
      }
      while (det == 'V')   //if incoming data is a V, turn ON horn
      { 
          digitalWrite(hornPin, HIGH);           
          det = check();  
      }
      while (det == 'v')   //if incoming data is a v, turn OFF horn
      { 
          digitalWrite(hornPin, LOW);           
          det = check();  
      }
      while (det == 'X')   //if incoming data is a X, turn ON xtraPin
      { 
          digitalWrite(xtraPin, HIGH);
          delay(500); 
          digitalWrite(xtraPin, LOW);
          delay(500);
          digitalWrite(xtraPin, HIGH); 
          delay(500);
          digitalWrite(xtraPin, LOW);
          delay(500); 
          digitalWrite(xtraPin, HIGH);
          delay(500); 
          digitalWrite(xtraPin, LOW);
          delay(500);
          det = check();  
      }
      while (det == 'x')   //if incoming data is a x, turn OFF xtraPin
      { 
          digitalWrite(xtraPin, LOW); 
          det = check();  
      }
}

int check()
{
  if (Serial.available() > 0)    //Check for data on the serial lines. 
  {    
    dataIn = Serial.read();  //Get the character sent by the phone and store it in 'dataIn'.
        
        if (dataIn == 'F') 
        {      
          determinant = 'F';
        }   
        else if (dataIn == 'B') 
        {  
          determinant = 'B';  
        }
        else if (dataIn == 'L')   
        {  
          determinant = 'L'; 
        }
        else if (dataIn == 'R')   
        {  
          determinant = 'R';
        }  
        else if (dataIn == 'I')   
        {  
          determinant = 'I';  
        }   
        else if (dataIn == 'J')   
        {   
          determinant = 'J'; 
        }           
        else if (dataIn == 'G')  
        { 
          determinant = 'G';  
        }     
        else if (dataIn == 'H')   
        { 
          determinant = 'H';  
        }    
        else if (dataIn == 'S')  
        {
          determinant = 'S';
        } 
        else if (dataIn == '0')  
        {
          velocity = 0;  
        } 
        else if (dataIn == '1')  
        {
          velocity = 25;
        }
        else if (dataIn == '2')  
        {
          velocity = 50;
        }
        else if (dataIn == '3')  
        {
          velocity = 75;
        }
        else if (dataIn == '4')  
        {
          velocity = 100;
        }
        else if (dataIn == '5')  
        {
          velocity = 125;
        }
        else if (dataIn == '6')  
        {
          velocity = 150;
        }
        else if (dataIn == '7')  
        {
          velocity = 175;
        }
        else if (dataIn == '8')  
        {
          velocity = 200;
        }
        else if (dataIn == '9')  
        {
          velocity = 225;
        }
        else if (dataIn == 'q')  
        {
          velocity = 255;
        }        
        else if (dataIn == 'U')  
        {
          determinant = 'U'; 
        }
        else if (dataIn == 'u')  
        {
          determinant = 'u'; 
        }
        else if (dataIn == 'W')  
        {
          determinant = 'W'; 
        }
        else if (dataIn == 'w')  
        {
          determinant = 'w'; 
        }
        else if (dataIn == 'V')
        { 
          determinant = 'V'; 
        }        
           else if (dataIn == 'v')  
        {
          determinant = 'v'; 
        }
        else if (dataIn == 'X')
        {
          determinant = 'X';  
        }
        else if (dataIn == 'x')
        {
          determinant = 'x';
        }
  } 
return determinant; 
}

I decided to power the whole project only from the battery compartment 4x AA batteries. Therefore I need to give attention to provide regulated 3VDC to the bluetooth module and the logig 5VDC towards the motordriver board. Also the front and backlight leds are regulated 3VDC.

To achieve the above I used a polulo DC to DC variable voltage regulator as well as a  fixed 3V regulator.

 I decided to go the minimum Arduino route. It is easy and it is not taking up space.

Below is a rough diagram of my power supply setup:

What I have done is to power the white leds (fron lights) straight from the Arduino data output, but with the correct resistor in line, so with the red backlight leds and my hazards are those type of leds once powered (3V3), the  flash in the specific sequence, therefore you can change the code accordingly.

Surely my l298 motordriver board is an overkill, but it was available and handy to me.

Videos of the RC car can be viewed here

I build another RC truck with code changed:

I wanted to acheive a stronger RC car than the previous ones build before. To increase torque I decide to up the voltage with 20%.

Then to accommodate more current I went for an expensive route the Polulo 14A per channel.

The outcome is fine. Strong spinning RC truck and good use of the speed control from the android application.

/*With this code the following changes:
1. Horn tone replaced with tone(12,300,interval); Also removed the digitalwrite(hornPin, LOW); with noTone(12);see code 
2. With switch on a melody will play.Melody sample from IDE incorporated into the code.
3. When RC front motor is gearbox driven, lower the torque accordingly with int frontMotorspeed = 50 and analogWrite(pinEnableLeftRight, frontMotorspeed); 
4. Dual VNH2SP30 Motor Driver MD03A (14A PER Channel)
5. Arduino Mini Pro 5VDC 16 Mhz
6. Bluetooth module Linvor
7. Own PSU for 5 and 3V3 respectively build on a small piece of veroboard.
*/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
int dataIn = 'S';        //data coming from the phone
int pinLeft = 10;        //One channel of the motordriver board  
int pinRight = 11;       
int pinEnableLeftRight = 9;//PWM on motordriver board.
int pinForward = 5;     //other channel of the motordriver board
int pinBack = 6;
int pinSpeedForwardBack = 3;//PWM on motordriver board
int pinfrontLights = 8; //Two white LED's in parallel with one series connected resistor
int pinbackLights = 7;  // Two red LED'S on parallel with series connected resistor
int hornPin = 12;
int xtraPin = 13;       //Connected to 2 LED's in parallel with series resistor(led's flicker type)
int determinant;        //used in the check function
char det;               //used in the loop function
int velocity = 0;
int frontMotorspeed = 50;//To lower the torque of the front motor which is drive by a gearbox. Not needed for front motor without gearbox 
int melody[] = {
NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};// notes in the melody:
int noteDurations[] = {
 4, 8, 8, 4,4,4,4,4 };  // note durations: 4 = quarter note, 8 = eighth note, etc.:

void setup(){  
    
Serial.begin(9600); 
pinMode(pinLeft, OUTPUT);
pinMode(pinRight, OUTPUT);
pinMode(pinForward, OUTPUT);
pinMode(pinBack, OUTPUT);
pinMode(pinEnableLeftRight, OUTPUT);
pinMode(pinSpeedForwardBack, OUTPUT);
pinMode(pinfrontLights, OUTPUT);
pinMode(pinbackLights, OUTPUT);
pinMode(hornPin, OUTPUT);
pinMode(xtraPin, OUTPUT);
 // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 8; thisNote++) {
    // to calculate the note duration, take one second 
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000/noteDurations[thisNote];
    tone(12, melody[thisNote],noteDuration);
    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(12);
  }}

void loop(){
        
      det = check();
      while (det == 'F')   //if incoming data is a F, move forward
      {      
          digitalWrite(pinEnableLeftRight, LOW);  
          analogWrite(pinSpeedForwardBack, velocity); 
          digitalWrite(pinLeft,LOW);
          digitalWrite(pinRight,LOW);   
          digitalWrite(pinForward,HIGH);
          digitalWrite(pinBack,LOW);
          digitalWrite(pinbackLights,HIGH);
          digitalWrite(pinfrontLights,LOW);         
          det = check();           
      }   
      while (det == 'B')   //if incoming data is a B, move back 
      {     
          digitalWrite(pinEnableLeftRight, LOW);  
          analogWrite(pinSpeedForwardBack, velocity);
          digitalWrite(pinLeft,LOW);
          digitalWrite(pinRight,LOW);   
          digitalWrite(pinForward,LOW);
          digitalWrite(pinBack,HIGH);
          digitalWrite(pinfrontLights,HIGH); 
          digitalWrite(pinbackLights,LOW);        
          det = check();           
      }  

      while (det == 'L')   //if incoming data is a L, move wheels left
      {      
          analogWrite(pinEnableLeftRight, frontMotorspeed);  
          analogWrite(pinSpeedForwardBack, 0);
          digitalWrite(pinLeft,HIGH);
          digitalWrite(pinRight,LOW);   
          digitalWrite(pinForward,LOW);
          digitalWrite(pinBack,LOW);                  
          det = check();           
      }   
      while (det == 'R')   //if incoming data is a R, move wheels right
      {     
          analogWrite(pinEnableLeftRight, frontMotorspeed); 
          analogWrite(pinSpeedForwardBack, 0); 
          digitalWrite(pinLeft,LOW);
          digitalWrite(pinRight,HIGH);   
          digitalWrite(pinForward,LOW);
          digitalWrite(pinBack,LOW);             
          det = check();           
      } 
      
      while (det == 'I')   //if incoming data is a I, turn right forward
      {      
          analogWrite(pinEnableLeftRight, frontMotorspeed);  
          analogWrite(pinSpeedForwardBack, velocity);
          digitalWrite(pinLeft,LOW);
          digitalWrite(pinRight,HIGH);   
          digitalWrite(pinForward,HIGH);
          digitalWrite(pinBack,LOW);
          digitalWrite(pinfrontLights,LOW);
          digitalWrite(pinbackLights,HIGH);          
          det = check();           
      }   
      while (det == 'J')   //if incoming data is a J, turn right back 
      {       
          analogWrite(pinEnableLeftRight, frontMotorspeed);  
          analogWrite(pinSpeedForwardBack, velocity);
          digitalWrite(pinLeft,LOW);
          digitalWrite(pinRight,HIGH);   
          digitalWrite(pinForward,LOW);
          digitalWrite(pinBack,HIGH);
          digitalWrite(pinfrontLights,HIGH);
          digitalWrite(pinbackLights,LOW);         
          det = check();           
      }           
      while (det == 'G')   //if incoming data is a G, turn left forward
      {  
          analogWrite(pinEnableLeftRight, frontMotorspeed);  
          analogWrite(pinSpeedForwardBack, velocity);
          digitalWrite(pinLeft,HIGH);
          digitalWrite(pinRight,LOW);   
          digitalWrite(pinForward,HIGH);
          digitalWrite(pinBack,LOW);
          digitalWrite(pinfrontLights,LOW);
          digitalWrite(pinbackLights,HIGH);           
          det = check();           
      }     
      while (det == 'H')   //if incoming data is a H, turn left back
      { 
          analogWrite(pinEnableLeftRight, frontMotorspeed);  
          analogWrite(pinSpeedForwardBack, velocity);
          digitalWrite(pinLeft,HIGH);
          digitalWrite(pinRight,LOW);   
          digitalWrite(pinForward,LOW);
          digitalWrite(pinBack,HIGH);
          digitalWrite(pinfrontLights,HIGH);
          digitalWrite(pinbackLights,LOW);          
          det = check();                                               
      }    
      while (det == 'S')   //if incoming data is a S, stop
      { 
          digitalWrite(pinEnableLeftRight, LOW);  
          analogWrite(pinSpeedForwardBack, 0);
          digitalWrite(pinLeft,LOW);
          digitalWrite(pinRight,LOW);   
          digitalWrite(pinForward,LOW);
          digitalWrite(pinBack,LOW);
          digitalWrite(pinfrontLights,LOW);
          digitalWrite(pinbackLights,LOW);        
          det = check();  
      }
      while (det == 'U')   //if incoming data is a U, turn ON front lights
      { 
          digitalWrite(pinfrontLights, HIGH);    
          det = check();  
      }
      while (det == 'u')   //if incoming data is a u, turn OFF front lights
      { 
          digitalWrite(pinfrontLights, LOW);           
          det = check();  
      }
      while (det == 'W')   //if incoming data is a W, turn ON back lights
      { 
          digitalWrite(pinbackLights, HIGH);           
          det = check();  
      }
      while (det == 'w')   //if incoming data is a w, turn OFF back lights
      { 
          digitalWrite(pinbackLights, LOW); 
          det = check();  
      }
      while (det == 'V')   //if incoming data is a V, turn ON horn
      {   
       tone(12,300,100);

         det = check();  
      }
      while (det == 'v')   //if incoming data is a v, turn OFF horn
      { 
        noTone(12);
       //  digitalWrite(hornPin, LOW);           
          det = check();  
      }
      while (det == 'X')   //if incoming data is a X, turn ON xtraPin
      { 
          digitalWrite(xtraPin, HIGH);
          det = check();  
      }
      while (det == 'x')   //if incoming data is a x, turn OFF xtraPin
      { 
          digitalWrite(xtraPin, LOW); 
          det = check();  
      }}

int check()
{
  if (Serial.available() > 0)    //Check for data on the serial lines. 
  {    
    dataIn = Serial.read();  //Get the character sent by the phone and store it in 'dataIn'.
        
        if (dataIn == 'F') 
        {      
          determinant = 'F';
        }   
        else if (dataIn == 'B') 
        {  
          determinant = 'B';  
        }
        else if (dataIn == 'L')   
        {  
          determinant = 'L'; 
        }
        else if (dataIn == 'R')   
        {  
          determinant = 'R';
        }  
        else if (dataIn == 'I')   
        {  
          determinant = 'I';  
        }   
        else if (dataIn == 'J')   
        {   
          determinant = 'J'; 
        }           
        else if (dataIn == 'G')  
        { 
          determinant = 'G';  
        }     
        else if (dataIn == 'H')   
        { 
          determinant = 'H';  
        }    
        else if (dataIn == 'S')  
        {
          determinant = 'S';
        } 
        else if (dataIn == '0')  
        {
          velocity = 0;  
        } 
        else if (dataIn == '1')  
        {
          velocity = 25;
        }
        else if (dataIn == '2')  
        {
          velocity = 50;
        }
        else if (dataIn == '3')  
        {
          velocity = 75;
        }
        else if (dataIn == '4')  
        {
          velocity = 100;
        }
        else if (dataIn == '5')  
        {
          velocity = 125;
        }
        else if (dataIn == '6')  
        {
          velocity = 150;
        }
        else if (dataIn == '7')  
        {
          velocity = 175;
        }
        else if (dataIn == '8')  
        {
          velocity = 200;
        }
        else if (dataIn == '9')  
        {
          velocity = 225;
        }
        else if (dataIn == 'q')  
        {
          velocity = 255;
        }        
        else if (dataIn == 'U')  
        {
          determinant = 'U'; 
        }
        else if (dataIn == 'u')  
        {
          determinant = 'u'; 
        }
        else if (dataIn == 'W')  
        {
          determinant = 'W'; 
        }
        else if (dataIn == 'w')  
        {
          determinant = 'w'; 
        }
        else if (dataIn == 'V')
        { 
          determinant = 'V'; 
        }        
         else if (dataIn == 'v')  
        {
          determinant = 'v'; 
        }
        else if (dataIn == 'X')
        {
          determinant = 'X';  
        }
        else if (dataIn == 'x')
        {
          determinant = 'x';
       }
  } 
return determinant; 
}

23 Aug 2013

And then I changed the code and car once more:

We swopped the front motor with gearbox for a servo control.

Included in the code again some TONE instructions with switch on.

The developer is also busy with a new android application, but the sample on his site is already working fine.

 

Here the code with my tone instructions added as well as anticrash with IR Sharp sensor:

//1.05
#include
Servo leftRight;  //Front steering servo
int pinfrontLights = 2;
int pinbackLights = 3;
int extra1 = 4;  
int extra2 = 5;
int pinSpeedForwardBack = 6;
int pinBack = 7;
int pinForward = 8; 
int speakerPin = 9;
int extra3 = 11;
int extra4 = 12;
int extra5 = 13;
byte commands[3];  //Stores the 3 readings sent by the phone.
int delayer = 0;  //Determines how often the sensor readings are sent to the phone.  
int reading0 = 0;
int reading1 = 0;
int reading2 = 0;
byte sensors[4]; //Stores the sensor readings 
#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
#define NO_SOUND
//array of notes
int melody[] = {
  /*NOTE_G4,NOTE_G4,NO_SOUND,NOTE_G4,NOTE_G4,NO_SOUND,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,
   NOTE_B3,NOTE_G3,NOTE_C4,NOTE_G3,NOTE_CS4,NOTE_G3,NOTE_C4,NOTE_G3,NOTE_B3,NOTE_G3,NOTE_C4,NOTE_G3,NOTE_CS4,NOTE_G3,NOTE_C4,NOTE_G3,
   NOTE_E4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_E4,
   NOTE_E4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,*/
   //Introduction
  NOTE_E4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_E4,
  NOTE_E4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,
  NOTE_E4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_E4,
  NOTE_E4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,
  NOTE_DS5,NOTE_D5,NOTE_B4,NOTE_A4,NOTE_B4,
  NOTE_E4,NOTE_G4,NOTE_DS5,NOTE_D5,NOTE_G4,NOTE_B4,
  NOTE_B4,NOTE_FS5,NOTE_F5,NOTE_B4,NOTE_D5,NOTE_AS5,
  NOTE_A5,NOTE_F5,NOTE_A5,NOTE_DS6,NOTE_D6,NO_SOUND
};

// note duration: 1 = whole note, 2 = half note, 4 = quarter note, 8 = eighth note, etc.
int noteDurations[] = {
  8,8,2,8,8,2,16,8,16,8,8,
  2,4,2,4,2,4,2,4,2,4,2,4,2,4,2,4,
  8,16,16,8,4,8,8,8,
  8,16,16,8,4,8,8,8,
  8,16,16,8,4,8,8,8,
  8,16,16,8,4,8,8,8,
  8,16,16,8,4,8,8,8,
  8,16,16,8,4,8,8,8,
  8,2,8,8,1,
  8,4,8,4,8,8,
  8,8,4,8,4,8,
  4,8,4,8,3
};
int pace = 1450; // change pace of music("speedy")

void setup()
{       
  Serial.begin(9600);  //Initialize serial communication with Bluetooth module at 9600 btu.
  pinMode(pinForward, OUTPUT);
  pinMode(pinBack, OUTPUT);
  pinMode(pinSpeedForwardBack , OUTPUT); 
  pinMode(pinbackLights,OUTPUT);
  pinMode(pinfrontLights,OUTPUT);
  pinMode(extra1,OUTPUT);
  pinMode(extra2,OUTPUT);
  pinMode(extra3,OUTPUT);
  pinMode(extra4,OUTPUT);
  pinMode(extra5,OUTPUT);
  pinMode(speakerPin, OUTPUT);
  leftRight.attach(10);
  // iterate over the notes of the melody:
   for (int Note = 0; Note <54; Note++) {//counter of Notes (54 limit the array)
   int duration = pace/noteDurations[Note];//Adjust duration with the pace of music
   tone(9, melody[Note],duration); //Play note
   delay(duration*1.2);// to distinguish the notes, set a minimum time between them.
   noTone(9);
   }
}

void loop()
{
  int sensorValue=analogRead(A2); //read in the sensor value
  //Serial.println(sensorValue); //allow us to see the sensor value for troubleshooting
  //Serial.println("Running...");
  if(Serial.available()==3){
    commands[0] = Serial.read();  //Direction
    commands[1] = Serial.read();  //Speed
    commands[2] = Serial.read();  //Angle
    /*
     Since the last byte yields the servo's angle (between 0-180 or 0x00-0xb4), it can never 
     be 255 (0xff). This and the range of the first byte (0xf1 - 0xfc) are used in the following 
     IF statement to make sure that the bytes never get mixed up.
     */
    if((commands[2]<=0xb4)&&((commands[0]<=0xfc)&&(commands[0]>=0xf1))){
      
      if (sensorValue > 150 && commands[0] == 0xf1){
        //Serial.println("Stopping...");
        stopMovement(); 
        return;
      }
      //Serial.println("OK...");
      //Serial.print(commands[0],HEX);
      //Serial.print(commands[1],HEX);
      //Serial.println(commands[2],HEX); 
      if(commands[0] == 0xf1)   //if incoming data is a F, move forward
      {    
        //Serial.println("Forward...");
        digitalWrite(pinForward,HIGH);
        digitalWrite(pinBack,LOW); 
        analogWrite(pinSpeedForwardBack,commands[1]);
        leftRight.write(commands[2]);
        //Serial.print("Forward ");
        //Serial.print(commands[1]);
        //Serial.println(commands[2]);
      }  
      else if(commands[0] == 0xf2)   //if incoming data is a B, move back
      {    
        digitalWrite(pinForward,LOW);
        digitalWrite(pinBack,HIGH); 
        analogWrite(pinSpeedForwardBack,commands[1]);
        leftRight.write(commands[2]);
        //Serial.print("Back ");
        //Serial.print(commands[1]);
        //Serial.println(commands[2]);
      }
      else if(commands[0] == 0xf3)   //if incoming data is a S, stop
      {
        digitalWrite(pinForward,LOW);
        digitalWrite(pinBack,LOW); 
        analogWrite(pinSpeedForwardBack,commands[1]);
        leftRight.write(commands[2]);          
        //Serial.print("Stop ");
        //Serial.print(commands[1]);
        //Serial.println(commands[2]);
      }
      else if(commands[0] == 0xf6)   //Back and front lights
      {
        if(commands[1]==0x01){  //back lights on
          digitalWrite(pinbackLights,HIGH);              
        }
        else if(commands[1]==0x00){  //back lights off
          digitalWrite(pinbackLights,LOW);                
        }
        if(commands[2]==0x01){  //front lights on
          digitalWrite(pinfrontLights,HIGH);
        }
        else if(commands[2]==0x00){  //front lights off
          digitalWrite(pinfrontLights,LOW);              
        }            
      }        
      else if(commands[0] == 0xf8)  //Extra button 1  
      {
        if((commands[1]==0x01)&&(commands[2]==0x01)){
          digitalWrite(extra1,HIGH);             
        }
        else if((commands[1]==0x00)&&(commands[2]==0x00)){
          digitalWrite(extra1,LOW);                 
        }
      }
      else if(commands[0] == 0xf9)  //Extra button 2   
      {
        if((commands[1]==0x01)&&(commands[2]==0x01)){
          digitalWrite(extra2,HIGH);                  
        }
        else if((commands[1]==0x00)&&(commands[2]==0x00)){
          digitalWrite(extra2,LOW);                 
        }
      }
      else if(commands[0] == 0xfa)  //Extra button 3
      {
        if((commands[1]==0x01)&&(commands[2]==0x01)){
          digitalWrite(extra3,HIGH);                  
        }
        else if((commands[1]==0x00)&&(commands[2]==0x00)){
          digitalWrite(extra3,LOW);                 
        }
      }
      else if(commands[0] == 0xfb)  //Extra button 4   
      {
        if((commands[1]==0x01)&&(commands[2]==0x01)){
          digitalWrite(extra4,HIGH);                  
        }
        else if((commands[1]==0x00)&&(commands[2]==0x00)){
          digitalWrite(extra4,LOW);                 
        }
      }
      else if(commands[0] == 0xfc)  //Extra button 5  
      {
        if((commands[1]==0x01)&&(commands[2]==0x01)){
          digitalWrite(extra5,HIGH);                  
        }
        else if((commands[1]==0x00)&&(commands[2]==0x00)){
          digitalWrite(extra5,LOW);                 
        }
      }  
    }
    else{
      //Resetting the Serial port (clearing the buffer) in case the bytes are not being
      //read in correct order.
      Serial.end();
      Serial.begin(9600);
    }
  }
  if(delayer == 20000){  //Increasing the value makes the reading smother, but delayed.
    reading0 = analogRead(0);  //Taking in a sensor's signal.
    reading1 = analogRead(1);
    reading2 = analogRead(2);
    reading0 = reading0 >> 2;  //Changing the range of the reading from 0-1024 to 0-255.
    reading1 = reading1 >> 2;
    reading2 = reading2 >> 2;
    //The leading byte 0xff (255) will let the app know that a new set of readings follow. This is
    //the reason why the sensor readings have a range of 0x00 to 0xfe (254).
    sensors[0] = 0xff;  
    sensors[1] = (byte) constrain(reading0,0,254); 
    sensors[2] = (byte) constrain(reading1,0,254); 
    sensors[3] = (byte) constrain(reading2,0,254); 
    Serial.write(sensors,4);  //Sending the readings.       
    delayer = 0;  //Resetting the delay variable.
  }
  delayer += 1;  //Incrementing the delay variable.
}

void stopMovement()
 {
        digitalWrite(pinForward,LOW);
        digitalWrite(pinBack,LOW); 
        analogWrite(pinSpeedForwardBack,commands[1]);
        leftRight.write(commands[2]);          
        //Serial.print("Stop ");
        //Serial.print(commands[1]);
        //Serial.println(commands[2]);
  }

15 November 2013

We now try to get closer to an ultimate RC controller.

I addressed the pitches.h library by adding the file.

We added timedAction.h library for "super loops", regarding flashing of led's and obstacle avoidance with ping sensor.

We experience some sort of delays on the extra buttons commands received from the phone application and will be addressed soon.

Here a picture of the bench setup: UNO, Bluetooth sheild, dc brushed motor, ping sensor, led indication, small motordriver board and servo, all with the same android application from the play store.

 

 

 

 



Photo Gallery
Arduino Android Bluetooth RC Car

This is my third arduino controlled RC car with an Android application from the market.
20130401123849 Medium.jpg 20130401124021 Medium.jpg 20130403091610 Medium.jpg 20130405172618 Medium.jpg 20130405172805 Medium.jpg 20130405172901 Medium.jpg 20130406110434 Medium.jpg 20130406110451 Medium.jpg 20130406110501 Medium.jpg 20130406110509 Medium.jpg 201304061138521 Medium.jpg 20130709110326 Medium-574.jpg 20130709110332 Medium-2240.jpg 20130709110344 Medium-3606.jpg 20130706142730 Medium-1540.jpg 20130711113156 Medium-3270.jpg 20130711114957 Medium-3519.jpg 20130711115027 Medium-4297.jpg 20130711115244 Medium-4973.jpg 20130711115257 Medium-1568.jpg 20130711113156 Medium-1299.jpg 20130711114957 Medium-3550.jpg 20130711115027 Medium-1044.jpg 20130711115244 Medium-2364.jpg 20130711115257 Medium-327.jpg 20130711113156 Medium-1500.jpg 20130711114957 Medium-4589.jpg 20130711115027 Medium-1596.jpg

20130401123849 Medium.jpg

The chassis and body stripped to be replaced by arduino control


Back Back to top