Infrared Controlled Autonomous Vehicle with video!
by Irvin De La Paz on 12/07/10 at 9:58 am
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;
}
}
}
}



A mechanical engineer trying to make a difference while learning, experimenting and applying different technologies. If you would like to contribute to this blog you can contact him at irvin de la paz @ upr. edu.
Irvin De La Paz
Jul 17th, 2010
Video Uploaded