Mattéo Pozzo di Borgo
Microengineering — between electronics, embedded systems and fabrication.
← Project timeline
Personal project

Bottle counter for a winemaker

A standalone ESP32 counter that detects each filled and corked bottle by infrared and shows the total live.

Period
Jul. 2026
Context
Personal project, made for my brother's wine estate
Team
Solo
Status
Completed
ESP32C++IR sensorOLEDEmbeddedCAD3D printing
Bottle counter fitted on the rotary part of the bottling machine
The counter on the machine, infrared sensor facing the bottles

Key points

  • Counts filled and corked bottles, directly on the rotary part of the machine
  • Contactless detection with a reflective infrared sensor
  • Total shown live on an SSD1306 OLED screen
  • C++ firmware on an ESP32, simply powered over USB-C
  • Start/Stop and Reset buttons, status LED, total kept in flash memory
  • Housing designed in Inventor and 3D-printed, mounted on an off-the-shelf universal clamp

The need

My brother is a winemaker. During bottling, he wanted to know how many bottles had been filled and corked, without counting them by hand.

How it works

On the machine, the bottles first go through a rotary system, then are placed on a conveyor. Counting happens on the rotary part: each time a bottle passes in front of it, the reflective infrared sensor detects it, the ESP32 increments the counter and the screen shows the new total.

Hardware

  • ESP32, programmed in C++
  • Reflective infrared sensor, to detect bottles without contact
  • SSD1306 OLED screen, to show the total
  • Powered through the ESP32's USB-C port

Interface and wiring

The ESP32 drives a screen, a sensor, two buttons and two LEDs. The buttons are wired to ground and use the ESP32's internal pull-up resistors: a press pulls the input low.

Wiring diagram of the ESP32 with the OLED screen, the infrared sensor, the two buttons and the two LEDs
PartESP32 pinRole
SSD1306 OLED screenGPIO 2 (SDA), GPIO 15 (SCL)Shows the total, I²C bus, address 0x3C
Reflective IR sensorGPIO 13Output goes low when a bottle passes
Start/Stop buttonGPIO 22Starts or pauses counting
Reset buttonGPIO 23Resets the total to 0
Green LEDGPIO 19Counting active
Red LEDGPIO 21Bottle in front of the sensor

Counting logic

The program does not count the presence of a bottle but its arrival: a pass is counted on the falling edge of the sensor signal, when it goes from high to low. A bottle standing still in front of the sensor is therefore counted only once.

After each count, further edges are ignored for 150 ms. This debounce delay avoids counting a bottle twice when its edge or label makes the signal flicker. It also sets the maximum rate: 1 / 0.150 s ≈ 6.7 bottles per second, i.e. about 6.7 × 60 ≈ 400 bottles per minute, well above the machine's pace.

The total is saved to the ESP32's flash memory every 10 bottles, on stop and on reset: after a power cut during bottling, the counter restarts from the last saved total, with at most 9 bottles to recount.

Housing

I designed the housing in Inventor to fit an off-the-shelf universal clamp. It is made of two 3D-printed parts: the housing, which holds the electronics, the screen and the sensor, and a plate screwed onto the clamp. The counter can therefore be fitted to the machine without modifying it.

3D render of the two housing parts: the 66 × 123 × 26 mm housing and the 71 × 8 × 68 mm mounting plate

How the code evolved

The project was first written in MicroPython, in four successive versions. The first lays the groundwork: a state machine that ignores detections that are too short, and saving the total. The next ones add the OLED screen, then the LEDs, then the splash screen and the large-digit display. The final version was rewritten in C++ with the Arduino environment. All versions are in the GitHub repo.