necessary so that the state of the other zones is ignored in
this decision.

Let’s see how we might use the siren shown in
Figure 4. The previous code tries to scare away intruders
with the light and radio, but, if that fails, the system can
turn on the siren (and perhaps the light) if a window is
opened. This can be accomplished with the following
code:

Notice we did not check the doors (Zone 1) in the
above subroutine because we will want to give residents a
short time to enter the home and disable the alarm. In
order to keep things simple, we will let the user disable
the alarm by pressing any mouse button for at least one
second. The following code shows a simple way of
implementing this feature in RobotBASIC. Notice that
since the sensors in this zone are N.O., this zone provides
a LOW in its bit position when it is violated.

CheckDoors:
if (SensorData bAND 1) = 0 // check Zone 1
// for a low input
// wait 15 seconds or until the mouse
// is pressed
for i = 1 to 15
Delay 1000 // wait one second
ReadMouse x,y,b // b will hold the
// button data
if b<>0 then break // exit the FOR-LOOP
// early
// notice the use of a single line
// IF-THEN here
next
// if b is still zero, then no one pressed
// the mouse
if b=0 then OutPort 2001,5 // turn on
// siren and
// light
endif
return

Using the mouse to turn off the alarm could be an
acceptable option, but most people would probably prefer
to enter a code to turn the alarm on and off, as is done in
commercial security systems. This is actually very easy to
implement using RobotBASIC’s event-driven capabilities
which allow the creation of a subroutine that is executed
whenever a keystroke (or other event) is detected.

If you would prefer to have a remote keypad like
those on commercial alarm systems, that too is easy since
RobotBASIC supports serial ports — both real and virtual.
Just program a small microcontroller (such as a Parallax
BASIC Stamp) to read information from a keypad, and
transfer that information to the PC using a serial
connection.

Of course, after you implement all of the necessary
subroutines, they must be placed in a loop that calls them
properly, as shown in the next example. The code in the
loop is simple and easy to follow because keystroke
entries can be handled in the background (simply change
the value of variables such as AlarmOn). The
ResetOutputs routine in this code will automatically turn
off all devices (lamp, radio, and siren) after a preset
amount of time so that your neighbors will not be
disturbed if you are unable to return to your home in a
timely manner.

These are all simplified examples, but hopefully you
get the idea of how easy it is to create a usable system
with a relatively small program. It is important to realize
though, that as you add features and functionality, that
your projects can become as complex as you desire.

Since RobotBASIC has commands for sending emails,
you can add this feature by simply inserting the
appropriate email code inside the proper IF block.
Implementing a web cam is easy, too. After RobotBASIC
captures two consecutive images, image-processing
commands can be used to compare the two pictures to
detect motion. This makes it easy for your system to
detect when an intruder is within view of the web cam
and then send the picture as an email attachment.

If you really want to get creative, you could make your
system interactive. With RobotBASIC’s ability to
communicate over the Internet, you could use your laptop
to take control of your home from anywhere in the world.
This gives you many options. If you mount your web cam
on a servomotor-controlled turret, for example, you could
use a remote mouse to point the local web cam to obtain
a panoramic view of your home (or alternatively, use
RobotBASIC’s internal robot protocol and a Bluetooth
connection to control a mobile robot equipped with a
wireless web cam to see anywhere you like).

RobotBASIC offers many features for
implementing complex PC and multi-processor
based projects. These include support for all
standard I/O operations including USB and
Bluetooth connectivity, as well as Internet
communication, web cam support, and much
more. Download your free copy (including
extensive documentation) at www.
RobotBASIC.com.