Presence detection in front of a cupboard

Hi There!

I want to create an application with the following functions:

  • Is someone present?
  • If yes, measure duration of presence
  • Log time, date and position

I thought of a relative simple way to do this, but I'm not sure if I can. I want to use ultrasonic distance sensors to measure the presence of an object (in this case a person) by starting a time measurement if the sensor senses something in between a distance range (say, between 0.2 and 1.5 meters). I would like to use a Raspberry Pi to log the data and save to a NAS.

Can I make the Arduino output a signal if it detects something in that range, and if the Pi receives that signal make it do a time measurement (And log that data)? This setup would be installed on four cupboards that are next to each other, so can I give each sensor an ID of some sort? 1, 2, 3 and 4 for example to see the difference in usage between the cupboards?

Thanks in advance!

Can I make the Arduino output a signal if it detects something in that range

You can make the Arduino do any number of things. Some of them would make sense to the Pi. Some would not.

so can I give each sensor an ID of some sort?

No. The sensors are stupid devices. They couldn't remember their own name. So, they don't get one.

The Arduino, on the other hand, would know which pin each sensor is connected to, and could "output a signal" that was different depending on which sensor was giving input. Cabinet 1's sensor could cause the Arduino to sweep a servo with a semaphore flag attached. Cabinet 2's sensor could cause the Arduino to make a GET request to a server. Cabinet 3's sensor could make the Arduino turn pin 8 on. Cabinet 4's sensor could cause the Arduino to send a string via a bluetooth shield.

Or something like that... 8)

Thanks for the reply!

Could I make the Pi understand Cabinet 1 ON and Cabinet 1 OFF? And have a program run time measurements? The Arduino would just have to output those signals if it detects something in range.

Could I make the Pi understand Cabinet 1 ON and Cabinet 1 OFF?

You have my permission to do that.

And have a program run time measurements?

You have my permission to do that.

The Arduino would just have to output those signals if it detects something in range.

Ah, yes. But how? What does "output a signal" mean to you?

PaulS:
Ah, yes. But how? What does "output a signal" mean to you?

Something along the lines of:
If sensorsignalfrompinx=range
Then Serial.print("sensorx")

On a loop, so that every 500 ms it prints out "sensorx" which the Pi would then calculate the duration of and log.

Then Serial.print("sensorx")

I would use println(), so there is a clear delimiter between packets.

I would use 10 or 11 as the value to send for cabinet 1 (no one's home or what's for dinner), 20 or 21 for cabinet 2, 30 or 31 and 40 or 41 for the other cabinets. That makes parsing nearly trivial. Receive 4 bytes - cabinet number, state, carriage return, and linefeed. Verify that the last two bytes are what are expected. Use the first two bytes to determine what to do.

Even better, though, than sending the data over and over, would be to send the data only when a change happens. Let the Pi do the timing, based on when serial data arrives, which won't be long after it has been sent.

PaulS:
I would use println(), so there is a clear delimiter between packets.

I would use 10 or 11 as the value to send for cabinet 1 (no one's home or what's for dinner), 20 or 21 for cabinet 2, 30 or 31 and 40 or 41 for the other cabinets. That makes parsing nearly trivial. Receive 4 bytes - cabinet number, state, carriage return, and linefeed. Verify that the last two bytes are what are expected. Use the first two bytes to determine what to do.

Even better, though, than sending the data over and over, would be to send the data only when a change happens. Let the Pi do the timing, based on when serial data arrives, which won't be long after it has been sent.

Great ideas, thanks! I think I know enough to start this project with some hardware.

4 sensors, each comes in to the arduino. the arduino knows if it is sensor 1 through 4
the arduino outputs on 4 pins that connect to 4 pins on the Rpi. when pin 1 goes high, person present in from of cabinet 1
this is all child's play. very easy, even for a beginner.

if you want to signal the R pi with one wire, AND, you have some software skills, you could use 1 wire to output a change.
with some timing, you could alert the R pi a change occurred, then send the state of each cabinet. let the R pi figure which one changed.

but, I suspect that the R pi can just as easily read the sensors and know what cabinet is under what state.

That was indeed what I was thinking of doing, thanks! For this application it is not important to make it all one wire (since the jumper wires aren't big anyway), so I will start off with the easy route. Thanks for your input!