Alright, folks, let’s dive into how I cobbled together a pretty neat, and super cheap, people-counting system for small spaces. I’ve been needing something like this for my workshop – you know, to get a handle on how many people are actually showing up to my weekend woodworking classes. I didn’t want to shell out big bucks for some fancy commercial system, so I decided to get my hands dirty and build my own.
The Idea
The basic idea was simple: I wanted to use something readily available and easy to work with. And since I am always tinkering, I have some ESP32 boards lying around. It’s perfect for this, It’s got built-in Wi-Fi, and you can program it with the Arduino IDE, which I’m already comfy with. I paired that with a couple of infrared breakbeam sensors – the kind you see on garage doors to keep them from closing on your car. Super basic, super cheap.
Gathering the Parts
Here’s what I grabbed:
- ESP32 Dev Board: I just used one I had on hand. Any generic one should work.
- Infrared Breakbeam Sensors (x2): I got a pair from a local electronics store, it’s pretty standard.
- Jumper Wires: To connect everything up. A bunch of female-to-female ones.
- Resistors: A couple of 220-ohm resistors, just to be safe with the LEDs in the sensors.
- Power Supply: I used a standard USB charger and a micro-USB cable to power the ESP32.
- Enclosure (optional): I 3D printed a simple case, but it’s not strictly necessary.
Setting Up the Hardware
First thing, I placed the sensors. I put one pair at the entrance, about waist-high. The idea is that someone walking through breaks the beam, and that’s how I count them. I made sure they were aligned properly – the transmitter (the one with the LED) needs to point directly at the receiver.
Then came the wiring. I am not an electrician, so I connected everything with what I have, connecting:
- The VCC (power) pin of each sensor to the 3.3V pin on the ESP32.
- The GND (ground) pin of each sensor to a GND pin on the ESP32.
- The signal pin of the first sensor to one of the digital pins on the ESP32 (I used pin 14).
- The signal pin of the second sensor to another digital pin (I used pin 27).
- Inserted the 220-ohm resistors in series with the LED side of each sensor, just to protect them.
It’s worth double-checking all the connections, to be safe.
The Code
Now, for the brains of the operation – the code. I fired up the Arduino IDE and wrote a simple sketch. The basic logic is:
- Initialize everything: Set up the pins for the sensors as inputs.
- Monitor the sensors: Keep checking if the beams are broken.
- Count people: If the first sensor is triggered, then the second, someone has entered. If the second is triggered, then the first, someone has exited.
- Send to the Cloud: Use the built in wifi of ESP32 to send the final data.
I won’t bore you with the code, but it’s all about reading the state of the sensors and keeping track of the count. I added some debouncing to avoid false triggers – sometimes the beam might flicker for a split second, and you don’t want to count that as a person.
Testing and Tweaking
After uploading the code to the ESP32, I did some testing. I walked through the doorway, and see the count changed. Then the other way. Perfect! I had to tweak the sensor placement a bit to make sure they were reliable, and I adjusted the debouncing delay in the code to get it just right.
Putting It All Together
Once I was happy with how it was working, I packed everything into the 3D-printed enclosure. I made sure the sensors were sticking out and properly aligned. And that was it! I mounted it by the entrance to my workshop, plugged it in, and started getting real-time data on how many people were coming and going.
It is not perfect, of course. If two people walk through at the exact same time, it might only count one. But for my needs, it’s more than good enough. And it cost me next to nothing! It’s been a fun project, and it’s actually pretty useful. If you’re looking for a simple, cheap way to count people in a small space, this is definitely a way to go.