Zwally, Scott

Project created by Scott Zwally

Project Name: IR Remote Controlled Vehicle / Edge Tracking Vehicle

Brief Description: While searching for ideas, I spotted a project where someone created a robot that can track a ball filled with IR lights and play soccer. I thought to create a robot to do that, but instead I decided to create a robot that responds to commands given by an IR remote. Later, I added a way where it can tell if it's on or off a table and not fall off the table. Then I decided to make it autonomous and be able to move around the edge of a table without falling off.

Detailed Description: With the first part, responding to an IR remote, I downloaded the IRremote library found on Ken Shirriff's blog and got the code values for the IR remote using IRrecvDemo. Using the code below, I assigned the various codes to make the robot move forward, backward, turn clockwise and counterclockwise, and stop. Then I added the distance sensors, which take a digital read to see whether they are on or off. With the addition of distance sensors, I made it so that if the robot views itself as being on the table, it follows the IR remote commands, and if views itself as being off of it, it backs up and starts turning clockwise. When I made it autonomous with edge-tracking capabilities, I used the distance sensor so that if it's on the table, it slowly turns towards the edge, but if it sees itself as of the table, it turns away from the edge. This gives the robot a waddling motion rather than a smooth one. When using the IR remote program, I had the distance sensors hanging forward and looking downwards, but when I had it be autonomous, I had the one distance sensor forward of the robot and looking at the ground at about a 45 degree angle with the ground so it could make corners safely.

Here's the program for the vehicle using the IR remote:

#include <Servo.h>

#include <IRremote.h>

int distanceSensorL = 5;

int distanceSensorR = 8;

int distanceStateL;

int distanceStateR;

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

Servo ServoL;

Servo ServoR;

void setup() {

pinMode(5, INPUT);

pinMode(8, INPUT);

ServoL.attach(16);

ServoR.attach(17);

Serial.begin(9600);

irrecv.enableIRIn(); // Start the receiver

}

void loop() {

distanceStateL = digitalRead(5); //reads both

distanceStateR = digitalRead(8); // sensors

if (distanceStateL == HIGH || distanceStateR == HIGH) { //off the table

// Serial.println("off"); // test for distance sensors

ServoL.write(0);

ServoR.write(180); // if it's off, backup for a half a second

delay(500);

ServoL.write(180); // then turn clockwise

ServoR.write(180);

} else if (distanceStateL == LOW && distanceStateR == LOW) { //on the table

// Serial.println("on"); // test for distance sensors

if (irrecv.decode(&results)) { //takes in commands from the IR remote

Serial.println (results.value);

if (results.value == 3779361413) { //forward

ServoL.write(180);

ServoR.write(0);

} else if (results.value == 3779331833) { //backward

ServoL.write(0);

ServoR.write(180);

} else if (results.value == 3779381813) { //right

ServoL.write(180);

ServoR.write(180);

} else if (results.value == 3779349173) { //left

ServoL.write(0);

ServoR.write(0);

} else if (results.value == 3779385893) { //stop

ServoL.write(90);

ServoR.write(90);

}

irrecv.resume(); //resumes taking in commands; do not leave out!

}

}

}

Here's the code for the edge-tracking, autonomous vehicle:

#include <Servo.h>

int distanceSensorL = 5;

//int distanceSensorR = 8; //only use if the right sensor will be hanging off the table instead of the left sensorint distanceStateL;

//int distanceStateR;Servo ServoL;

Servo ServoR;

void setup() {

pinMode(5, INPUT);

// pinMode(8, INPUT); ServoL.attach(16);

ServoR.attach(17);

Serial.begin(9600);

}

void loop() {

distanceStateL = digitalRead(5);

// distanceStateR = digitalRead(8); if (distanceStateL == HIGH) { //off the table Serial.println("off");

ServoL.write(180); //turn away from edge ServoR.write(89);

} else if (distanceStateL == LOW) { //on the table Serial.println("on");

ServoL.write(91); //turn towards edge ServoR.write(0);

}

}

Problems Encountered:

1. I was having troubles with the distance sensors working with the servos; the distance sensors would always view themeselves as on the table. So then I added the disk capacitors to the sensors and everything worked out there.

2. Also, with the IR sensor, the distance sensors, and the servos working, be sure to use a 9 volt battery, because the robot won't respond to commands all that well and won't sense itself as being off the table.

3. When you are getting your IR signals from your remote using the IRrecvDemo program from the IRremote file, be sure to remove "HEX" or the robot won't respond to your commands.

4. If the robot doesn't respond well to commands when the IR receiver is facing away from the remote, extend the IR receiver and place it on the top with the dome facing the ceiling.

5. If the light in the distance sensors is flickering while edge-tracking and the robot keeps falling off, replace the 9-volt battery and everything should work out.

6. I noticed that when the robot is receiving IR signals, zeros appear. Sometimes, they messed up the command signals sent, other times, they don't visibly affect the performance. They started appearing when before they didn't, and I don't know what caused them to appear or how to fix them if they interrupt the IR signal.

7. When doing testing and loading the programs, it helps to make a stand and put your robot on it so it doesn't go anywhere or fall off. I made mine out of Lego.

Additions if I had more time and/or money:

1. I would make the robot perform the tasks it originally was meant for: go around a table putting foam cups over PVC pipes, pushing stuff off the table, and taking in measurements.

2. I would replace the tape with something more permanent, like glue.

3. I would add a piezo so that when it backs-up, it makes a beeping sound.

4. I would make another one and make the original send IR signals to the other one so that it follows the first car.