Email Address:
Password:

Lost your password?

This is the legacy website; please use the new website.

More Fun With the PICAXE: A Shop Door Minder

Part 2 of the series shows you how to build a "Shop Door Minder...With Attitude".

By Stan Swan

Last month (Feb 2003) we introduced the innovative PICAXE08 IC and a simple application, a flashing LED, all built into a solderless "PICNIK box".

Click for larger image
If you don't happen to own a shop, you can always find something else to count - just remember to take into account four legs and a tail . . .

If you didn't see last month's issue, it will pay you to get a copy and read it because some of the concepts might be a little different to what you're used to, such as BASIC Stamps, etc.

By now, readers should have familiarised themselves with basic operations and the commands high, low, pause and goto.

PICAXE instructions are much the same as used in classic BASIC programming. There are a lot of BASIC texts around (no pun intended!), such as Greg Perry's "QBASIC by Example" (QUE 1993) or from the Parallax BASIC Stamp Programming Manuals. There's also a huge amount of information available on the 'net.

Given that you don't need to be a programming guru to use PICAXE instructions, initial applications here will be educational rather than exotic.

PICAXEs have only enough RAM for about 40 program lines, so there's some incentive to code efficiently! Our simple application here uses about half the memory available, so room remains for your own tweaking.

Shop Door Minder

Click for larger image
This reveals just how useful such PC feedback is-you can note all the variables ticking away nicely!

A shop door minder usually consists of a light source which creates a beam, a light sensor which detects that beam and a buzzer circuit which sounds when the beam is broken. Sometimes there is a delay circuit to make the buzzer sound long enough to be noticed; sometimes the buzzer "locks on" when it is actuated to behave more like an alarm.

This month's circuit acts as a "shop door minder with attitude", since it not only sounds a buzzer when the light beam is broken but also provides a simple "traffic" indication by flashing a LED at an increasingly faster rate with each event.

Now that could be handy - if you don't happen to own a shop and wish to count customers, this project could, at a glance, tell you the number of times your cat door is opened! Don't own a cat? You'll think of something to count!

The flash rate increases are not linear but counts per minute can be noted and related to visitor numbers via a simple lookup table. A further LED could even be added (pin 0?) to indicate a count of 10 had been reached, at which point the main counter could drop back to a slow rate again. By this means, up to perhaps 30 events can be quite reliably "read off ".

If a PC remains attached, the exact count (to 255 events) can be just read off using debug. Mmm - 255 cats visited last night? What IS in your pantry!

The circuit

Aside from the core parts mentioned last month, just a few extra resistors are used, one of which is a light dependent resistor, or LDR.

Your setup values may vary depending on your application but 100Ω in the voltage divider, plus similar as a LED dropping resistor, should do.

For initial trials a small bright light (perhaps a white LED) is also needed. More practical setups could see the light path extended with lenses, shrouds or even a mirror. Only small currents pass along the wires so leads to the LDR and light can be conveniently placed. Things really depend on the stray background light seen by the LDR, although this can be allowed for to some extent by altering readadc threshold values.

Click for larger image
If this looks somewhat similar to last month's project, it just might be! The basic differences are the LED and LDR which provide an "analog" input to the PICAXE. The PICAXE programming does the rest.

For a longer light path the lens from a pocket torch may help to concentrate the beam, while the LDR could even be recessed into the torch base to give shading from stray light. The program's readadc threshold value, initially 160, may need lowering to suit of course.

To prevent false triggering from shadows, reflections or visitor legs (or tails!), a small delay, perhaps "pause 500", may be needed in the readadc loop. Obviously this delay may cause the unit to become unresponsive if events occur too rapidly.

Having a light on to hold the alarm off may be wasteful of battery power of course. Perhaps you could modify the program so that darkness holds the sensor off and room light alone is enough to trigger things - much as would occur when a medicine cupboard door was opened.

The point of these PICAXE circuits is to stimulate your interest, to see what can be done very cheaply and to help you come up with your own variations. Of course, we will help you along the way with more applications to keep those creative juices flowing!

Incidentally, if you come up with a scathingly brilliant PICAXE application that you would like to share with the world (and perhaps feature on these pages), please feel free to email me - s.t.swan@massey.ac.nz

Where to get the PICAXE-08

Currently there is no Australian distributor. Order direct from the UK agents (Revolution Education) on line shop www.techsupplies.co.uk - they are very prompt.

Click for larger image
There are a few differences between the photo above and the Protoboard layout at right. Follow the layout and you shouldn't go wrong!
Click for larger image
PICAXE-08 Commands Used This Month

readadc

PICAXEs have a valuable Analog to Digital Conversion (ADC) feature, which in theory converts "real world" analog voltages into 256 steps of digital equivalents. There's an unavoidable deadspot on the upper range however and the resulting 160 divisions are treated in blocks of 10, so only 16 discrete values are available! Although obviously unsuitable for MP3 encoding or the like, this is quite enough for many simple applications.

In fact our circuit here uses ADC at just a yes/no level in response to an LDR's (light dependent resistor) resistance changes with illumination, so not even all these 16 divisions matter. Pin 1 ADC input needs a voltage rather than a resistance, so the old voltage divider trick is rustled up, involving two series resistors connected between +ve and ground with their midpoint delivering a variable voltage as the LDR value changes. The readadc command finally assigns this ADC value to a program variable at pin 1. Alter the readadc threshold value or resistor (here 160Ω and 100Ω) to fine tune with your LDR and light path.

Incidentally, LDRs typically have a resistance of 1 MΩ + in the dark and around 1 kΩ in bright light, with a quite rapid response as illumination alters.

sound

With the suggested piezo speaker, sounds can be directly produced from output pins using the sound command. Most piezos are optimised for high frequencies (typically 4kHz) so fidelity may be poor for other tones. It's worth experimenting with your setup, since a more distinctive "fruity" alert may be produced with two sounds together.

debug

If the serial programming cable remains connected during PICAXE runs, program data values can be usefully monitored on the PC screen. Up to 16 "byte" variables (b0 - b15) can have tabs kept on them.

pulseout

This provides timed duration output pulses (to microseconds) at specified pins, and effectively packages up HIGH, PAUSE and LOW in one efficient command .

for - next (step)

Creates a repeating loop that executes program lines between the FOR and NEXT statements as it increments. The optional STEP value defaults to 1 unless specified.

maths operations

Variables to a maximum value of 255 (at which point they roll over) can be added, subtracted, multiplied or divided, with left to right solving but with only integer solutions. Hex and binary are also handled but brackets are disallowed and fractional portions of results are discarded (although clever techniques can off set this).

Basic Program Listing
(This can also be downloaded from http://picaxe.orcon.net.nz/adcprog.bas)
' Demo program for March 2003 SilChip PICAXE-08 article Ver1.0 20th Jan 2003
' Best assembled & tested with solderless "PICNIK" box as detailed SilChip Feb03
' Refer http://picaxe.orcon.net.nz for background info & potential of PICAXE-08
' Extra parts = LDR, White LED, Red LED, 2 x 100 Ohm, 1 x 330 Ohm, piezo speaker
' LDR & illuminating light can be moved apart- maybe use lenses & light guides?
' New commands here = sound, readadc, debug, pulsout, for-next & simple maths.
' Ref.PICAXE prog.editor .pdf help files,& BASIC Stamp manuals etc for insights
' via Stan SWAN (MU@W, New Zealand) => s.t.swan@massey.ac.nz <=

' Byte variables b0= LDR "resistance value" b1= event counter
' b2= pulse delay in msec b3= sound loop
' Strictly only the LHS code below is needed. Remarks (') can be ignored

sound 4,(100,10,80,10) 'initial dual sounds to inform that powered up
   
ldrdemo: ' LDR resistance monitoring routine
readadc 1,b0 ' read LDR low resolution value via voltage divider
debug b0 ' show variable LDR value(s) to attached PC screen
if b0 <160 then beeper ' warbling alert tones when LDR shaded
b2 = 250/b1 ' produce delay value.NB max variable value is 255
if b2 =0 then ldrdemo ' prevents LED flash when not yet triggered
pulsout 2,1000 ' pulse LED pin 2 for 1000x10 microsec =10millisec
pause b2:pause b2:pause b2 ' more events give decreasing delay between pulses
goto ldrdemo ' continually loop unless LDR shaded
 
beeper: ' piezo speaker 2 tone sound routine
for b3= 1 to 3 ' loop to sound tones 3 times
sound 4,(100,20,80,20) ' repeating dual tones each 20 msec
next b3 ' sound loop increment
b1=b1+1 ' event counter increment
goto ldrdemo ' return to monitoring routine
Some more references...

1. "QBASIC by Example"
Greg M Perry (Que Books 1993)

2. Parallax Inc, the BASIC Stamp originators, have free resource downloads (.PDF files) via their web site (www.parallax.com)
BASIC Stamp Users Programming Manual Version 2. (351 pages, 3.2MB download)
BASIC Stamp 1 Application Notes Ver 1.9(126 pages, 1MB download).

3. "The Art of Electronics"
Horowitz and Hill (Cambridge University Press 1989).
Chapter 9 offers good ADC insights.

Share this Article: 

Privacy Policy  |  Advertise  |  Contact Us

Copyright © 1996-2021 Silicon Chip Publications Pty Ltd All Rights Reserved