Step 7: Bonus Robot Circuit!
It would be nice if your robot could respond to external stimulus. Fortunately, since we used the battery holder block from the Snap Circuits motion detector set, we can use the PIR sensor (the block labeled "Motion Detector U7") and transistor from the same set to build a motion detecting robot.
Parts needed for this build:
1 10 X 7 Plastic Base Grid
1 Snap Circuits Rover
1 9 volt Battery Block B5
1 Motor Control IC U8
1 8 Pin Socket U21 With PICAXE 08m Installed
4 1KOhm Resistors R2
1 Slide Switch S1
1 USB Programming Cable
1 Motion Detector Block U7
1 NPN Transistor Q2
1 Green LED D2
9 Single Snaps
11 Two Snap Conductors
2 Three Snap Conductors
1 Four Snap Conductor
3 Five Snap Conductors
1 Six Snap Conductor
1 Seven Snap Conductor
1 Orange Jumper Wire
1 Yellow Jumper Wire
1 Green Jumper Wire
1 Purple Jumper Wire
1 Gray Jumper Wire
1 White Jumper Wire
Optional Parts (so you can save the program in the PICAXE memory):
2 Single Snaps
1 100 Ohm Resistor R1
Build the robot according to the steps shown in the photographs
In the first circuit, we used all four of the output pins on the PICAXE to drive the Snap Rover motors. There are only two pins left--both of which are input pins--the serial in (S-In) and pin 3. I decided to use pin 3 as the input pin for the Motion Detector block. See picture 1 for the circuitry built inside the Motion Detector block. Though the circuitry looks complicated, there are only three snaps on the Motion Detector block: Positive (+), OUT, and Ground (-). I adapted the following circuit for the motion detecting robot so that I could light up an led when the motion detector detected motion to make the robot easier to program (the LED lights up whenever the motion detector detects motion then all I had to do was look at the voltage on pin 3 to differentiate between when no motion was detected and when motion was detected) :
While writing the program for the motion detecting robot I noticed that pin 3 had current on it while the LED was off (no motion detected), but was pulled down to 0 volts when the motion detector detected motion and the LED lit up. This serendipitously made programming much easier. All I had to do was tell the program to wait, or do nothing, until pin 3 to dropped to 0 Volts and then proceed to the motor tests.
Take a look at the modified flowchart in picture 2. You'll notice the same set of motor tests "Forward", "Backward", "Left Turn", and "Right Turn". The "Pause 5000" block has been replaced with the following:
let b0=1 I added this to make sure that the variable b0 is greater than zero so the program did not accidentaly go through the motor tests before the motion detector detected any motion.
let b0=pins assigns the value of pins (in this case the input port, pin 3) to the variable b0. When no motion detected, "pins" has a value greater than zero (actually the value on my PICAXE pin 3 in this circuit equals 8, go figure). When motion is detected, pins has a value of zero.
The decision diamond says the following:
If b0=0 (motion detected) then proceed through the motor tests and when the motor tests are completed go back to the beginning of the program.
If b0 has any value other than zero, simply go back to the beginning of the program.
So, the robot will just sit there until the motion detector detects motion.
Picture 1 source: www.snapcircuits.net/downloads/ic_info.pdf