We use cookies to provide you with a better experience. If you continue to use this site, we'll assume you're happy with this. Alternatively, click here to find out how to manage these cookies

hide cookie message
2,674 Tutorials

How to build and program a robot

Getting started with robotics

Step 7. The motors and distance sensor are mounted on the outside of the chassis, so you’ll have to make some holes for the wiring to make a neat job. Using a drill (or scissors), make holes close to where the lead exits each of the motors and another where the lead exits the distance sensor. Pass the leads through the holes.

Robot 7

Step 8. Plug the lead from the lefthand motor into channel 0 of the Mini-IO Shield, the lead from the righthand motor into channel 1, and the lead from the distance sensor into channel 2. In each case, ensure the white wire is the closest to the outer edge of the Arduino Uno board. Use cable ties to tidy up the wiring.

Robot 8

Step 9. Download the IDE for the Arduino board. Extract the files from the Zip archive, preserving the folder structure, then follow the instructions to install the driver. In Windows 7 you’ll find this under ‘Other Devices’; it’ll move to Ports when the driver has been installed. Make a note of its COM number.

Robot 9

Step 10. Start up the IDE by double-clicking the Arduino application. Download the sample code from tinyurl.com/67jwsLe, then open it in the IDE by selecting Open from the File menu. Select Board from the Tools menu and choose ‘Arduino Uno’. Now compile the program using ‘Verify/Compile’ from the Sketch menu.

Robot 10

Step 11. If it’s not still connected from Step 9, connect the junkBot’s Arduino Uno board to your PC using the USB cable. Select ‘Serial Port’ from the Tools menu and choose the COM port that you noted in Step 9. Select ‘Upload to Board’ from the File menu. When the ‘Done uploading’ message appears, disconnect the USB lead.

Robot 11

Step 12. Plug the lead from the battery pack into the Uno board and place the junkBot on the floor facing a wall. It should move forward until it reaches the wall, then turn around and proceed until it finds another wall. If it moves backwards, the two motors have been connected the two wrong way around.

Robot 12

Step 13. Now try modifying the sample code. Edit it using a text editor, such as EditPad Lite. Enter the code in the screenshot in place of the code starting with ‘while(!front_bump())’. The ends of some lines have scrolled off the screen, but anything after a // is a comment and won’t affect operation.

Robot 13

Step 14. Repeat Steps 10, 11 and 12 with this new code. The junkBot should behave as before, but when it reaches a wall it will now stop, back up and turn around. You can now start your own voyage of discovery by altering the software further or writing your own code from scratch.

Robot 14

IDG UK Sites

Amazon 3D smartphone release date, price and spec: The hologram phone?

IDG UK Sites

iPhone 5s review: why the iPhone 5s is still the best phone you can buy in 2014

IDG UK Sites

Passwords don't work: here's four ways to fix them

IDG UK Sites

The art of rebranding: Creative agency The Neighbourhood explains how & why it rebranded