9 Burglar Alarm

A burglar alarm is supposed to detect an intruder. To do that, though, the alarm must be as sophisticated as possible to detect and act upon a variety of situations. A computer, equipped with the proper sensors and actuators, can do just this and become an effective burglar alarm.
     Intruders may reveal their presence to a computer-controlled burglar alarm in a number of ways. First of all, the intruder must somehow enter the building-a door or window is the most logical means of entry. If the computer's sensors are set to detect use of these entrances, an alarm can be triggered when someone passes through them.
     Sensors could also be set to detect anyone in areas considered off-limits. For instance, if a sensor detects someone in the living room when all rightful occupants are sleeping upstairs, the burglar alarm can safely assume that an unauthorized person is in the protected area.
     Another possibility is to have the alarm sensors detect movement of particular objects. Most car alarms work on this principle. The sensors can be set to tell whether your stereo, television, or anything else has been moved. If an intruder tries to steal something, the burglar alarm can alert you, or even alert the police.

Using What You Know
The previous projects in this book laid the groundwork for a burglar alarm. In particular, the joystick project in Chapter 3 and digital light sensor project in Chapter 7 will be used as the sensors. The electronic switch project, found in Chapter 8, is the actuator required by the alarm. If you didn't put them together earlier, turn back now and try them. Be sure you have a basic understanding of these circuits before proceeding. You'll need to refer to these chapters as you construct this burglar alarm.
     As you saw in Chapters 2 and 3, a computer joystick is actually a set of switches. Many types of burglar alarm sensors are switches as well. These sensors can be connected to your computer in the same way as a joystick-through the I/O lines of the control port.
     One type of switch sensor is a thin, adhesive, metallic tape that can be stuck on windows and other glass. This tape normally acts as a closed switch, allowing current to flow through a circuit. If the glass is broken, the fragile tape breaks, too, and the circuit is interrupted. Another type of switch sensor is a magnetic switch. This sensor is generally used to detect doors and windows being opened or closed, but it could also be installed on desk drawers. A typical application is a magnet mounted on a door, with the magnetic switch mounted on the door frame. When the door closes, the magnetic switch either closes or opens, depending on the type of switch. When the door opens, the magnetic switch changes.
     Other types of sensor switches include vibration detectors, ultrasonic sensors, and even infrared sensors. Most of these "switch" alarm sensors can be purchased at electronic stores such as Radio Shack.
     Your alarm will use the digital light sensor project built earlier to detect entry into an off-limits area. The light source and sensor should be set up so that any light in the controlled area will trigger the sensor.
     The computer will use the electronic switch to turn on the alarm itself. The alarm can be a buzzer or a louder alarm (providing it doesn't exceed the ratings of the relay or solderless breadboard). With the proper programming, your computer could even use a modem to call the police, and then play a tape recording announcing your address and reporting a break-in.

Setting Up the Alarm
To set up your computer as a burglar alarm, plug the electronic switch into control port 1.

step-by-step
Before placing the digital light sensor's 9-pin plug into control port 2, solder wires for switch sensors to its pins 2, 3, 4, and 6.

Figure 9-1. Atari and Commodore 64/128 Alarm

If you have a VIC-20, you need a new connector since both the electronic switch, the digital light sensor, and the other switch sensors must be plugged into the single control port.

Figure 9-2. VIC-20 Alarm

To do this, you need to make a new connector:

step-by-step
1. Solder wires to pins 1, 2, 3, 4, and 6 of a 9-pin plug. Solder two wires each to pins 7 and 8.
2.  Remove the old connectors from the electronic switch and light sensor cicuits.
3. The wire from pin 1 of the new connector inserts into point A4 of the electronic switch circuit. It provides the digital signal required to turn the electronic switch on or off.
4. The wire from pin 2 connects to point 14 of the light sensor circuit to receive its digital output signal.
5. The wires from pins 7 and 8 provide the power to the two circuits. One set of two wires from pins 7 and 8 connects to points Y1 and X1 respectively of the light sensor circuit board. The other set of two wires from pins 7 and 8 connects to points X1 and Y1 respectively on the electronic switch circuit. The remaining wires from the control port are used for switch sensors.

Whichever type (or types) of switch sensors you choose for your burglar alarm, they must be normally closed. They're set up so that they ordinarily form a closed loop between the ground pin of the control port and one of the I/O pins. The Commodore 64, 128, and Atari computers can each have four switch sensors connected to them in addition to the light sensor. The VIC-20 can have three switch sensors in addition to the light sensor. For any of the machines, there's no need to wire one end of the switch sensors directly to pin 8 of the control port-any connection to ground, such as the x row of the light sensor circuit, will do.
     Since, in normal conditions, the switch sensors form a closed loop between ground and their particular I/O lines, these lines are at a logic low level. Similarly, the digital light sensor circuit outputs a logic high signal as long as no light is detected. The computer program of the burglar alarm can tell if things are as they should be just by checking to make sure that the bits in the data register corresponding to the sensors are off.
     If one of the sensor bits of the data register has changed, this means one of the sensors has been activated-its corresponding I/O line no longer forced to ground. The burglar alarm program must detect if this happens and send a signal to the electronic switch to turn on the alarm.
     You may want to experiment with infrared emitters and detectors, such as those used in the digital timer project of Chapter 7. In a darkened hallway, you might be able to use the digital timer as a switch for an intruder alert. Other infrared detectors and emitters could be purchased.

test
Program 9-1 is a simple demonstration program illustrating the use of your computer-controlled burglar alarm. Once you have the basic circuitry working, you can modify the program and circuit to add additional sensors as necessary. If you need more sensors than this simple alarm allows, refer to the multiplexer project of Chapter 12.

Program 9-1-Commodore 64/128


MH 120 PRINT"{CLR}ADJUST THE INFRARED BEAM AND THE"
FA 130 PRINT"POTENTIOMETER UNTIL THE MESSAGE JUST"
GQ 140 PRINT"CHANGES FROM OFF TO ON"
KX 150 PRINT:PRINT"PRESS X TO CONTINUE"
SF 160 A$=CHR$(145)
PM 165 A=PEEK(56320)
BJ 170 IF (A AND 2↑0) THEN PRINT "OFF"
XM 175 IF (A AND 2↑0)=0 THEN PRINT "ON"
KE 180 GET B$
FK 190 IF B$="X"THEN220
PH 200 PRINTA$A$
AD 210 GOTO165
EK 220 PRINT"TRIGGER A SENSOR TO START ALARM"
HQ 225 REM CHECK SENSOR STATUS
MX 230 B=PEEK(56320)
QH 240 IF B=A THEN 230
JQ 250 PRINT "WARNING-ALARM TRIGGERED"
AG 260 FOR I=0 TO 4
AA 270 IF (B AND 2↑1) THEN PRINT "SENSOR ";I+1;" DETECTS VIOLATION"
EH 280 NEXT I
MM 340 TI$="000000"
QM 370 REM TURN ON ALARM
SQ 375 REM SET DATA DIRECTION REGISTER FOR OUTPUT
XJ 380 POKE 56323,PEEK(56323)OR(2↑0)
AM 385 REM SET DATA LINE LOGIC LOW TO TURN ON ALARM
HF 390 POKE 56321,PEEK(56321)ANDNOT(2↑0)
QC 395 REM ALARM ON FOR 2.5 SECONDS
KE 400 IF TI>3600/24 THEN 420
GP 410 GOTO 400
BP 420 REM SET DATA LINE LOGIC HIGH TO TURN OFF ALARM
AK 430 POKE 56321,PEEK(56321)OR(2↑0)
JR 440 REM RESET DATA DIRECTION REGISTER FOR INPUT
PM 450 POKE56323,PEEK(56323)ANDNOT(2↑0)


Program 9-1-VIC-20

GE 10 PRINT"TURN ON FLASHLIGHT AND ADJUST THE"
GG 20 PRINT"POTENTIOMETER TILL THE MESSAGE JUST"
SR 30 PRINT"CHANGES FROM OFF TO ON"
KQ 40 PRINT:PRINT"PRESS X TO CONTINUE"
GM 50 A$=CHR$(145)
PB 60 A=PEEK(37137)
HS 70 IF (A AND 2↑3) THEN PRINT "OFF"
FH 80 IF (A AND 2↑3)=0 THEN PRINT "ON "
XA 90 GET B$
MH 100 IF B$="X"THEN130
QB 110 PRINTA$A$
SQ 120 GOTO60
DX 130 PRINT"TRIGGER A SENSOR TO START ALARM"
QG 140 Z$=" DETECTS VIOLATION"
MG 150 REM CHECK SENSOR STATUS
ES 160 B=PEEK(37137)
FS 170 POKE37154,0:IF(PEEK(37152)AND(2↑7))THEN PRINT"SENSOR 3";Z$:GOTO230
EF 180 IF B=A THEN160
RP 190 PRINT "WARNING-ALARM TRIGGERED"
GG 200 IF (B AND 2↑3) THEN PRINT "SENSOR 1”;Z$
MM 210 IF (B AND 2↑4) THEN PRINT "SENSOR 2";Z$
DX 220 IF (B AND 2↑5) THEN PRINT "SENSOR 4";Z$
HB 230 POKE 37154,255
XE 240 TI$="000000"
PC 250 REM TURN ON ALARM
GH 260 REM SET DATA DIRECTION REGISTER FOR OUTPUT
HB 270 POKE 37139,PEEK(37139)OR(2↑2)
PR 280 REM SET DATA LINE LOGIC LOW TO TURN ON ALARM
PM 290 POKE 37137,PEEK(37137)ANDNOT(2↑2)
RM 300 REM ALARM ON FOR 2.5 SECONDS
BC 310 IF TI>3600/24 THEN330
SG 320 GOTO310
HB 330 REM SET DATA LINE LOGIC HIGH TO TURN OFF ALARM
CB 340 POKE 37137,PEEK(37137)OR(2↑2)
AC 350 REM RESET DATA DIRECTION REGISTER FOR INPUT
EF 360 POKE37139,PEEK(37139)ANDNOT(2↑2)


Program 9-1-Atari

PL 110 REM ALARM PROGRAM
KP 120 PRINT "TURN ON FLASHLIGHT AND ADJUST THE"
LF 130 PRINT "POTENTIOMETER TILL THE MESSAGE JUST "
K0 140 PRINT "CHANGES FROM OFF TO ON”
FE 150 PRINT "PRESS X TO CONTINUE"
GH 155 FOR J=1 TO 2500:NEXT J
SP 160 IF STICK(1)=1 THEN PRINT "OFF”
DB 170 IF STICK(1)=0 THEN PRINT "ON “
MB 180 REM CHECK IF X KEY PRESSED
KD 190 IF PEEK(764)=22 THEN 210
GC 200 GOTO 160
ML 210 REM CLEAR OUT LAST KEYSTROKE
CM 220 POKE 764,255
DD 230 PRINT "TRIGGER A SENSOR TO ST ART ALARM"
NI 240 A=STICK(1):B=STRIG(1)
GM 250 IF (A=0 AND B=0) THEN 240
LG 260 PRINT "WARNING - ALARM TRIGGERED"
OC 270 IF A=1 THEN PRINT "SENSOR 1"
OF 280 IF A=2 THEN PRINT "SENSOR 2"
DJ 290 IF A=4 THEN PRINT "SENSOR 3"
PA 292 IF A=8 THEN PRINT "SENSOR 4"
ON 294 IF B=1 THEN PRINT "SENSOR 5"
CF 300 PRINT "DETECTS VIOLATION"
NK 305 REM INITIALIZE CLOCK
MO 310 POKE 18,0:POKE 19,0:POKE 20,0
NC 320 REM SET DATA LINES FOR OUTPUT
FP 330 POKE 54018,48
IO 340 POKE 54016,255
FM 350 POKE 54018,52
OG 360 REM SET DATA LINES LOW TO TURN ON ALARM
CF 370 POKE 54016,0
AM 380 IF ((PEEK(18)*255*255)+(PEEK( 19)*255)+(PEEK(20)))>3600/24 THEN 400
HA 390 GOTO 380
OF 400 REM TURN OFF ALARM BY SETTING DATA LINES LOGIC HIGH
IN 410 POKE 54016,255
AJ 420 REM RESET DATA LINES FOR INPUT
GA 430 POKE 54018,48
CD 440 POKE 54016,0
FN 450 POKE 54018,52

Download (Saved BASIC)
Download / View (Listed BASIC)

Before mounting sensors, you should first check your burglar alarm. The switch sensors can be simulated by connecting their I/O pin wires to the ground of either of the circuits. When you run the appropriate version of Program 9-1, you're instructed to carry out the necessary adjustment to the digital light sensor. Once you do this, your burglar alarm is operational.
     To trigger the alarm, shine a light on the light sensor or disconnect a switch sensor wire from ground. The program prints on the screen which sensor was triggered and turns on the alarm after a delay of several seconds (so that an authorized person could disable the alarm). The alarm stays on for a couple of seconds before shutting off. You'll probably want to increase the delay of timers when you install the system. (Of course, a power failure will disable the alarm. The program will have been removed from your computer's memory.)


Other Applications
Not all the applications for this project are as serious as a burglar alarm. You could mount a magnetic switch on the refigerator door to make sure someone isn't cheating on a diet. If you have a small store, you could use this project to sound a buzzer when a customer enters. With some thought, you can modify the program and circuit for almost any application.


Return to Table of Contents | Previous Chapter | Next Chapter