Infrared Controlled Autonomous Vehicle with video!

by Irvin De La Paz on 12/07/10 at 9:58 am

Infrared Controlled Autonomous Vehicle with video!

Introduction

It’s been a while since I began experimenting with robots.  Those who know me close enough have known I wanted to do some inventions and microprocessors  knowledge is required to accomplish them. Today I present to you (like a proud parent) my son “ICAV BOT”. ICAV stands for Infrared Controlled Autonomous Vehicle.

Components

The bot components are as followed:

  • 2  L293D H Bridge controlling 4 motors! (There are 4 in total but I only use 2)
  • 74HC595N shift register chip (component of Lady Ada Motor shield)
  • ATmega328 based platform (Arduino Duemilanove<– dev board)
  • Buzzer 3 volt
  • Infrared demodulator 38 khz!
  • Aluminum chassis
  • SPDT Switch <— Better is DPST to turn ON/OFF arduino duemilanove and Motor shield

Behavior

  • Decides by itself where he wants to go  (Autonomously)
  • Generates  sound tones from frequency  128hz to 4500 hz
  • Can be controlled with any infrared controller for drone operation
  • No other sensor is present

Video

Construction Pics

Source Code

Infrared Controlled Autonomous Vehicle (ICAV) by Irvin De La Paz is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

/*
#==================================================
#    Infrared Controlled Autonomous Vehicle  ICAV #
#                       V1.0                      #
#         Code by Irvin De La Paz                 #
#         Irvin+robot@irvindelapaz.com            #
#         Website:www.irvindelapaz.com            #
#        Licensed under Creative Commons          #
#Attribution-NonCommercial-ShareAlike 3.0 Unported#
#=================================================#
*/
#include  //MOTOR Library
#include  //Infrared Receiver Library

AF_DCMotor motor3(3, MOTOR12_64KHZ);
AF_DCMotor motor4(4, MOTOR12_64KHZ);

int RemoteMode=0; // Infrared drone mode, 0=off / 1=on
int LastProccessID; //store last proccess id for comparative value
int ProccessID;  //will store random behavior of robot
long time;   //time the robot has been on
long  randomtime; //random time  behavior will last
long randomizer; //store how long proccess id should last

//Declaring music part

int BuzzerPin = 14;
int length = 64; // the number of notes
int beats[64]; //Holds the time of each note 64 been the maximum number of values it can hold
int tempo = 25;
// InfraRed  Part
int Irsensor = 16;
IRrecv irrecv(Irsensor);
#define UP 0x80FF58A7
#define DOWN 0x80FFC837
#define FAN  0x80FF708F
#define MODE 0x80FF40BF
#define POWER 0X80FF48B7
#define TIMER 0X80FFD827
decode_results results;
//=====FUNCTIONS===============

void GetMeRandom(void){
  ProccessID = random(0,6);
  time = millis();
  randomizer= random(2000,4500);
  randomtime = time + randomizer;
  //randomSeed(analogRead(0));
                      }
// RANDOM PROCCESSES FUNCTIONS
void directo(void){
  motor3.run(FORWARD);
  motor4.run(FORWARD);
}
void StopAll(void){
  motor3.run(RELEASE);
  motor4.run(RELEASE);
}

void CirculoD(void){ //Turn right
  motor3.setSpeed(200);
  motor4.setSpeed(200);
  motor3.run(BACKWARD);
  motor4.run(FORWARD);
}  

void CirculoI(void){ //Turn left
  //motor1.run(BACKWARD);
  //motor2.run(FORWARD);
  motor3.setSpeed(200);
  motor4.setSpeed(200);
  motor3.run(FORWARD);
  motor4.run(BACKWARD);  

}

void Reverse(void){
  motor3.run(BACKWARD);
  motor4.run(BACKWARD);
}

void deccelerate(void){
int i;
for (i=255; i!=0; i--) {
    motor3.setSpeed(i);
    motor4.setSpeed(i);
    delay(10);
  }
}

void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(BuzzerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(BuzzerPin, LOW);
delayMicroseconds(tone);
  }
}

void randomizebeats(void){
  length=random(4,50); //declaring the number of notes to be played
  for (int i=0; i < length; i++) {
   beats[i]=random(0,7); //declaring the duration of each note
  }
}

void playNote(int duration) {
    int tones[65] = {123,131,139,147,156,165,175,185,196,208,220,233,247,262,277,294,311,330,349,370,
    392,415,440,466,494,523,554,587,622,659,698,740,784,831,880,932,988,1047,1109,1175,1245,1319,1397,
    1480,1568,1661,1760,1865,1976,2093,2217,2349,2489,2637,2794,2960,3136,3322,3520,3729,3951,4186,4435,4699,4978};
    int i  = random(0,64);
    playTone(tones[i], duration);

}

//=====END OF FUNCTIONS========

void setup() {
  irrecv.enableIRIn(); // Start the receiver
  pinMode(BuzzerPin, OUTPUT);
  Serial.begin(9600);
  //motor1.setSpeed(160);
  //motor2.setSpeed(160);
  motor3.setSpeed(160);
  motor4.setSpeed(160);
  randomizebeats();
  delay (5000);
}

void loop() {
long codigorecibido; //store code received
  if (irrecv.decode(&results)) {

    if (results.value == POWER && RemoteMode ==0 ) {
                  RemoteMode = 1; }

          delay (250);
          irrecv.resume();
          //Just for debugging
          //Serial.println("Primer comando exitoso");
          //Serial.println(RemoteMode);
          //Serial.println(results.value,HEX);

  }

while (RemoteMode == 1) {
if (irrecv.decode(&results)) {
    if (codigorecibido != results.value)
    {
        codigorecibido = results.value;
      //Serial.println("Estoy en while");
    delay(250);
    irrecv.resume();
    }

if (irrecv.decode(&results)) {
  Serial.println("STOPPING ALL");
  StopAll();
  codigorecibido=123456;
  delay(250);
  irrecv.resume();
  }
                          }
  switch (codigorecibido) {
      case DOWN:
        Serial.println("A");
        directo();
        break;
      case UP:
       Reverse();
       Serial.println("B");
       break;
      case MODE:
        CirculoI();
        Serial.println("C");
        break;
      case FAN:
        CirculoD();
        Serial.println("D");
        break;
      case POWER:
       RemoteMode =0;
       break;
      case TIMER:
        randomizebeats();
           for (int i = 0; i < length; i++) {
              playNote(beats[i] * tempo);
              delay(tempo / 2);  // pause between notes
           }
       break;
      default:
        break;
                         }
                      }

while (RemoteMode == 0) {
GetMeRandom();
StopAll();

Serial.println(ProccessID);
Serial.println(randomizer);

  while(time < randomtime) {
    if (irrecv.decode(&results)) {
     RemoteMode =1;
     time =millis()+randomtime;
      break;}
    if (ProccessID == 0)
    {   //Serial.println("Empezo a viajar derecho!");
        directo();
        time = millis();}

   else if (ProccessID == 1)
    {   //Serial.println("Empezo CirculoD");
        CirculoD();
        time = millis();}    

   else if (ProccessID == 2)
    {   //Serial.println("Empezo CirculoI");
        CirculoI();
        time = millis();}   

  else if (ProccessID == 3)
    {   //Serial.println("Empezo Reverse");
        Reverse();
        time = millis();}
  else {
     //Serial.println("que rayos, un 5!");
     randomizebeats();
     for (int i = 0; i < length; i++) {
        playNote(beats[i] * tempo);
        delay(tempo / 2);  // pause between notes
}

     break;
   }
        }

}
  }

One Response to “Infrared Controlled Autonomous Vehicle with video!”

  1. Irvin De La Paz

    Jul 17th, 2010

    Video Uploaded

Leave a Reply




PHVsPjxsaT48c3Ryb25nPndvb19hZHNfcm90YXRlPC9zdHJvbmc+IC0gdHJ1ZTwvbGk+PGxpPjxzdHJvbmc+d29vX2FkXzMwMF9hZHNlbnNlPC9zdHJvbmc+IC0gPHNjcmlwdCB0eXBlPVwidGV4dC9qYXZhc2NyaXB0XCI+PCEtLQ0KZ29vZ2xlX2FkX2NsaWVudCA9IFwicHViLTU4MzMyMzMyNzEyNzYyMDNcIjsNCi8qIDMwMHgyNTAsIGNyZWF0ZWQgMTAvMjAvMTAgKi8NCmdvb2dsZV9hZF9zbG90ID0gXCIyNzU0OTc1Nzg2XCI7DQpnb29nbGVfYWRfd2lkdGggPSAzMDA7DQpnb29nbGVfYWRfaGVpZ2h0ID0gMjUwOw0KLy8tLT4NCjwvc2NyaXB0Pg0KPHNjcmlwdCB0eXBlPVwidGV4dC9qYXZhc2NyaXB0XCINCnNyYz1cImh0dHA6Ly9wYWdlYWQyLmdvb2dsZXN5bmRpY2F0aW9uLmNvbS9wYWdlYWQvc2hvd19hZHMuanNcIj4NCjwvc2NyaXB0PjwvbGk+PGxpPjxzdHJvbmc+d29vX2FkXzMwMF9pbWFnZTwvc3Ryb25nPiAtIGh0dHA6Ly93d3cud29vdGhlbWVzLmNvbS9hZHMvd29vdGhlbWVzLTMwMHgyNTAtMi5naWY8L2xpPjxsaT48c3Ryb25nPndvb19hZF8zMDBfdXJsPC9zdHJvbmc+IC0gIzwvbGk+PGxpPjxzdHJvbmc+d29vX2FkX2ltYWdlXzE8L3N0cm9uZz4gLSBodHRwOi8vd3d3Lndvb3RoZW1lcy5jb20vYWRzL3dvb3RoZW1lcy0xMjV4MTI1LTEuZ2lmPC9saT48bGk+PHN0c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