BoxBot setup & demo


If you have just completed your BoxBot and want to get it doing something, we have created this page for you. We will show you how to connectup the breadboard and get the bot roaming around randomly. This is designed to test the bot ready for more advance projects.

Items you will need for this project



BoxBot robot chassis

Arduino

Servos

Jump Wire Kit

You will also need 4 AAA Batteries, and one 9v PP3 rectangular battery.

Prerequisits


This example assumes you are familiar with the Arduino IDE, connection and uploading. If not we suggest you visist www.arduino.cc and read their getting started and learning guides.



The circuit


White wires are shown in grey for clarity.


Make up this circuit on your breadboard. The wire colours are just for clarity on the diagram and do not relate to the jump wire kit colours, however the wires on the servos are true. The circuit connects the Arduino to the servos.
Pay attention to the polarity, and the servo connections. Double check all your connections are correct before connecting power. Short circuits and reverse polarity can damage the Arduino, sensors and servos.

The demo code


(Arduino only)

// Bot builder BoxBot demo code. Random movements #include <Servo.h> // Included to make the servos turn Servo leftServo; // Telling the above library we have this servo Servo rightServo; // Telling the above library we have this servo void setup() { leftServo.attach(9); // Enables the use of this servo rightServo.attach(10); // Enables the use of this servo } void loop() { int choice = random(2); // Declare a random 1 or 2 number int duration = random(2000); // Declare a random number between 1 and 2000 goForward(); // Use the goForward code below delay(duration); // Use a delay that turns the servos for the random duration in milliseconds // After the above delay has finished let's turn the robot if (choice == 1) // If the random number is 1 then go right { goLeft(); // Use the goLeft code below } else // If the random number is not 1 it must be 2 so... { goRight(); // Use the goRight code below } delay(duration); // Use a delay that turns the servos for the random duration in milliseconds } void goForward() // This makes the bot go forward by turning a servo: { leftServo.write(110); // One way rightServo.write(50); // And the other way } void goRight() // This makes the bot turn by making the servos: { leftServo.write(50); // Turn the same way lower than 90 (center) rightServo.write(50); // Turn the same way lower than 90 (center) } void goLeft() // This makes the bot turn by making the servos: { leftServo.write(110); // Turn the same way higher than 90 (center) rightServo.write(110); // Turn the same way higher than 90 (center) }

Testing


Power up your bot. Servos 1st, Arduino 2nd. If everything is connected and coded properly, the bot will travel forwards, then make a turn to thew left or right. This behaviour repeats.

That's it :-)