MicroBit Room Occupancy Counter and Controller

Introduction: MicroBit Room Occupancy Counter and Controller

About: Life long maker and Arduino fanatic! High School Computer Science teacher. Go out and make something Wonderful!

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)

Step 1: Build the Room Counter Circuit

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!

Step 2: Testing Your Circuit

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.

Step 3: Coding the Room Occupancy Counter

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!

Step 4: Build the Command Centre and Code It

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!!!!

Block Code Contest

Participated in the
Block Code Contest

Be the First to Share

    Recommendations

    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Big and Small Contest

      Big and Small Contest
    • For the Home Contest

      For the Home Contest

    3 Comments

    0
    MakersAtMicrosoft
    MakersAtMicrosoft

    2 years ago

    Excellent project idea! Definitely useful, even beyond the pandemic. Great write-up, as well. Curious, how accurate/reliable have you found the LDRs?

    0
    hausofpayne17
    hausofpayne17

    Reply 2 years ago

    If you could link my Instructable on your website I'd appreciate it. Thank you.

    0
    hausofpayne17
    hausofpayne17

    Reply 2 years ago

    Thank you for your very kind thoughts!

    I find the key to accuracy in LDRs is getting a good threshold sample before the progam actually gets into the main loop.

    You may not get predictable and reliable results in a dimly lit room

    I'm working on another project and I've set my activation threshold to 97% of the average of 100 samples of the ambient light. Seems to work pretty well.

    An LDR is a sensor worth about 2 cents. So it's not a high accuracy device. But in many applications, it does a great job.

    If you want, put a light source across from the LDRs to give them brighter illumination like the light beams in elevators. You'll get reliable results.

    Thanks again!

    Gord