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

 

 



0807214

Well, on its way to be ultimate RC control.

This entry is now a combination of all previous RC control attempts on my website.

Lots of features added and see the code for more details.

Thanks to Wynand Wolmarans from H4H who is always willing to coach me with the programming in C.

Thank to the developer for both the original Arduino sketch and android application update.

/*

//1.0.5 UNO R3
//Motordriverboard: TB6612F sparkfun/on protoboard, not in car. In car current is a polulo 30 motordriverboard.
/* This code make use of timedaction.h libraries to accommodate interrupts being the blinking led's.

 Also the l293.h library included.

 The codes play a James Bond melody for intro after switch on of the circuit.
 Also battery voltage monitor included.LED indication.
 Obstacle avoidance(antichrash) with ping only front fixed sensor SRF02 and not on pan and tilt.
 SRF02:PCB back referred: +5VDC left top corner.
 Second pin from top left   = A4 : I2C
 Third pin from top            = A5 : I2C
 Fourth pin from top         = Unused for I2C
 Bottom pin                    = Ground
 Buzzer for horn (polarity involved).
 8 Ohm speaker for melody.
 Application from the play market with speedcontrol and servo control.Joystick website:
 
 Bluetooth module.
 Motordriverboard.L298 or similar.
 PSU for 5v and 3V3 respectively.Voltage regulated.
 Existing brushed motor. Existing gearbox on stripped RC car.4 wheel drive monster truck HSP stripped from its inside electronics.
 Existing Servo for front steering.
 Existing NiMH battery(7.2 to 11VDC) and switch.
 100K and 10K quarter watt in series resistor devider on A1. Top +5V, lower gnd and middle to A1.Voltage monitor.
 My supply voltage max 14VDC.From here 6VDC for servo!
 Note:Connect servo to its own supply and not from the arduino board.
 LDR:4K7 resistor.A0
 OPEN; A2 and A3 (Can be featured use for extraPin3 and extraPin5 controlled from phone).
 On mini A6 and A7 too.

*/

It is also the latest upgrade android application by the developer. He also improved a lot of enhancements. 

Sketch:

#include "pitches.h"            //Library file tone
#include "Wire.h"
#include "SRF02.h"              //Ping library 
#include
#include
#include        //Like super loop
#define NO_SOUND 0              // make the rests in music
#define pinForward 8     
#define pinBack 7       
#define pinSpeedForwardBack 6
#define pinFrontLights 2
#define pinBackLights 3
#define pinFrontSteering 10
int extra5           =    12;   //Horn buzzer with polarity
int extra4           =    13;   //Blue rooftop leds blinking with timedaction blink interrupt
int voltLedpin       =     5;   //Output for voltage monitor LED.
int emergencySpeed   =   150;  //set speed to reverse motor for emergency stop.
//int distance         =     0;
int carSpeed         =     0;
int speakerPin       =     9;    //Melody on 8 ohm speaker
int pace             =  1600; // change pace of music("speedy")
int melody[] =
{
  //Introduction://array of notes
  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
};
int noteDurations[] =
{
  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
};// note duration: 1 = whole note, 2 = half note, 4 = quarter note, 8 = eighth note, etc.


//L293(pinForward, pinBack, pinFwdBakVel);
L293 redCar(pinForward,pinBack,pinSpeedForwardBack);
TimedAction timedAction = TimedAction(250, blink); //This initializes a TimedAction class that will change the state of an LED every quarter second
Servo leftRight;
boolean ledState = false;

//Battery supply voltage monitor
int analogInput = 1;//A1
float vout = 0.0;
float vin  = 0.0;
float R1   = 100000.0; // resistance of R1 (100K) -see text!
float R2   = 10000.0; // resistance of R2 (10K) - see text!
int value  = 0;

byte commands[4] = 
{
  0x00,0x00,0x00,0x00};
byte prevCommands[4] = 
{
  0x01,0x01,0x01,0x01};
//Variables will be used to determine the frequency at which the sensor readings are sent 
//to the phone, and when the last command was received.  
unsigned long timer0 = 2000;  //Stores the time (in millis since execution started) 
unsigned long timer1 = 0;  //Stores the time when the last sensor reading was sent to the phone
unsigned long timer2 = 0;  //Stores the time when the last command was received from the phone
//14 byte payload that stores the sensor readings
byte three[14] = 
{
  0xee,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xcc};
//Constant used to caculate the 9V battery voltage
float stepConstant = 9.04;
//The union allows you to declare a costumized data type, in this case it can be either 
//a float or a byte array of size 4. What we need is to store a float which is 4
//bytes long and retrieve each of the 4 bytes separatelly.
union u_sensor0
{
  byte a[4];  
  float b;
}
sensor0;
union u_sensor1
{
  byte c[4];  
  float d;
}
sensor1;
int i = 0;

SRF02 srf02[1] = 

  SRF02(0x70, SRF02_CENTIMETERS),
  //SRF02(0x71, SRF02_CENTIMETERS), 
  //SRF02(0x72, SRF02_CENTIMETERS)
};

unsigned long nextPrint = 0;

/*Intelligent Lighting*/
#define ldrPin       0   //LDR and resistor 4k7. A0
int parklightPin =  11; // Pin used for parkLight Led.
int inVal        =   0; // variable used to store state of input
int switchOn     =  80; // value at which we switch parkLightPin on.

/*static int vccRead (byte us = 250)
 {
 analogRead(6);//setup "almost" the proper ADC readout
 bitSet(ADMUX, 3);//then fix it to switch to channel 14
 delayMicroseconds(us);//delay substantially imroves accuracy
 bitSet(ADCSRA, ADSC);
 while (bit_is_set(ADCSRA, ADSC));
 word x = ADC;
 return x ? (1100L * 1023) / x : -1;
 }
 int ledPin = 5;*/

void setup()

  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.
  }  
  Serial.begin(9600); 
  Serial.println("\n[bandgap]");
  Wire.begin(); 
  pinMode(pinFrontLights, OUTPUT);
  pinMode(pinBackLights, OUTPUT);
  pinMode(speakerPin, OUTPUT);
  pinMode(parklightPin, OUTPUT);
  pinMode(voltLedpin, OUTPUT);
  pinMode(extra4, OUTPUT);
  pinMode(extra5, OUTPUT);
  pinMode(ldrPin, INPUT);

  leftRight.attach(pinFrontSteering);
  timedAction.disable();             //We disable the blinking leds now and will activate with button from application on phone.
  digitalWrite(extra4, ledState);
  SRF02::setInterval(75);
}

void loop()
{
  /*analogRead(0);//just to checkthat it doesnt affect result
   Serial.println(vccRead());
   delay(500);
   
   if (vccRead() <= 1101)
   {
   digitalWrite(ledPin, HIGH);
   delay(10);
   digitalWrite(ledPin, LOW);
   delay(1000);
   }*/

  SRF02::update();
  if (millis() > nextPrint)
  {
    int distance = srf02[0].read();
    float stopDistance = 1.0 * (float) carSpeed;
    if (distance > 0 && distance <= 
    stopDistance && commands[0] == 0xf1)
    {
      EmergencyStop();
    }
    //Serial.print(distance);
    // Serial.println("cm");
    // Serial.print(",");
    //Serial.print(srf02[1].read());
    //Serial.print(",");
    //Serial.print(srf02[2].read());
    //Serial.println();
    nextPrint = millis () + 1000;
  }
  timedAction.check();                    //Our blink leds interruption
  Intelligentlighting();                  //May be to the setup????
  voltageMonitor();                       //Led battery voltage indication. 

  if(Serial.available()==4)
  {
    timer2 = millis();  //Store the time when last command was received
    memcpy(prevCommands,commands,4);  //Storing the received commands   
    commands[0] = Serial.read();  //Direction
    commands[1] = Serial.read();  //Speed
    commands[2] = Serial.read();  //Angle
    commands[3] = Serial.read();  //Lights and buttons states
    /*
     Since the last byte yields the servo's angle (between 0-180), it can never be 255. At times, the two
     previous commands pick up incorrect values for the speed and angle. Meaning that they get the direction 
     correct 100% of the time but sometimes get 255 for the speed and 255 for the angle.
     */
  }
  if((commands[2]<=0xb4)&&((commands[0]<=0xf5)&&(commands[0]>=0xf1)))
  {
    //Make sure that the command received involves controlling the car's motors (0xf1,0xf2,0xf3)
    if(commands[0] <= 0xf3)
    {
      if(commands[0] == 0xf1)
      {  //Check if the move forward command was received
        if(prevCommands[0] != 0xf1)
        {  //Change pin state to move forward only if previous state was not move forward
          redCar.forward_1W(commands[1]);
          //Serial.println("Updated direction FWD");
        }  
      }
      else if(commands[0] == 0xf2)
      {  //Check if the move back command was received     
        if(prevCommands[0] != 0xf2)
        {  //Change pin state to move back only if previous state was not move back
          redCar.back_1W(commands[1]);
          //Serial.println("Updated direction BAK");
        }
      }
      else
      {  //Check if the stop command was received    
        if(prevCommands[0] != 0xf3)
        {  //Change pin state to stop only if previous state was not stop
          redCar.stopped_1W();   
          //Serial.println("Updated direction STP");
        }
      }
      //Change speed only if new speed is not equal to the previous speed
      if((prevCommands[1] != commands[1]) && ((prevCommands[0] == 0xf1)||(prevCommands[0] == 0xf2)||(prevCommands[0] == 0xf3)))
      {
        redCar.setSpeed_1W(commands[1]);
        carSpeed = commands[1];
        //Serial.println("Updated speed " + commands[1]);
      }          
      //Steer front wheels only if the new angle is not equal to the previous angle
      if(prevCommands[2] != commands[2])
      {
        leftRight.write(commands[2]);  
        //Serial.println("Updated angle"); 
      }  
      if(prevCommands[3] != commands[3])
      {
        //Serial.println(commands[3],BIN);
        //Change the light/button states
        //               _______________________________________________
        //command[3] =  |  0  |  0  |  0  |  0  |  0  |  0  |  0  |  0  |  binary
        //              |_____|_____|_____|_____|_____|_____|_____|_____|
        //Buttons ---->  Front  Back  Horn   A     B     C     D     E   
        //Front lights
        if((bitRead(prevCommands[3],7))!=(bitRead(commands[3],7)))
        {
          if(bitRead(commands[3],7))
          {
            digitalWrite(pinFrontLights,HIGH);
          }
          else
          {
            digitalWrite(pinFrontLights,LOW);
          }
        }
        //Back lights
        if((bitRead(prevCommands[3],6))!=(bitRead(commands[3],6)))
        {
          if(bitRead(commands[3],6))
          {
            digitalWrite(pinBackLights,HIGH);
          }
          else
          {
            digitalWrite(pinBackLights,LOW);
          }
        }
        //Horn 
        if((bitRead(prevCommands[3],5))!=(bitRead(commands[3],5)))
        {
          if(bitRead(commands[3],5))
          {
            digitalWrite(extra5, OUTPUT);
          }
          else
          {
            digitalWrite(extra5,LOW); 
          }
        }
        //Blinking rooftop leds with timedaction
        if((bitRead(prevCommands[3],4))!=(bitRead(commands[3],4)))
        {
          if(bitRead(commands[3],4))
          {
            timedAction.enable();          // Begin blink led's
          }
          else
          {
            timedAction.disable();        // Stop blinking the leds 
          }
        }
      }
      else if(commands[0] == 0xf5)
      {
        //Stop everything
        redCar.stopped_1W(); 
        digitalWrite(pinFrontLights,LOW);
        digitalWrite(pinBackLights,LOW);
      }
      else
      {
        //Here you put the code that will control the tilt pan (commands[0] == 0xf4)   
      }     
    }
    else
    {
      //Resetting the Serial port (clearing the buffer) in case the bytes are not being read in correct order.
      Serial.end();
      Serial.begin(9600);
    }
  }
  else
  {
    timer0 = millis();  //Get the current time (millis since execution started)
    if((timer0 - timer2)>400)
    {  //Check if it has been 400ms since we received last command
      //More tan 400ms have passed since last command received, car is out of range. Therefore
      //Stop the car and turn lights off
      redCar.stopped_1W();  
      digitalWrite(pinFrontLights,LOW); 
      digitalWrite(pinBackLights,LOW);
    }
    if((timer0 - timer1)>=477)
    {  //Check if it has been 477ms since sensor reading were sent
      sensor0.b = (analogRead(0) * stepConstant) * 0.001;  //Calculate the 9V's voltage
      //Break the sensor0 float into four bytes for trasmission
      three[1] = sensor0.a[0];
      three[2] = sensor0.a[1];
      three[3] = sensor0.a[2];
      three[4] = sensor0.a[3];
      //Break the sensor1 float into four bytes for trasmission
      sensor1.d = map((sensor0.b * 100),615,900,10,100);  //Calculate the 9V's %
      three[5] = sensor1.c[0];
      three[6] = sensor1.c[1];
      three[7] = sensor1.c[2];
      three[8] = sensor1.c[3];
      //Get the remaining reading from the analog inputs
      three[9] = map(analogRead(2),0,1023,0,255);
      three[10] = map(analogRead(3),0,1023,0,255);
      three[11] = map(analogRead(4),0,1023,0,255);
      three[12] = map(analogRead(5),0,1023,0,255); 
      //Send the six sensor readings
      Serial.write(three,14);
      //Store the time when the sensor readings were sent
      timer1 = millis();
    }
  }
}
void blink()
{
  ledState ? ledState = false : ledState = true;
  digitalWrite(extra4, ledState);
}

void Intelligentlighting()

{
  inVal = analogRead(ldrPin);                 // Read state of the input pin
  //Serial.println(inVal);
  //delay(550);
  if(inVal <= switchOn)
  {
    digitalWrite(parklightPin, HIGH);
  }

  else
  {
    digitalWrite(parklightPin, LOW);
  }
}

void EmergencyStop()
{
  digitalWrite(pinBackLights, HIGH);              //Backlights on to indicate emergency stop.
  tone(extra5, 500);                              //Buzzer tone audio to indicate emergency.
  digitalWrite(pinForward, LOW);                  //this stops the motor turning. Both pins to LOW
  digitalWrite(pinBack, LOW);
  delay(200);                                     //Vary this just enough to see the car stop,
  digitalWrite(pinForward, LOW);                  //This reverse the motor after stop
  digitalWrite(pinBack, HIGH);
  analogWrite(pinSpeedForwardBack, emergencySpeed); //The motor reverse with this speed set on top.
  delay(750);                                    //Delay after reverse and motor stop again.Hopefully without momentum again!!
  //Vary delay accordingly to get momentum to a minimum backwards run.
  digitalWrite(pinForward, LOW);                  //Motor stop without momentum.
  digitalWrite(pinBack, LOW);
  digitalWrite(pinBackLights, LOW);               //Backlights off again.
  noTone(extra5);                                 //Make sure the buzzer wont buzzzz.
  delay(1);                                       //The end of the emergency stop,and code ready to return
  Serial.end();//Resetting the Serial port (clearing the buffer) in case the bytes are not being read in correct order.
  Serial.begin(9600);
}

void voltageMonitor()

{
  // read the value at analog input
  value = analogRead(analogInput);
  vout = (value * 4.85) / 1024.0; // see text
  vin = vout / (R2/(R1+R2));
  //Serial.println(vout);

  if (vout <= 0.74)
  {  
    digitalWrite(voltLedpin, HIGH);
  }
  else
  {
    digitalWrite(voltLedpin, LOW);
  }
}



Photo Gallery
Ultimate RC Control

On its way to be ultimate RC control.

 


20140610135532 Mobile-4694.jpg 20140701173840 Mobile-3948.jpg 20140701173904 Mobile-3901.jpg 20140701173955 Mobile-200.jpg 20140701174013 Mobile-4561.jpg 20140701174043 Mobile-4075.jpg 20140702182737 Mobile-1069.jpg 20140702182801 Mobile-1067.jpg Screenshot20140708124635 Mobile-1557.png 20140708165836 Mobile-2718.jpg 20140708165859 Mobile-3152.jpg 20140708165913 Mobile-2028.jpg 20140709135610 Mobile-2048.jpg 20140709140702 Mobile-2034.jpg 20140709140738 Mobile-2870.jpg 20140709140803 Mobile-4224.jpg

20140610135532 Mobile-4694.jpg

Back Back to top