MicroBit Room Occupancy Counter and Controller

by hausofpayne17 in Circuits > Microcontrollers

1897 Views, 9 Favorites, 0 Comments

MicroBit Room Occupancy Counter and Controller

microBit Room Occupancy Counter with remote Command Centre
IMG-2766.JPG

During a pandemic, one way to reduce transmission of the virus is to maximize physical distancing between people.

In rooms or stores, it would be helpful to know how many people are in the enclosed space at any given time.

This project uses a pair of sensors to detect people entering and leaving a room. The circuit could be mounted on the door frame so people pass by it as they exit and enter.

It works by having two Light Dependent Resistors (LDR) set to detect a person passing the device. As the level of light falling on an LDR increases, the flow of current through the resistor increases. This can be measured by the microBit.

A person leaving the room will cross the ‘interior’ LDR first and that will be detected by the microBit. If there is more than one person in the room, it will subtract one from the occupant count.

A person entering the room will cross the ‘exterior’ LDR first and that will be detected by the microBit. If there are fewer than the maximum allowed people in the room, it will add 1 to the occupant count. If the exterior detector is passed, and there are already the maximum allowed people in the room, a ‘stop sign’ will be displayed and a warning sound will play.

Optional Command Centre

There is a second microBit that is the command centre. It would be at the cashier’s or teacher’s location. Every time someone enters or leaves the room, the room count is sent wirelessly to the command centre microBit. If the maximum occupancy is reached, the command centre microBit also beeps and shows the warning symbol.


The user can also increase or decrease the maximum occupancy by using the A and B buttons to change the maximum occupany value. By pressing Button A and Button B together, the new maximum value is sent wirelessly to the room counter microBit where the maximum occupancy value is updated.

Let’s build this project!

Supplies

Room Occupancy Counter

  • BBC microBit
  • Breadboard
  • Light Dependent Resistor (2)
  • 1K Ohm resistor (2)
  • Piezo Buzzer
  • Connecting wires
  • Alligator clip patch cords (5)

Command Centre (optional)

  • BBC microBit
  • Piezo buzzer
  • Alligator clip patch cords (2)

Build the Room Counter Circuit

IMG-2767.JPG
roomCounter circuit.png

Wire up the circuit as shown in the diagram. You can use the alligator clip patch cords to join the output wires, GND and 3V wires to the pins on the microBit.

Make sure you have the polarity of the piezo buzzer oriented correctly. If there's a shorter pin, it goes to GND and the longer pin goes to Pin 0 on the microBit. If they're the same length, the orientation does not matter.

Double-check your wiring and then let's get coding!

Testing Your Circuit

LDR Calibration Blocks.png

Before you spend time doing all the coding for the counter, take a few minutes to either enter this LDR Calibration sketch or upload the attached sketch .hex file to your microBit.

When running, the sketch will show you a little diamond on the display when it detects your hand covering the light dependent resistor. Test both analog pins 1 and 2 before proceeding to the next step.

Coding the Room Occupancy Counter

Room Occupancy Counter.png

Enter the code blocks on the diagram or upload the .hex file to your microBit.

The variable maxOccupancy can be adjusted to suit the occupancy limit of the room.

The levelDrop variable is the light level reduction value that must be exceeded before the microBit will count a person as entering/exiting the room. You may need to adjust this value based on the ambient light in your room.

When uploaded, try passing your hand over the 'exterior' light dependent resistor. The room count should increase.

As you keep 'entering' the room, eventually you'll exceed the maxOccupancy value and a 'stop sign' will display on the LED display and a short tune will play as an audible warning. No more people may enter the room.

Pass your hand over the 'interior' light dependent resistor and the room count should start decreasing each time you cover the light dependent resistor.

Okay! You've got a room occupancy counter built!

Want to make it even BETTER? Read on!

Build the Command Centre and Code It

Room Occupancy Monitor.png

Connect a second microBit as follows.

Using an alligator clip patch cord, connect the shorter side of a second piezo buzzer to the GND pin on the microBit.

Connect the longer side of the buzzer to Pin 0 of the microBit using another patch cord. Again, if the pins are the same length, the orientation doesn't matter.

This set of code blocks uses the radio features of microBit.

Enter the code blocks based on the diagram or upload the .hex file that's provided to the microBit.

Every time the room occupacy counter microBit detects an entry or exit, it sends the current room count to the monitoring station. If the maximum occupancy limit is exceeded it sends a '99' that the monitoring station detects and then shows the 'stop sign' and plays the warning sound.

The user may increase the maximum occupancy limit by pressing Button B on the microBit.

The user may decrease the maximum occupancy limit by pressing Button A on the microBit.

Pressing Button A and Button B together will send the new maximum occupancy value to the room occupancy counter microBit. You'll see a 'u' on the other microBit's display to indicate the value has been updated. Now the room occupancy counter will operate based on the new value.

I hope you found this Instructable fun and informative!

NOW GO MAKE SOMETHING WONDERFUL!!!!