Traffic counter: how it is built
An induction loop under the tarmac counts every vehicle on our road, Fagerholmsvägen, since 2003. This page describes the hardware and software. The statistics are on the statistics page (in Swedish).
How it works
Since November 2026
- The loop. Wire laid under the tarmac. Every car changes the loop's inductance as it passes over it.
- The detector, a Sarasota 215B fed through a 240 to 120 VAC transformer, notices the change and closes a relay for as long as the vehicle is over the loop.
- The counter is a Wemos D1 mini (ESP8266, a WiFi microcontroller the size of a stamp). The detector gives a short pulse per vehicle, about 14 ms. The counter takes one pulse from the first closing of the relay until it has been open for 30 ms, so the contact's bounces when it closes and opens belong to the same vehicle, and a 2 s lockout stops one vehicle from counting twice. It stamps each vehicle with the exact time (NTP) and sends it over WiFi (MQTT). If the network is down it keeps up to 600 vehicles and sends them later with their real times.
- The server stores every vehicle in a database (SQLite), confirms each one back to the counter, and writes the figures for the statistics page. Every open page gets each vehicle the moment it is stored (Server-Sent Events through NGINX), about 0.7 s after the car has passed. On the 1st of every month it adds last month's summary.
- Home Assistant listens too, and flashes a yellow lamp indoors for every vehicle.

Three LEDs on the counter
Green blinks slowly: the program runs.
Blue is lit while a vehicle is over the loop.
Red means trouble: steady = no WiFi, fast blink = no contact with the server, slow blink = the server has not confirmed the vehicles.
The original build, 2018
From December 2018 to November 2026 a Raspberry Pi B+ did the counting. The loop and the detector are still the same.






With two loops a known distance apart on the same road, the counter could in theory work out each vehicle's speed. The Pi's Python program · All monthly summaries as text · The page as it was in 2018