I have been interested in embedded electronics for a few years now, so I decided to build a robot. Right now, its fairly boring, but the great thing about it is there is tons of room for expansion. Let me know what you all think!
All the parts are from radio shack, mouser and sparkfun, except for the wood, from michaels, and the tamiya gearbox, motors and treads, from amazon.com.
Top view, arduino and electronics are on a breadboard stuck to a piece of wood over the gearbox. Plenty of room for expansion. The motors run of 3 AA batteries, and the arduino runs from a 9 volt. THe motor driver is an l293d.
The photo below shows the gearbox and treads, and my paperclip and wire obstacle detector.
Oh, and my personal favorite part, the blue LED power switch:
So? What do you think? Anything i did horribly wrong? What is the first sensor/arm/expansion i should add?
Thanks!
EDIT: I included my code below:
int portmotor[] = {6,7}; //Left motor drive pins.
int starboardmotor[] = {4,5}; //Right motor drive pins
int portenable = 10; //Left enable
int starboardenable = 11; //Right enable
void setup()
{
pinMode(portmotor[0],OUTPUT);
pinMode(portmotor[1],OUTPUT);
pinMode(starboardmotor[0],OUTPUT);
pinMode(starboardmotor[1],OUTPUT);
pinMode(portenable, OUTPUT);
pinMode(starboardenable, OUTPUT);
}
void loop()
{
forwards(255); //Go forwards at full speed. For all motor functions, the speed is a PWM number. The motors need at least a PWM of 200, thus the speed range is 200 to 255.
delay(1000);
if(analogRead(3) > 900) //Every 1000 seconds, poll the obstacle detector, if it is pushed, run the avoid routine.
{
avoid();
}
}
void avoid()
{
stopall();
portbackwards(225);
delay(2000);
}
void portbackwards(int speed) //Left motor backwards
{
analogWrite(portenable, speed);
digitalWrite(portmotor[0],HIGH);
digitalWrite(portmotor[1],LOW);
}
void portforwards(int speed) //Left motor forwards
{
analogWrite(portenable, speed);
digitalWrite(portmotor[0],LOW);
digitalWrite(portmotor[1],HIGH);
}
void portstop() //Left motor stop.
{
analogWrite(portenable, 0);
digitalWrite(portmotor[0],LOW);
digitalWrite(portmotor[1],LOW);
}
void starboardbackwards(int speed) //Right motor backwards
{
analogWrite(starboardenable, speed);
digitalWrite(starboardmotor[0],HIGH);
digitalWrite(starboardmotor[1],LOW);
}
void starboardforwards(int speed) //Right motor forwards
{
analogWrite(starboardenable, speed);
digitalWrite(starboardmotor[0],LOW);
digitalWrite(starboardmotor[1],HIGH);
}
void starboardstop() //Stop right motor.
{
analogWrite(starboardenable, 0);
digitalWrite(starboardmotor[0],LOW);
digitalWrite(starboardmotor[1],LOW);
}
void forwards(int speed) //Turn on both motors at the same time for a straight course.
{
int newspeed = speed - 10; //Compensate for the robot's weight imbalance.
analogWrite(starboardenable, speed);
analogWrite(portenable, newspeed);
digitalWrite(starboardmotor[0],LOW);
digitalWrite(portmotor[0],LOW);
PORTD = PORTD | B10100000;
}
void stopall() //Stop both motors, using port manipulation.
{
PORTD = PORTD & B00001111;
}