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

 

 



09/10/2013

Arduino Android Bluetooth RC Hammer.

Again based on the same android application as all the other.

But this time, the code includes James Bond melody with switch on, and included timedaction.h library to accommodate the blinking of leds on one of the extra pins on the application.

What is significant about the timedaction library is the fact that we can blink a led on and off, while the rest of the code is running!

Watch this space, next upgrade will be anticrash, which is already tested but not implemented.

Code:

#include <TimedAction.h>
//this initializes a TimedAction class that will change the state of an LED every second.
TimedAction timedAction = TimedAction(250,blink);
boolean ledState = false;
#include <Servo.h>
Servo leftRight;  //Front steering servo
int pinForward = 8;       
int pinBack = 7;       
int pinSpeedForwardBack = 6;
int pinbackLights = 3;
int pinfrontLights = 2;
int extra1 = 4;//hazards  
int extra2 = 5;//not used
int speakerPin = 9;//Melody 
int extra3 = 11;//not used
int extra4 = 12;//Blue rooftop leds
int extra5 = 13;//Horn
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 NO_SOUND 0 // make the rests in music
#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

//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()
{ 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

// to distinguish the notes, set a minimum time between them.
    delay(duration*1.2);
  }
  
  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(speakerPin,OUTPUT);
  pinMode(extra1,OUTPUT);
  pinMode(extra2,OUTPUT);
  pinMode(extra3,OUTPUT);
  pinMode(extra4,OUTPUT);
  pinMode(extra5,OUTPUT);
  leftRight.attach(10);
  timedAction.disable(); // ons sal hom later enable as die selfoon knoppie gedruk word
  digitalWrite(extra4,ledState);
  }

void loop()
{
    timedAction.check();

    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))){
      //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
      {    
        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)){
           timedAction.enable(); // begin blink          
        }
        else if((commands[1]==0x00)&&(commands[2]==0x00)){
           timedAction.disable(); // hou op blink          
        }
      }
      else if(commands[0] == 0xfc)  //Extra button 5 
        {
        if((commands[1]==0x01)&&(commands[2]==0x01)){
            digitalWrite(extra5, HIGH);
            delay(100);
            digitalWrite(extra5, LOW);
            delay(100);
            digitalWrite(extra5, HIGH);
            delay(100);
            digitalWrite(extra5, LOW);
            delay(100);
            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 blink()
{
  ledState ? ledState=false : ledState=true;
  digitalWrite(extra4,ledState);
}

 



Photo Gallery
Red Hammer RC Bluetooth

Arduino Hammer truck controled from Android application via bluetooth. Blinking led while code is running with timedaction.h library.

Horn, fitted.

Hazard lights and of course front and back lights.


20131003152139 Small-2484.jpg 20131003152216 Small-4799.jpg 20131004153934 Small-3277.jpg 20131004153944 Small-3272.jpg 20131004153957 Small-3686.jpg 20131005113213 Small-1935.jpg 20131005113225 Small-3132.jpg 20131005131505 Small-3201.jpg 20131005131514 Small-2797.jpg 20131005131547 Small-413.jpg 20131005131558 Small-1863.jpg 20131006104414 Small-1437.jpg 20131006104424 Small-1151.jpg 20131006104445 Small-534.jpg 20131009154310 Small-2446.jpg 20131009154322 Small-1368.jpg 20131009154343 Small-1440.jpg 20131009154420 Small-1980.jpg

20131003152139 Small-2484.jpg

Back Back to top