Building a Smart Object Counter & Automated Bin with Arduino

Building a Smart Object Counter & Automated Bin with Arduino

July 16, 2026 by ThinkRobotics
Share

Have you ever needed to keep track of how many items pass down a conveyor belt, or wanted to build a smart trash bin that tells you when it is full? This project turns a standard Arduino Nano into an automated object counter using a simple infrared (IR) sensor. It tracks every object that passes by and even gives a visual hardware alert when the bin reaches its maximum capacity. Code for this project is available here.

The Hardware Setup

This build relies on three main components communicating with each other:

Arduino Nano IR Sensor I2C LCD Display (0x27)
  • IR Sensor: Connected to digital pin 2, this acts as our digital tripwire.
  • I2C LCD Display: Operating on standard address 0x27, this screen displays the live count and system alerts.
  • The Brains: An Arduino Nano reading the sensor and pushing visual updates to the screen.

Component Pinout Guide

Wire your components to the Arduino Nano using the following connections:

Component Component Pin Arduino Nano Pin Function
IR Sensor VCC 5V Power supply
IR Sensor GND GND Ground
IR Sensor OUT / SIG D2 Digital signal (Tripwire)
I2C LCD VCC 5V Power supply
I2C LCD GND GND Ground
I2C LCD SDA A4 I2C Data line
I2C LCD SCL A5 I2C Clock line

How It Works: Tracking Capacity

The core logic is built around a predefined "bin capacity" of 10 items. When the IR sensor detects an object, its signal drops to LOW. The Arduino registers this event, increments the total object count by one, and immediately updates the LCD to show the new count.

Once the recorded count hits that magic number of 10, the system goes into alert mode. The screen clears its standard tracking text and flashes a "!!! ALERT !!! BIN IS FULL" message.

Technical Highlights in the Code

State Change Detection

The code does not just blindly count whenever the sensor is blocked. It actively compares the current sensor state to the last known state. This ensures that if an object stops directly in front of the sensor, it only gets counted exactly once, preventing inflated false data.

Driverless I2C Communication

To keep the compiled memory footprint as light as possible, this code skips bulky third-party display libraries. Instead, it uses custom, bare-metal functions to send hexadecimal commands directly over the I2C bus to the display.

Hardware Visual Alarms

When the bin is full, the code takes the alert a step further than just text on a screen. It manipulates the LCD's backlight variable, toggling between LCD_BACKLIGHT and LCD_NOBACKLIGHT every 500 milliseconds to physically flash the screen and grab your attention.