how to know entry and exit of a person.

Iam a beginner in arduino. kindly help me to develop a sketch for detecting the entry of person in to a toilet and through detecting the entry, the toilet light should turn on and by detecting the exit of the person, the light should turn off.
the important thing is that i am using a pir sensor(modified to narrow the detecting angle by removing the Fresnel lens and attaching a 2 cm small pipe at the sensor ) and the pir is attached to one side of the entry to the toilet, so that when some body enters or exits the output will be high.

shall i use the modulo function for this purpose. if yes how it can be. pls help...

What if someone starts to go in, then changes their mind and goes back? After that, the light will turn off when someone enters and on when they leave!

(Weird)Can you post the photo (layout) of the TOILET ?

Can you place the sensor at wall ?When the toilet is occupied,the reading will be different than the reading when the toilet is unoccupied.

Place the sensor at the wall opposite to the door and you can detect the persons coming in.
-Malhar

This is probably exactly what you need.

Once you get that working with the led, I think you'll need to have a separate discussion on controlling mains power, but we'll worry about that another day.

With a single sensor, you can sense presence but you cannot distinguish entry from exit.

vaj4088:
With a single sensor, you can sense presence but you cannot distinguish entry from exit.

Re-reading the OP's first post, I see the idea is to use the PIR as a beam, which is probably not a great idea. Put the lens back on and use it like it's designed for.

There two issues with using PIR you need to consider. The first is when the ambient temperature is about the same as the people (or if they have heavy insulating coats on) - they become "invisible". The other issue to consider is PIR sensors tend to look for motion - so you have the poor person that goes in and sits down to "think" and the place goes dark because of no motion. Tends to be a bit irritating. I do see PIR used in restrooms in parks and such places, but I think what they do is if motion sensed turn on, but then keep it on for say 5 minutes AFTER that last motion is sensed (any other motion resets the 5 minute timer). The other way is with dual sensors in the doorway located a bit apart on the horizontal axis - by seeing which sensor breaks first, you can tell direction then you count up/down to determine number of people. Make sure the sensors are low enough to detect kids but high enough to not count two legs as two people. Probably have PIR as well for the case where someone takes their little kid in.

wouldn't it be easier to use a pressure senor on the floor to detect if someone is in there or not?

kau_cinta_ku:
wouldn't it be easier to use a pressure senor

In the men's yes.... but maybe not in the ladies'

:o

kau_cinta_ku:
wouldn't it be easier to use a pressure senor on the floor to detect if someone is in there or not?

What if I don't step on the pressure sensor?
What if someone poops on it ?spills water on it?