AI & Agents

How to Build a People Counter with OpenClaw and Raspberry Pi for Retail Analytics

Most Raspberry Pi people counter projects stop at raw counts dumped to a CSV. This guide goes further: you wire a sensor to a Pi, pipe the data into an OpenClaw agent, and get daily natural-language reports covering peak hours, trends, and anomalies. The result is a sub-$100 retail analytics system that turns foot traffic numbers into actionable insight.

Fast.io Editorial Team 9 min read
AI agent workspace for retail analytics data

Why Foot Traffic Data Matters for Retail

Foot traffic is the most fundamental metric in physical retail. It tells you when customers arrive, how long they stay, and which hours justify extra staffing. Grand View Research valued the global people counting system market at $1.35 billion in 2022, projecting it to reach $2.65 billion by 2030 at a 12.2% CAGR. That growth reflects a simple truth: stores that measure foot traffic make better decisions about staffing, layout, and promotions.

Commercial people counting systems from vendors like V-Count and FootfallCam cost thousands per location. For a single storefront, pop-up shop, or co-working space, that price makes no sense. A Raspberry Pi with a $5 IR sensor and an OpenClaw agent can deliver the same core insight at a fraction of the cost.

The gap in existing DIY guides is what happens after counting. Most tutorials end with a number on a screen or a row in a spreadsheet. They don't answer the questions a store manager actually asks: "Was today busier than last Tuesday?" or "What time should I schedule my second cashier?" That's where an AI agent adds value.

What to check before scaling openclaw raspberry pi people counter retail analytics agent

Two sensor approaches dominate Pi-based people counters. Each has clear tradeoffs.

IR break-beam sensors use an emitter and receiver pair mounted on opposite sides of a doorway. When someone walks through, they break the beam and the Pi registers the event on a GPIO pin. Pairs cost $5 to $10 from Adafruit or similar suppliers, draw minimal power, and work in any lighting condition. The receiver wire connects to a GPIO pin set as an input with a pull-up resistor, going low when the beam is broken. Effective range tops out around 40 to 50 cm, so they work best in standard doorways.

The main limitation is directionality. A single beam counts events but can't distinguish entry from exit. Two parallel beams spaced a few inches apart solve this: the order of beam-break events tells you which direction the person moved. Even so, IR sensors struggle when two people walk through side by side.

Camera-based counting uses the Pi Camera Module 3 (a 12MP Sony IMX708 sensor with autofocus, 1080p video, and a 75-degree field of view) paired with OpenCV or a TensorFlow Lite model. The Picamera2 library provides the Python interface. Camera counting can detect direction, distinguish people from objects, and even estimate group sizes. Accuracy improves with good lighting and a top-down camera angle.

The tradeoff is complexity. Camera-based counting needs more processing power, more storage for frames, and more careful calibration. A Pi 5 with 4GB RAM handles it, but a Pi 4 will run hot under sustained video processing. Privacy is also a factor since you're recording video of customers.

Quick Comparison - Cost per unit: IR break-beam $5 to $10 per pair. Camera Module 3 around $25 to $35.

  • Direction detection: IR needs dual beams. Camera handles it natively.
  • Accuracy in crowds: IR drops off with side-by-side traffic. Camera handles groups better.
  • Privacy impact: IR records no identifiable data. Camera captures video frames.
  • Processing load: IR uses near-zero CPU. Camera requires sustained CPU or GPU work.
  • Lighting sensitivity: IR works in darkness. Camera needs adequate light.

For a single-door retail shop, dual IR beams give you the best cost-to-accuracy ratio. For larger spaces or multi-entrance setups, camera-based counting justifies the added complexity.

Setting Up OpenClaw on a Raspberry Pi

OpenClaw turns a Raspberry Pi into an always-on AI agent. The Pi handles sensor input and local logic while OpenClaw routes the reasoning to cloud-hosted LLMs via API. Even a Pi 4 with 2GB RAM works since the heavy computation happens server-side.

According to the official OpenClaw docs, you need a Raspberry Pi 4 or 5 with at least 2GB RAM (4GB recommended), a microSD card of 16GB or larger (or a USB SSD for better reliability), and a 64-bit OS.

The documented installation path starts with flashing Raspberry Pi OS Lite (64-bit) using the official Raspberry Pi Imager. Enable SSH during the setup wizard so you can configure the Pi headless. After first boot and system updates, install the required dependencies (git, curl, build-essential), then Node.js via the NodeSource repository, and finally OpenClaw itself using the official install script.

The onboard wizard walks you through API key configuration. OpenClaw's docs recommend API keys over OAuth for headless devices, which makes sense for a sensor node that runs unattended. The --install-daemon flag during onboarding sets up OpenClaw as a background service that restarts on boot.

Power draw is minimal. A Pi 5 running OpenClaw averages around 5W, which translates to roughly $0.50 to $1.00 per month in electricity. That's the "server cost" for your retail analytics agent.

Fastio features

Give your retail analytics agent a persistent workspace

Upload daily foot traffic reports from your Pi to a shared workspace with built-in AI search. 50GB free, no credit card required. Built for openclaw raspberry people counter retail analytics agent workflows.

Building the Counting Pipeline

The architecture has three layers: sensor input, local counting logic, and agent analysis.

Layer 1: Sensor input. For IR break-beam sensors, a Python script monitors the GPIO pin. When the beam breaks, the script logs a timestamped event. With dual beams, it checks which beam fired first to determine direction (in vs. out). For camera-based setups, a Python script captures frames via Picamera2, runs them through an OpenCV background subtractor or a MobileNet SSD model, and logs detected person events with timestamps.

Layer 2: Local counting logic. A lightweight script aggregates raw sensor events into structured counts. Every 15 minutes (or whatever interval suits your traffic volume), it writes a summary to a local JSON or CSV file: timestamp, entries, exits, net occupancy. This runs independently of the agent, so you never lose data if the network drops.

Layer 3: Agent analysis. This is where OpenClaw adds value beyond raw counting. On a schedule (hourly, end-of-day, or both), a script passes the accumulated count data to OpenClaw for analysis. The agent can answer questions like:

  • What were peak traffic hours today?
  • How does today compare to the same day last week?
  • Were there any unusual spikes or drops?
  • Based on this week's pattern, what staffing does tomorrow need?

The key insight is that OpenClaw acts as the reasoning layer while the Pi handles data collection. Raw counts go in, natural-language analysis comes out. You don't need to build dashboards or write SQL queries. The agent reads the data and writes a report in plain English.

For persistent storage and team access, the reports need to go somewhere beyond the Pi's SD card. This is where a workspace platform fits into the pipeline.

AI-powered document analysis and summary generation

Storing Reports and Sharing with Your Team

A Pi running under a shop counter is not where your store manager checks analytics. The reports need to land in a shared workspace where the right people can access them.

You could use local network shares, email, or cloud storage like Google Drive or S3. Each works, but each has friction. Network shares require VPN or LAN access. Email buries reports in inboxes. S3 needs IAM configuration and a separate viewer.

Fast.io offers a cleaner path for agent-generated content. The OpenClaw agent can upload daily reports to a Fast.io workspace using the MCP server or the REST API. Once uploaded, files are automatically indexed by Intelligence Mode, which means your team can ask questions about the data in natural language: "What was our busiest day last month?" or "Show me the trend for Saturday foot traffic." No separate vector database or search setup required.

The free agent plan includes 50GB of storage, 5,000 monthly credits, and 5 workspaces with no credit card and no expiration. That's more than enough for daily text reports and weekly summaries. Workspace permissions let you give the store manager read access while the agent retains write access, and the ownership transfer feature lets you hand the entire workspace to a client if you're building this for someone else.

Other options worth considering:

  • InfluxDB + Grafana for time-series dashboards if you want visual charts
  • Google Sheets via their API for simple shared spreadsheets
  • Notion for teams already using it as a wiki

The advantage of Fast.io over these alternatives is the built-in AI layer. Your reports aren't just stored; they're queryable. A store owner who doesn't read CSVs can open the workspace chat and ask plain questions about their foot traffic data.

Practical Tips and Common Problems

Sensor placement matters more than sensor quality. An IR break-beam mounted at waist height in a 90cm doorway will outperform a camera mounted at a bad angle. Test placement before you commit to permanent installation. For IR sensors, mount the emitter and receiver at the same height on opposite sides of the doorframe, 80 to 100cm from the floor.

SD card reliability is a real concern. Constant logging writes wear out microSD cards. Use a USB SSD for any production deployment, or at minimum, write logs to a tmpfs partition and flush to disk on a schedule. A 128GB USB SSD costs about $15 and will outlast any SD card.

Network interruptions shouldn't lose data. Always buffer counts locally before sending them to the agent or uploading reports. The counting script should work offline and sync when connectivity returns. Design the pipeline so each layer can fail independently without data loss.

Calibration takes iteration. The Code4Lib Journal documented a study at Hudson County Community College comparing PIR, laser, and ultrasonic sensors on Raspberry Pi units. None achieved reliable accuracy out of the box, and all required recalibration after environmental changes. People lingering in doorways threw off every sensor type. Build in a calibration period of at least a week before trusting the numbers.

Privacy considerations for camera setups. If you use camera-based counting, process frames on-device and discard them after extracting count data. Don't store raw video unless legally required. Post signage if your jurisdiction requires disclosure of video monitoring. IR sensors avoid this issue entirely since they capture no identifiable information.

Start simple, add complexity later. A single IR break-beam with a daily OpenClaw summary report is a working system. You can add direction detection, occupancy tracking, camera-based counting, and trend analysis incrementally. Each addition should solve a specific question your team is actually asking.

Frequently Asked Questions

How do I build a people counter with Raspberry Pi?

Connect an IR break-beam sensor pair to your Pi's GPIO pins, then run a Python script that monitors the receiver pin for beam-break events. Each event gets a timestamp. For direction detection, use two parallel beam pairs and check which fires first. Aggregate the raw events into hourly or daily counts using a second script. The Adafruit break-beam sensor tutorial covers the wiring in detail.

Can Raspberry Pi do retail analytics?

Yes, but with a caveat. The Pi handles data collection (counting, timestamping, local storage) well. For analytics, meaning trend detection, comparisons, and reporting, you need either custom code or an AI agent like OpenClaw to interpret the raw numbers. The Pi collects the data; the agent makes sense of it.

What sensor is best for counting foot traffic?

IR break-beam sensors offer the best balance of cost, reliability, and privacy for single-doorway setups. They cost $5 to $10 per pair and work in any lighting condition. Camera-based counting with the Pi Camera Module 3 gives better accuracy in wider spaces and can detect direction natively, but costs more, uses more power, and raises privacy concerns.

How accurate are Raspberry Pi people counters?

Accuracy depends heavily on sensor type and placement. IR break-beam sensors in standard doorways achieve good accuracy for single-file traffic but struggle with side-by-side entry. Camera-based counters using OpenCV or TensorFlow Lite can reach higher accuracy in controlled conditions. A study published in the Code4Lib Journal found that no Pi sensor type achieved reliable accuracy without careful calibration and environmental tuning.

How much does a DIY people counter cost?

A basic setup runs $50 to $100 total. That includes a Raspberry Pi 4 or 5 ($35 to $80 depending on RAM), an IR break-beam sensor pair ($5 to $10), a microSD card or USB SSD ($10 to $15), and a power supply ($8 to $12). OpenClaw is free to install, though you pay for the LLM API calls it makes. At typical usage, API costs run a few dollars per month for daily report generation.

Related Resources

Fastio features

Give your retail analytics agent a persistent workspace

Upload daily foot traffic reports from your Pi to a shared workspace with built-in AI search. 50GB free, no credit card required. Built for openclaw raspberry people counter retail analytics agent workflows.