Home Chapter 9 BS2 Programming the project

Site Search

GTranslate

Chinese (Simplified) French German Italian Portuguese Russian Spanish
BS2 Programming the project

Building the Circuit

Parts necessary

1 PIR sensor 5 volts
1 10 K ohm resistor
hookup wires
1 Solid-state relay with extension cord soldered in line with the SSR. Parts supplier Jameco’s part number is 176698CG and the manufacturers part number is (KYOTO) KB20C06A-R
NOTE soldering lessons in chapter 13.4
1 AC socket with plug attached
1 AC 15–100 watt bulb
Electrical tape or shrink rap tubing to protect leads and your hands from the AC voltage

In this activity you will be using the PIR to activate the lamp.

  1. Wire the SSR on the board and leave the PIR sensor where it is.

  2. Remember the PIR can see the lamp, so place the bulb away from sensing area of the PIR so the bulb will not accidentally activate the lamp.

PIR and solid state relay circuit

 

Schematic for project

 

Programming the project

In the next program you will be using the PIR to activate the lamp. This is important, as it is the basis for sensing something from a distance and having something activated at a distance.

 Enter the program below:

' {$STAMP BS2}
' {$PBASIC 2.5}

OUTPUT 4 ‘Make pin 4 an output so you can switch the solid state relay on and off.

INPUT 0 ‘ Make pin 0 an input so you can see the PIR with the BS2

Sense:

IF (IN0 = 1) THEN relay 'look to see if PIR has detected something and
‘made P0 high, if so then go to subroutine called relay

GOTO sense 'if P0 is not high return to start of program and continue forever…

Relay: 'this subroutine turns relay on.

HIGH 4 'turn the relay on

PAUSE 1000 'keep the relay on for 1 seconds

LOW 4 'turn the relay off

PAUSE 100 ‘keep light off for .1 second

GOTO sense 'return to start of program