A simple AVR-based object counter that uses an IR obstacle sensor to detect passing objects, displays the count on a 16x2 I2C LCD, and provides visual feedback via an RGB LED.
See implementation: counter.c (key symbols: F_CPU, IR_SENSOR_PIN, RESET_BUTTON, RED_PIN, GREEN_PIN, BLUE_PIN, set_color, I2C_init, LCD_init, LCD_print, LCD_setCursor, main).
- Real-time counting of objects passing an IR sensor.
- Live count displayed on 16x2 I2C LCD.
- RGB LED status: green on detection, blue idle.
- Manual reset button to clear the count.
- Implemented with low-level AVR register programming (no Arduino libraries).
- Arduino Uno (ATmega328P) — controller
- IR-08H obstacle sensor — detection
- KY-016 RGB module — visual status
- 16x2 LCD with I2C backpack — display
- Push button — reset
- Breadboard, jumper wires, 5V supply
- IR OUT -> Arduino D2 (PD2)
IR_SENSOR_PIN - IR VCC -> 5V
- IR GND -> GND
- RGB RED -> D9 (PB1)
RED_PIN - RGB GREEN -> D10 (PB2)
GREEN_PIN - RGB BLUE -> D11 (PB3)
BLUE_PIN - Reset button -> one side to PD3 (D3)
RESET_BUTTON, other side to GND (use internal pull-up) - LCD SDA -> A4, SCL -> A5, VCC -> 5V, GND -> GND
(Refer to counter.c for exact pin macros and behavior.)
- On power-up the LCD shows "Object Counter" and initializes peripherals via
I2C_initandLCD_init. - The program polls the IR sensor on
IR_SENSOR_PIN. A LOW on this pin indicates an object and increments the count (debounced via software). - On detection the LED is set via
set_colorto green and the new count is printed usingLCD_print/LCD_setCursor. - When idle the LED displays blue. Pressing the reset button (active LOW) clears the count.