Introduction: Dance Dance Roverbot! Build a Light Activated Dancing Snap Circuits Programmable Robot.

About: You can try my projects AT YOUR OWN RISK. There's infinite ways to damage or destroy persons and property. I can't think of them all. Kids use adult supervision. I've lost count of the number of items that I h…
In this Instructable you will learn how to build a light activated dancing Snap Circuits programmable robot. First, you will learn how to install the PICAXE Programming Editor (the PICAXE is the microcontroller, or computer brain for your Dance Dance Roverbot). Next, you will learn what a simple PICAXE program looks like and what it does. Then you will learn about the various parts and electronic components used to build Dance Dance Roverbot. You will then assemble Dance Dance Roverbot. Finally you will learn how to program and test Dance Dance Roverbot.

Snap Circuits is an educational toy that teaches electronics with solderless snap-together electronic components. Each component has the schematic symbol and a label printed on its plastic case that is color coded for easy identification. They snap together with ordinary clothing snaps. The components also snap onto a 10 X 7 plastic base grid analogous to a solderless breadboard. There are several Snap Circuits kits that range from a few simple circuits to the largest kit that includes 750 electronic projects.

All the kits include manuals printed in color with easy to follow diagrams to assemble the projects. The illustrations for each project look almost exactly like what the components will look on the base grid when finished. Because the electronic symbol is printed on each electronic component, once the project is completed, it will look almost exactly like a printed electronic schematic.

To build Dance Dance Roverbot, I used parts from three different sets, the Snap Circuits Motion Detector, Snap Circuits Rover, and Snap Circuits Micro. Elenco does not currently have a Snap Circuits programmable robot product. I find this surprising since Elenco has developed the Snap Circuits Rover, which is a remote controlled rover and the Snap Circuits Micro that teaches you how program the PICAXE microcontroller and how to build circuits for the PICAXE, but Elenco has yet to develop a product that combines the PICAXE with the Snap Circuits Rover.

I designed Dance Dance Roverbot to be easy to build completely out of Snap Circuits parts and easy to program to inspire folks from 8 to 80 to get interested in robotics. I've entered Dance Dance Roverbot in the Toy Challenge Contest so, If you like this Instructable, please vote for it: https://www.instructables.com/contest/toy2/?show=ENTRIES

The following are the Snap Circuits parts you will need to build Dance Dance Roverbot (parts can be ordered separately from Elenco http://www.elenco.com/product/productlist/snap_circuits®; or C & S sales http://cs-sales.net/sncirepa.html):

Software CD from the Snap Circuits XP or Snap-Micro I kit (if you do not have either of these kits you can download the PICAXE Programming Editor from http://www.picaxe.com/Software/PICAXE/PICAXE-Programming-Editor/)

1 10 X 10 Plastic Base Grid
1 Rover
1  9 volt Battery Block B5
1  Motor Control IC U8
1 8 Pin Socket U14 With PICAXE 08m Installed
1 100K Ohm Rsistor R5
2 1K Ohm Resistors R2
1 Photo Resistor RP
1 Slide Switch S1
1  USB Programming Cable
2 Single Snaps
15 Two Snap Conductors
1 Three Snap Conductor
1 Four Snap Conductor
1 Six Snap Conductor
1 Seven Snap Conductor
1 Orange Jumper Wire
1  White Jumper Wire
1 Green Jumper Wire
1 Yellow Jumper Wire
1 Purple Jumper Wire
1 Gray Jumper Wire

Step 1: Installing the PICAXE Programming Editor

The PICAXE Programming Editor is the software you will use to program the PICAXE micro-controller installed on the Snap Circuits 8 Pin Socket U14 block (the PICAXE chip carrier). The software contains the flowcharting software, the editor that you can use to write BASIC programs and the compiler for the micro-controller.

BASIC is an acronym that stands for Beginners All-purpose Symbolic Instruction Code. It was created way back in the 1960s as an easy to understand programming language to introduce students to computer programming.
 
What's a compiler? Have you seen those geeky T-shirts that say "there are only 10 types of people in the world: those who understand binary, and those who don't?" If you find yourself scratching your head instead of laughing hysterically, then you don't understand binary. Computers, on the other hand, understand only binary. 1s and 0s. On and off.

I have heard of some people who can do binary code, or machine language in their heads, but the rest of us normal people would have a difficult time writing a computer program out of nothing but 1s and 0s. Instead we use a higher level language like BASIC to write software.

Have you ever been to a foreign country and didn't know the language? You can hire a translator to translate what you say into the language that the locals can understand. That's what a compiler does. Computers can't understand BASIC so a compiler translates the software you write in BASIC into machine code, or the 1s and 0s that computers can understand.

Part needed for this step:

Software CD from the Snap Circuits XP or Snap-Micro I kit (if you do not have either of these kits you can order the CD from Elenco or download the PICAXE Programming Editor from http://www.picaxe.com/Software/PICAXE/PICAXE-Programming-Editor/)

Install the PICAXE Programming Editor from the Snap Circuits XP or Snap-Micro I software CD (Windows XP/Vista/7). The setup program will auto run when you put the CD in the drive. Click the large button that says “Install the PICAXE Programming Editor software."

Step 2: Installing the PICAXE Programming Editor (continued)

Insert the Snap Circuits USB Programming Cable into an empty USB port on your computer. Click on the PICAXE Programming Editor icon on your desktop to open the editor.

Step 3: Installing the PICAXE Programming Editor (continued)

The Options dialog will automatically open (if the “Show options on startup” check box is checked). If it does not, go to View > Options. On the Mode tab, select 08M--this is your PICAXE microcontroller.

Step 4: Installing the PICAXE Programming Editor (continued)

Click on the Serial Port tab and select the COM port where your USB Programming Cable is connected. Click the Ok button to go to the programming editor. In the Programming editor click File and then click New Flowchart to start entering your flowchart.

Step 5: A Sample Program for the PICAXE

This is what a PICAXE Programming Editor flowchart looks like. The flowchart in this example is very simple--can you guess what it does? It will turn a motor that is connected to pin 4 on the PICAXE for 10 seconds. We can take a look at how each step is processed.

The "start" terminator is ignored by the compiler, but is useful to you to easily locate the start of your program.

The "pause" process tells the PICAXE to wait 1000 miliseconds, or 1 second before proceeding to the next step in the program. When you tell the PICAXE to execute the program, you will notice a 1 second pause before anything happens.

The parallelogram flowchart symbol represents data, or input/output. It contains the command "high 4" and this command will set pin 4 high, which means the microcontroller will send voltage to that pin, or output current to that pin. If you have a motor connected to pin 4 then current from this pin will pass through the motor and the motor will begin to spin.

This "pause" process tells the PICAXE to wait 10000 miliseconds, or ten seconds. This means pin 4 will remain high for 10 seconds thus continuing to send current to the motor for ten seconds (the motor will spin for ten seconds).

This data flowchart symbol contains the command "low 4." It tells the PICAXE to turn the pin off, or to output 0 volts. This will cut power to the pin and the motor connected to it will stop spinning.

If you want to see what the BASIC code looks like, you can click Flowchart and then click Convert Flowchart to BASIC. The code will look like the the following:

‘BASIC converted from flowchart:
‘C:\DOCUMENTS AND SETTINGS\DESKTOP\SNAPROVERBOT.CAD
‘Converted on 10/30/2011 at 20:53:11
main:
pause 1000     'Tells the PICAXE to wait 1000 miliseconds (1 second)
high 4                'Sets pin 4 high, which sends current to pin 4 (if there is a motor connected it will spin)
pause 10000   'Tells the PICAXE to wait 10000 miliseconds (10 seconds--motor will spin for 10 seconds)
low 4                  'Sets pin 4 low, or ouputs 0 volts. This cuts the power to the pin and the motor stops spinning

Step 6: The PICAXE Microcontroller

What’s this PICAXE thingy? The PICAXE is a micro-controller, or a computer on a microchip. It is the computer brain of your Roverbot. It’s not as powerful as the computer in your video game console, or your laptop computer, but it does have circuits for processing, memory, logic, input and output. You can find micro-controllers in many toys, your DVD player, your TV, your microwave oven, and nowadays even in your washing machine and dryer. In your microwave, for example, the micro-controller processes what you punch in on the keypad, outputs information on the display screen, controls the cooking time, the turntable, and the bell when your dinner has finished cooking.

The Snap Circuits block (U14) that serves as the PICAXE carrier is specially labeled to more easily identify the pins on the PICAXE microcontroller chip. Think of the chip as a square bug with eight legs. There is a notch in the top to help you orient the chip and a little dot marks leg 1. Legs and pins can sometimes get confusing, but on the U14 block the legs (and the corresponding snaps the legs are connected to) are labeled in red 1-8 going in the counterclockwise direction. The functions of each leg are labeled in blue.

Leg 1 (snap 1): This is the postive (+) voltage input. It can take from 3 volts to 5 volts. You will want to avoid putting more than 5 volts through the PICAXE since this might damage it.

Leg 2 (snap 2): S-In. Serial In pin--it is used to download your program to the PICAXE.

Leg 3 (snap 3): This pin 4! Luckily the snaps are labeled or the pin numbers could get confusing. Pin 4 can be used as an Input pin or an output pin. In the previous step this is the pin the program set to high to send current to the motor for ten seconds. then the program set the pin low to cut the power to stop the motor from spinning.

Leg 4 (snap 4): This is pin 3. It is an Input only pin

Leg 5 (snap 5): This is pin 2. It can be used as an Input pin or an output pin

Leg 6 (snap 6): This is pin 1. It can be used as an Input pin or an output pin

Leg 7 (snap 7): This is pin 0. It is an Ouptut only pin. It is also the Serial Out pin. This pin will also be used when downloading your program to the PICAXE.

Leg 8 (snap 8): This is GND or Negative (-) for the PICAXE

Step 7: Snap Circuits Rover

Now that you have installed the PICAXE Programming Editor and learned how to write a simple program, its time to starte building your robot. There are three basic parts that you need to build a robot: a power source, a brain (the PICAXE of course) and a means of locomotion.

The Snap Circuits Rover is one example of locomotion. It has advantages and disadvantages.

Advantages:

It is a ready-made vehicle. In other words, you don't have to build a vehilce--it is already built for you.

It has two motors, one on the right side and one on the left side. Each motor is connected to the front and rear wheels by a series of geers (the geering was added in to slow the Rover down rather than a need for extra torque) so that the right motor turns the right front and rear wheels, and the left motor turns the the left front and rear wheels. In the first picture You can see the front of the rover as well as the gears that connect the left side wheels to the left side motor.

It is designed to have the Snap Circuits base plate connected directly to it. It is also designed so that power and motor control are easily connected with Snap Circuits jumper wires. In the second picture you can see the base plate attached. You can also see the snaps on the rear of the rover. The third picture explains the function of each snap. 

It has a battery compartment for six AA batteries to power the motors with 9 volts.

Disanvantages:

It is not designed to have attachments such a robotic grabber arm attached to it.

You must be careful to design your circuit so that you do not accidently pass the 9 volts from the rover's battery pack through the PICAXE microcontroller since this will most likely damage the PICAXE.

Step 8: The Voltage Regulator

The simplest way to power the rover and power the PICAXE is to use two different power supplies that share a common ground. To power the PICAXE, you can use the Snap Circuits B5 block. The advantage to using this block is you can connect a standard 9 volt battery to the block and it will deliver a reliable 5 volts to the PICAXE through L7805 voltage regulator circuit (see circuit schematic). The B5 also has two 5 volt outputs--one to power the PICAXE and one that you can use to power another device.

Now you have a convenient way of powering your PICAXE with a reliable 5 volts from the B5 block. As a safety feature for the PICAXE, it would also be a good idea to keep the 9 volts from the rover separate from the PICAXE in case while you are building and testing the circuit something gets connected the wrong way. Thus for this build you will use an H-bridge. It has special circuitry inside it that will prevent the 9 volts from the rover's battery pack from accidently passing through the PICAXE.

Step 9: The H-bridge

The first picture is a simplified H-bridge. The motor in the center is connected to 9 volts of power and ground by four switches (S1, S2, S3, and S4). With all four switches off, the motor will not get any power and the motor will not turn. The switches can be turned on in pairs: S1 and S4 or S3 and S2 to allow current to pass from the 9 volt batteries through the motor to negative or ground.

Now take a look at the second picture.

If you close switches S1 and S4, current will flow through the motor and it will turn in one direction.

If you close switches S3 and S2, current will flow through the motor and it will turn in the opposite direction.

The H-bridge is a very simple circuit. Unfortunately it would be impractical to use manual switches to drive a motor. Several companies make H-bridge integrated circuits (ICs) that are easy to use by simply applying power to a particular pin also called "setting the pin high" to drive the motor in one direction. Cutting the power to that pin and applying power to another pin will drive the motor in the opposite direction. The circuitry inside the H-bridge ICs is somewhat complicated, so most folks will choose to use an H-bridge IC rather than building the circuit themselves.

The third picture is the Snap Circuits Motor Control IC, or H-bridge. At the top of the figure you can see the electronic schematic of the Motor Control block. On the lower left you can see a picture of the block. The lower center shows the function of each snap for the block and on the lower right is a description of what each snap does.

Step 10: Build a Circuit for the Light Activated Roverbot

In this step you'll build the circuit for the rover bot. You'll recognize the power regulator block (B5), the PICAXE (U14), the H-bridge block (U8, labeled "Motor Control"), and the snaps for the rear of the rover. You'll also notice some new components. In addition to the snap conductors and the jumer wires, you will notice 2 1K ohm resistors, a 100 ohm resistor, and a photo resistor. The photo resistor is the sensory input (like a primitive eye that is sensitive to light) for the PICAXE brain. 

The Snap Circuits parts needed for this step:

1 10 X 10 Plastic Base Grid
1 Rover
1  9 volt Battery Block B5
1  Motor Control IC U8
1 8 Pin Socket U14 With PICAXE 08m Installed
1 100K Ohm Rsistor R5
2 1K Ohm Resistors R2
1 Photo Resistor RP
1 Slide Switch S1
1  USB Programming Cable
2 Single Snaps
15 Two Snap Conductors
1 Three Snap Conductor
1 Four Snap Conductor
1 Six Snap Conductor
1 Seven Snap Conductor
1 Orange Jumper Wire
1  White Jumper Wire
1 Green Jumper Wire
1 Yellow Jumper Wire
1 Purple Jumper Wire
1 Gray Jumper Wire

Click each picture to see a step by step process of the build (assuming you have already attached the 10 X 10 Plastic Base Grid to the rover--see Step 8 if necessary for a picture of the base grid attached to the rover). The build also shows the USB Programming Cable connected.

Step 11: Program the Roverbot

Create this flowchart in the PICAXE Programming editor.

The simplest way to describe what this program does is it waits for the light level in the room to reach a certain intensity and once that light level is reached, the program alternates switching the rover's right and left motors on and off. This will result in the rover turning right, then left, then right, then left, ad infinitum. Here is what the BASIC code looks like:

'BASIC converted from flowchart:
'C:\Documents and Settings\Desktop\lightmeter1.cad
'Converted on 1/25/2012 at 06:10:25

main:
label_6:                                      'While b0 is less than 201
  readadc  4,b0                          'Get value of b0 from pin 4 (amount of light falling on RP sensor)
  serout 0,N2400,(#b0,13,10) 'output value of b0 (amount of light falling on RP sensor) to programming editor's serial terminal
  wait 1                                         'wait one second before proceeding
  if b0> 200 then label_51       'if value of b0 > 200 (if brightness of light on RP sensor reaches chosen level, roverbot starts dancing
  goto label_6                            'light isn't bright enough so, take another reading
label_51:
label_27:
  high 0                                        'switch left roverbot motor on
  low 1                                          'switch right roverbot motor off
  pause 1000                              'right motor turns for one second 
  low 0                                          'switch left motor off
  high 1                                        'switch right motor on
  pause 1000                             'right motor turns for one second
  goto label_27                          'repeat until Dance Dance Roverbot is switched off

The "readadc  4,b0" process reads the analog-to-digital converter value on pin 4 and assigns that value to b0 the possible values are from 0 to 255 depending on the amount of light falling on the photo resistor (RP) connected to pin 4 on the PICAXE.

The "serout 0,N2400,(#b0,13,10)" input/output is not necessary for the program to run. I inserted it so I could test the light levels in the room on the Programming Editor's Serial Terminal and adjust the program accordingly. When you convert the flowchart to BASIC and program the PICAXE you can display the Serial Terminal by pressing the F8 key. In the picture you can see that I tested the light levels in a room with a dimmer switch on the light.

The "wait" process tells the program to wait one second before proceeding to the next step. On the on the Programming Editor's Serial Terminal I saw the values displayed once every second.

The "if b0> 200 then label_51" decision diamond says that if the value assigned to b0 is greater than 200  then goto the next step in the program otherwise go back to the "readadc  4,b0" process. If you look at the Serial Terminal picture what do you think happened when I raised the light level using the dimmer switch and the value in b0 jumped from 122 to 235?

The "high 0" input/output tells the PICAXE to set pin 0 high. This will start the left side motor on the rover to start turning forward.

The "low 1" input/output tells the PICAXE to set pin 1 low. This will tell the right side motor on the rover to stop turning.

The "low 0" input/output tells the PICAXE to set pin 0 low. This will tell the left side motor on the rover to stop turning.

The "high 1" input/output tells the PICAXE to set pin 1 high. This will start the right side motor on the rover to start turning forward.
 
To run the program, make sure the Snap Circuits Slide Switch S1 is switched off else the program will execute while the program is still downloading to the PICAXE and may accidentally disconnect the programming cable if the light level falling on the RP sensor causes it to return a value greater than 200 causing the roverbot to dance. Next, make sure that the Snap Circuits 9 volt Battery Block B5 is switched on or the program will not download to the PICAXE. Connect the Snap Circuits USB Programming Cable to your computer.

1.  Connect the yellow snap to the S-In snap on the Snap Circuits 8 Pin Socket U14 block (the PICAXE chip carrier).

2.  Connect the red snap to the S-Out snap on the Snap Circuits 8 Pin Socket U14 block (the PICAXE chip carrier).

3.  Connect the black snap to the GND, or negative (-) snap on the 8 Pin Socket U14 block (the PICAXE chip carrier).

Before proceeding you will want to cover the RP sensor with your finger.

In the Programming Editor click PICAXE and then click Run. A status bar will display to show the progress of the download of the program to the PICAXE.

Once the program finished downloading, disconnect the programming cable from your computer and from Dance Dance Roverbot. Place the Roverbot on the floor a safe distance from any obstacles. Then switch the Slide Switch S1 to on. When you are ready to watch your Roverbot dance, slowly remove your finger from the RP sensor. When enough light falls on the sensor to set the value of b0 to 201 the Dance Dance Roverbot will start turning right, then left, then right, then left (a robotic version of The Twist), until you turn the Slide Switch off. 

Step 12: Congratualtions!

In this Instructable you learned how to build a light activated dancing Snap Circuits programmable robot. You learned how to install the PICAXE Programming Editor. You learned what a simple PICAXE program looks like and what it does. Then you learned about the various parts and electronic components used to build Dance Dance Roverbot. You then assembled Dance Dance Roverbot. Finally you learned how to program and test Dance Dance Roverbot.

Dance Dance Roverbot can also double as a guard robot. If placed in a dark room it will stay put and guard that room until someone turns the lights on at which time Dance Dance Roverbot will start to do The Twist. The motors will be loud enough to awaken someone sleeping in that room. I'm sure you can think of other uses for Dance Dance Roverbot. Happy Hacking!