3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

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

Step 11Program the Roverbot

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. 
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
15
Followers
12
Author:KRA5H(Fun With Snap Circuits)
IT professional.