Presence detector example

BendyRoad BrainBuilder: The easiest way to create custom firmware

Presence detector example

My first BrainBuilder project was inspired by an assignment from a few years ago.

People were always walking around to check every office, looking for an available workplace. It would be really convenient if they would be able to see which desks were free, on a display in the lobby.

An office floorplan with occupied and free desks

After all, it’s simply a matter of detecting whether or not people are sitting at desks.

Or so you would think.

I requested offers from suppliers, but these turned out to be too expensive, or vaporware. Management requested we would develop one ourselves. But developing reliable firmware for the desk sensors proved to be much more difficult and time-consuming than we had budget for. We developed a prototype, and then the project was shelved.

Now, with BendyRoad BrainBuilder, I revisited that idea.

The very first requirement for a workplace occupancy system is finding out if a workplace is occupied or not. Passive infrared detectors are commonly used for that. They have a very wide field of view and ‘see’ infrared. If something changes in that view, the output signal is set to ‘high’. They are pretty good at detecting human presence.

There are a few of things to watch out for when using PIR sensors; for example activation of the sensor by a person or animal walking past. This should not result in the desk being marked ‘occupied’, and it should not be considered ‘free’ while someone is just gone for a while to fetch coffee.

The logic for marking desks as free or occupied depends on user preferences, so this is solved in firmware.

I built my prototype by wiring up the infrared sensor and a couple of LEDs to an Arduino. I quickly had a working prototype in a few hours, and then kept on adding features. A display shield shows how long I’ve been at my desk, and how long it was free before I sat down.

Development board with human-presence-detector hardware

There isn’t a ready-to-use clock (yet!) in BrainBuilder, so I made one by creative use of variables for hours, minutes and seconds.

Now that I’m writing this, glancing at that clock showing ‘occupied’, I get the idea for a feature to alert me to get up and walk for a bit. Will it be a blinking LED, or a buzzer? Why not both? Will it be something I can set on or off via the keyboard?

I’m just going to try these ideas out with BrainBuilder. It’s very quick to implement them, and see if they work out in real life.

Working example

Here is the full story on how it works, as an example you can follow step by step.

Workplace occupancy sensors detect if someone is sitting at a desk. Typical use is in flex-offices to create an overview of available workplaces.

How it works

A passive infrared (PIR) sensor is mounted on or under a desk, and is triggered by motion and movement. When someone sits down at the desk, the sensor signals a change in status.

Shopping list

  • passive infrared sensor of the type HC-SR501, this comes already mounted on a small PCB, see images below
  • 3 LEDs
  • Arduino display shield
  • Arduino Uno

How to make one

  • Adjust the jumper and the potentiometers on the sensor’s PCB: See our information on PIR sensors.
  • Connect the infrared-sensor
  • Wire the LEDs
  • Download the example program here by right-clicking on the link, then choose ‘save link as’: presence detector example and save the file ‘presence_detection.prg’ in your BrainBuilder Development Studio work directory.
  • Start the BrainBuilder Development Studio and open the example.
  • Check if the right development board is specified; that’s under ‘Hardware’, default is an Arduino Uno. If you use an Arduino Mega, delete the Arduino Uno (right-click, then delete), and add an Arduino Mega, and give a name to the Mega.
  • Customize the settings (pins for the LEDs, digital-input pin for the infrared-sensor) TODO screen print details
  • Customize the setting for the timing: how much time to wait before signaling the workplace is occupied (this avoids triggering by people walking by)
  • For signaling that the workplace is free, there is also a customizable wait period (to keep the occupied status while someone is away to get a coffee)

Outputs

  • The white LED lights when the infrared-sensor signals there is movement. There is no processing done on this output. This makes it easy to adjust the infrared-sensors potentiometers.
  • The green LED lights when the workplace is free
  • The red LED has two functions: showing the sensor is in the 20-second calibration phase after the Arduino has just started up, and showing the desk is occupied
  • There is also telemetry output over the serial port; it reports the status periodically
  • This example makes use of a display showing the current status on the left and the last status period on the right. This is

Further customization

  • You may not need the display, the LEDs or the telemetry. You can simply delete them or set them to ‘disabled’ in case you might need them later.
BrainBuilder Development Studio with human-presence-detector example
Close-up human-presence-detector Arduino display showing status

Try now >>>