Alright, so I’ve been messing around with this idea for a while now, trying to get a decent foot traffic counter working for my buddy’s small shop. He wanted something simple, cheap, and not too intrusive, you know? Something that wouldn’t scare away the customers or cost him an arm and a leg.

I started by looking at what was already out there. Most of the commercial stuff was either way too expensive or required some serious installation that we just didn’t want to deal with. Plus, a lot of them needed a constant internet connection, which is a bit iffy in his place. So I figured, why not try to build something myself? I’ve always been a bit of a DIY guy, and this seemed like a fun challenge.

My first go

My first idea was pretty basic: use a couple of those cheap infrared sensors, the kind you see in automatic doors or security systems. I hooked them up to a little microcontroller, an Arduino in this case. The plan was simple: one sensor to detect people entering, and another to detect people leaving. I wrote some code to count the difference, and voila, a basic foot traffic counter! Or so I thought.

I set it up in his store, right by the entrance. It kinda worked, but it was super unreliable. Sometimes it would count one person as two, or miss people entirely. It was especially bad when a group of people walked in together. The sensors just couldn’t keep up. Plus, the wires were all over the place, and it looked pretty messy. Not exactly the professional look my buddy was going for.

Back to the drawing board

Okay, so the infrared sensor idea was a bust. I needed something a bit more sophisticated. I started looking into ultrasonic sensors. They’re a bit more accurate than infrared, and they can handle multiple people better. I grabbed a couple from an online store, replaced the infrared ones in my setup, and rewrote the code.

This time, it worked a bit better. It was definitely more accurate, and it didn’t get confused by groups as much. But it still wasn’t perfect. It would sometimes get triggered by things that weren’t people, like a stack of boxes being moved or a large shopping bag swinging around. It needed something more than just detecting motion. It needed to actually recognize people.

The camera solution

That’s when I started thinking about using a camera. I mean, cameras are everywhere these days, and they’re pretty good at seeing things, right? I did some digging and found this open-source library called OpenCV. It’s used for computer vision, basically teaching computers to “see.” I thought, maybe I could use this to detect people in the camera’s view.

I got myself a cheap USB webcam and hooked it up to a Raspberry Pi. This was a bit more involved than the Arduino setup. I had to install an operating system on the Pi, get OpenCV up and running, and then write some Python code to process the camera feed. It took a lot of trial and error, and a lot of late nights staring at a screen, but I finally got something working.

The code uses OpenCV to detect “blobs” in the video that look like human shapes. It then tracks these blobs as they move across the frame. If a blob crosses a certain line, it’s counted as a person entering or leaving. It’s not foolproof, but it’s surprisingly accurate. It can even handle multiple people walking in and out at the same time, which was a big win.

The final product

So, after all that tinkering, I finally had a working foot traffic counter. It’s not perfect, but it’s way better than my first attempt. It’s also pretty cheap to make. The most expensive part was the Raspberry Pi, and even that’s not too bad. And the best part is, it doesn’t need an internet connection to work. It just stores the counts on an SD card, and my buddy can check them whenever he wants.

I put the whole thing in a nice little box, so it doesn’t look like a science project anymore. It’s now sitting discreetly above the entrance of his store, happily counting away. He’s been using it for a few weeks now, and he’s pretty happy with it. He says it gives him a much better idea of how many people are actually coming into his store, which helps him with things like staffing and inventory.

It was a fun little project, and I learned a lot along the way. Maybe this will inspire some of you to try building your own foot traffic counter. It’s not as hard as you might think, and it can be a really useful tool for a small business.