PIR sensor with LCD counter: need a push in the right direction

oKors

New Member
I'm fairly new to Picaxe and have spent the last week scouring the internet and search function on the forum looking for code or a "sample" circuit for the device I'm trying to create. Haven't found anything inline with my needs.

Basically I want to build a small PIR motion detection unit with a counter. When someone walks by the counter will increment by 1.

Here's a few of the PIR's I'm looking into: Panasonic NaPion or this low-power sensor which seems to only source out of china.

I guess right now I'd appreciate a push in the right direction. Which chip or kit will drive the counter and also provide a reset. Also, I couldn't really find any example code on this. As a learning curve I'd like to practice on a real-world application if that makes sense.

Thanks, and sorry for the noobie questions.
 

lanternfish

Senior Member
Hi and welcome to the Forum

What is your previous electronics experience?

To help you on your way I have the following comments:

1. As you are making a counter a quick search of the forums using the Search option could provide you with a lot of info from others projects. Also have a look at the completed projects section.

2. As for the pir, either would probably do. The digital out (On or Off) will make for easy interfacing.

Anyway, have a browse around for similar projects on this site and let us know if you need more assistance.
 

Chavaquiah

Senior Member
I can vouch for those Panasonic. A bit on the expensive side but work great and do so from 5V, same as most Picaxes.

Any Picaxe can drive them as all it takes is a single input pin. Not all Picaxes have a reset pin but cutting power for a little while should achieve the same function.

Just for fun, I still have the code I used for my very test with a Napion:

Code:
#picaxe 08M
#no_end

symbol PIR = pin1
symbol LED = 4

main:
	b0 = PIR
	if b0 = 0 then
		high LED
	else
		low LED
	endif
	goto main
It doesn't get much easier than this, does it? ;) And yes, I used the "humble" Picaxe-08M.

Going low voltage and with the promise of greater functionality, you may also have a look at the ePir. I bought a few but haven't got round to use them yet, so don't know if they are really good.

Back to the Panasonics, driving a counter would be very simple. I'd just recommend a small pause after a presence is detected, just in case the sensor fires more than once per "presence." Also, remember to wait a little after a reset, so the sensor has time to settle down (when started, it will give a few false warnings for a few seconds).

Code would be similar to:

Code:
symbol PIR = pin1
symbol counter = w1

init:
	wait 30 'Give the PIR time to settle
	w1 = 0

main:
	b0 = PIR
	if b0 = 0 then
		inc counter
		wait 5
		debug 'Show counter
	endif
	goto main
EDIT:

Be sure to always download datasheets for the products you're using. For instance, for the Panasonic you may try this one. In most cases, the datasheet will show you example circuits. For the Panasonic, it is very simple: one pin to power, one pin to ground, a capacitor between those 2 and the third pin goes to the Picaxe.
 
Last edited:

Dippy

Moderator
Thats a nice answer Chava.

Okors, did you mean a reset for the PICAXE chip or just a 'reset' (zeroing) button for your counter ?
That is also very easy to achieve.
The Manual shows how to connect a button. - Manual 3 , page 25.
Then you can use a similar IF method to detect a button press and set your counter variable to Zero.

... next you'll be asking how to save the value in EEPROM so you don't lose it when the power goes ;)
 

hippy

Ex-Staff (retired)
Some good answers above. Basically you are looking at a circuit and program which can count activations with four parts -

1) PIR activation detection
2) Counting function
3) Zeroing / Reset function
4) Display count mechanism

If new to PICAXE you can develop each of those parts separately then combine them as a whole once happy with the operation of the individual parts.

How you want to display your count will really dictate which PICAXE is best. You could go for an electro-mechanical counter solution which has its own reset button and will only need a pulse giving to it to increment the count. For cheapness you can possibly modify a pedometer counter. In fact, an off the shelf burglar alarm PIR with relay switch output, 08M and pedometer may be a good idea to prototype with, get a feel for the PICAXE and other issues involved. You wouldn't really even need a PICAXE for that.
 

oKors

New Member
Wow, thanks for the great replies fellas. Yeah, being this new to Picaxe is really overwhelming at first. I'm only beginning to realize the power of picaxe!

So to answer some questions:
What is your previous electronics experience?
I have a two year AAS degree in electronics and manufacturing technology. What that means (5-years out of college later) is, I understand very well and can comprehend electronics terminology, follow schematics, test and identify electrical components and even troubleshoot to a great degree.
What I'm not so good at is knowing what I want in a semi-complex circuit and designing it from scratch. But that's what Google is good for!

Okors, did you mean a reset for the PICAXE chip or just a 'reset' (zeroing) button for your counter ?
...resetting the counter for the LCD display. I'm sure that's easy enough to figure out though.

... next you'll be asking how to save the value in EEPROM so you don't lose it when the power goes ;)
LOL, no I'm not that 'tarted.

Some good answers above. Basically you are looking at a circuit and program which can count activations with four parts -

1) PIR activation detection
2) Counting function
3) Zeroing / Reset function
4) Display count mechanism

If new to PICAXE you can develop each of those parts separately then combine them as a whole once happy with the operation of the individual parts.

How you want to display your count will really dictate which PICAXE is best. You could go for an electro-mechanical counter solution which has its own reset button and will only need a pulse giving to it to increment the count. For cheapness you can possibly modify a pedometer counter. In fact, an off the shelf burglar alarm PIR with relay switch output, 08M and pedometer may be a good idea to prototype with, get a feel for the PICAXE and other issues involved. You wouldn't really even need a PICAXE for that.
Indeed, all good answers. Your 4-part list sums my needs up best. As for the counter mechanism, I want a low-power lcd type counter.
In the end all the components will be housed in a rugged, weatherproof box with a sealed window to display the counter and a hole for the push-to-reset button. Battery optimization is crucial since I'll be using this device in remote locations and only checking in on it once a month.

Would an 08M chip work? I have an 08M kit already and a programing cable (no PIR yet). If this could get me started I will looking into buying one of those ePIR's Chava suggested.

Thanks again guys!

...back to searching some more
 

hippy

Ex-Staff (retired)
It may be possible with an 08M but if you want to use parallel controlled LCD rather than FRM010, AXE033 or other serial controlled LCD you'll need some extra I/O and the larger program space may be an advantage as well.

Always hard to say what's needed until there's more detail on what needs to be done. It may turn out that the PIR sensor needs some filtering to keep accurate counts without missing any and that could be software intensive requiring larger code space.

I would probably design and prototype using a 20X2. If that's done right, using only pins B.0, B.1, C.6 and C.7, you can likely drop an 08M in place of the 20X2 and it's only an issue of converting the code. Symbol definitions for I/O pin names etc will help there.
 

oKors

New Member
...the "e" in ePIR

Going low voltage and with the promise of greater functionality, you may also have a look at the ePir. I bought a few but haven't got round to use them yet, so don't know if they are really good.

BTW, whats the "E" in ePIR mean?

Sorry but unless I'm missing something mfg docs don't specify.
 

Chavaquiah

Senior Member
I don't know what the e in ePir means. I guess it's just a trademark that Zilog uses.

Anyway, I'm sorry to have sent you in a wrong path, as I don't think that this Zilog PIR is the best answer to your projects. I was not aware you would require extremely low power. The ePIR packs a lot of functionality but at a cost (battery drain).

The Napion, on the other hand, has a version optimized for low power - 46µA, or so Panasonic says.
 

Haku

Senior Member
I got 4 almost identical to those Parallax ones for $15 from Hong Kong including postage. http://shop.ebay.co.uk/i.html?_nkw=4+pir+circuit

They use 40uA when sensing and 60uA when triggered. You can adjust how long the output stays high for when triggered but not the sensitivity, however it is very sensitive and can spot you at a distance of two rooms easily. Only downside I found was that I couldn't plug it directly into a breadboard because the capacitors got in the way, bending the pins might work though.

I recently hooked the output of one up to a mosfet so when it was triggered it switched on a wireless camera and a 433mhz transmitter, at the other end I hooked up the 433mhz receiver to another mosfet so it switched on the AV receiver and a pocket tv with AV in.
 
Top