Introduction: Fifty Dollar Box Bot

The objective is to construct a programmable hobby bot that is affordable and simple to make. The parts will be purchased from places such as Wal-Mart, Radio-Shack, any Hobby Store, or online store that is accessible to the public. The price range is 50 dollars or lower for the entirety of the robot.

Step 1: Gather Your Materials

Here is a list of all materials needed to complete the bot and their prices.

-Arduino Uno (The Brain)
http://www.bestofferbuy.com/Arduino-UNO-2011-ATmega328PPU-ATmega8U2-USB-Board-with-USB-Cable-p-77195.html?currency=USD&utm_source=gbase&utm_medium=cse&utm_campaign=gbase_usa&gclid=CPOc5f7p9bYCFQsy4AodOV4AXg
Price: $18.20

-4xAA to barrel jack holder (Power for the Brain)
https://www.sparkfun.com/products/09835
Price: $2.49

-9V Snap Connector (Power for the motors)
https://www.sparkfun.com/products/91
Price: $1.25

-Dual Motor Gearbox
https://www.sparkfun.com/products/319
Price: $10.95

-Motor Driver (Logic Controller between Arduino and Motors)
https://www.sparkfun.com/products/315
Price: $2.35

-Light Sensor
https://www.sparkfun.com/products/9088
Price: $1.50

-Breadboard
https://www.sparkfun.com/products/9567
Price: $5.95

-Hook-up Wire
https://www.sparkfun.com/products/8022
Price: $2.50

-Resistor 10k Ohm
https://www.sparkfun.com/products/10466
Price: $0.50

-Wheels
Two minute maid juice lids were used
with rubber bands wrapped around them
for traction.

-Frame
Any good sized cardboard box

Total Price:
$45.69
(Go buy a towel with the change in case panic ensues)

Some additional notes about the parts list:

Batteries not included.

There are multiple colors of hook up wire that can be used. For the sake of being able to see how I wired everything shown in later steps I used multiple colors.

I did use jumper wires for the leads on the motors again for the sake of having a different color. The hook up wire should suffice.



Step 2: Gather Your Tools

Tools you will need:

-Soldering Iron
-Electrical Tape
-Knife
-Super/Hot Glue
-Wire Strippers
-Sharpies (Red, Green, Black, Blue)

Step 3: Assemble the Gearbox & Attach the Wheels

I chose this step to be first for two reasons

1. If you are using gorrila glue it takes about 2 hours to dry and harden completely.
2. The gearbox assembly is the most complicated portion of the construction.

If you are using gorilla glue remember that both surfaces need to be wet in order for the glue to activate.
Use of a hot glue gun reduces the time by quite a bit and reduces the amount of mess created.

Sparkfun provides a wonderful tutorial on assembling the gearbox linked below.
https://www.sparkfun.com/products/319

Step 4: Soldering the Leads on the Motors

After the leads have been soldered on you can place the motors in the gearbox.

Now to move on to the wiring of the breadboard and arduino.

Step 5: Prep the 9V Snap Connector

The 9V is what is going to power the motors and this will be done through the breadboard the picture above shows what the leads need to look like after stripping them.

I found a piece of heat wrap to put around the loose wires so they would not catch on anything and provide them with a bit of protection.

Step 6: Preparing the Bread Board

Place the H-driver in the breadboard positioned so that pin 1 is in slot 10 E.
The Top left pin is pin one. The Top of the H-Bridge Can be determined by looking for the indent in the chip.

Color the bread board with the sharpie markers accordingly.

All GND/Ground slots will be black.
All 5V/Power slots will be red
All of the motor ports will be green
All of the ports going to the logic pins on the arduino board will be blue.

I put a black or red line above and below each column on the left and right of the board as a visual reference that the entire column is charged or grounded.

Instructables provides a great description of how breadboards work in the link below.
https://www.instructables.com/id/How-a-Breadboard-Works/

Step 7: Wiring the Breadboard and Arduino

When wiring the breadboard to the arduino keep the following in mind:

On the H Bridge pins 1 and 9 (1,2EN, 3,4EN respectively) need to be connected to a pin on the arduino that has a "~" so that it can receive speed signals.

Cut the wire longer than you need it. You can always shorten a wire, making one longer is difficult.


Notes:

The Positive and Ground leads seen attached to the far right of the breadboard belong to the 9V snap connector.

I ran out of black wire and though green is commonly used as a color for ground/negative lines I used a sharpie to color them black for visual purposes.

You do not need to bend the wire or even cut them as exactly as I did, again this was for visual purposes only and is a bit more difficult than necessary.

Step 8: Adding a Photoresistor

The leads on the photoresistor and resistor can be left at the length they are at or cut shorter.

Step 9: Prepare the Box

Place everything in the box before you begin cutting to be sure everything fits comfortably.

Cut slots for the wheels.

Step 10: Connect the Motor Leads to the Breadboard

Attach the wires in the board slots that are green.

Use Electrical Tape to adhere the gearbox to the cardboard box.

Step 11: Finishing Touches

Tape the 9V to the side of the box to keep it from moving around and away from the gearbox.

You have completed the construction of Box Bot!

Step 12: Box Bot in Action

Here is some example code for the boxbot project you can use to get started and a video demonstration of what it does.


Note: During the course of making the bot run around I found out a few things.
1. It is actually more secure to tie down the gear box by using some of the hook up wire.
2. Make sure the wheels are centered in the video my bot drags a little to the right and I believe this is because of having an off centered wheel.

You can copy & Paste the code below(I attempted to attach the file several ways and it would not show up.):

/*
*Simple arduino code
*to show off capabilities
*of the robot
*Comments to the side of any code is
*"If you have never used arduino before,..."
*/

//Define datamembers

//define a pin for the photoresitor and its threshold
int lightPin = 0;
int threshold = 750;//In the room I was working in 1000 was really dark
                     //and 525 was really bright you might have to play
                    //around with this value depending on your setting.
                   
//Define and initialize motor variables
//Motor speed range is from 0 to 255 (Slowest to fastest)

//Left Motor
int speedPin1 = 9;
int motor1APin = 4;
int motor2APin = 3;
int speed_value_motor1 = 64; //quarter speed

//Right Motor
int speedPin2 = 10;
int motor4APin = 12;
int motor3APin = 11;
int speed_value_motor2 = 64; //quarter speed


//initial setup before the loop begins
void setup(){
    Serial.begin(9600);  //Begin serial communcation
                         //This will only affect the arduino
                         //when it is connected to the PC
    //Set the digital pins as outputs for the left and right motor
    pinMode(speedPin1, OUTPUT);
    pinMode(motor1APin, OUTPUT);
    pinMode(motor2APin, OUTPUT);
   
    pinMode(speedPin2, OUTPUT);
    pinMode(motor4APin, OUTPUT);
    pinMode(motor3APin, OUTPUT);   
}

//This is what actually runs
void loop(){
    Serial.println(analogRead(lightPin));

    if(analogRead(lightPin) > threshold )//Reads in the serial value if it is dark do the code within the brackets below
    {   
        Serial.println("dark"); //Will only show when connected to PC used for testing purposes
        fullStop();
    }
    else //Otherwise (if it is not dark) do the code within the brackets below
    {
        Serial.println("bright"); //Will only show when connected to PC used for testing purposes
        moveForward();
    }

    delay(1000);
}

//this method calls the appropriate methods to
//cause both motors to rotate in such a way
//that moves the bot forward
void moveForward(){
  leftMotorForward();
  rightMotorForward();
}

//This method makes only the right
//motor to rotate in a forward direction
void leftMotorForward(){
  //puts the motor in the forward motion
  digitalWrite(motor1APin, LOW);
  digitalWrite(motor2APin, HIGH);
 
  analogWrite(speedPin1, speed_value_motor1);
}

//This method makes only the left
//motor to rotate in a forward direction
void rightMotorForward(){
  digitalWrite(motor4APin, LOW);
  digitalWrite(motor3APin, HIGH);
 
  analogWrite(speedPin2, speed_value_motor2); 
}

/This method causes both motors to come to a full stop
void fullStop(){
  stopLeftMotor();
  stopRightMotor();
}

//Sets the speed to 0 causing the left motor to stop spinning
void stopLeftMotor(){
  analogWrite(speedPin1, 0);
}

//Sets the speed to 0 causing the right motor to stop spinning
void stopRightMotor(){
  analogWrite(speedPin2, 0);
}