Digital Object Counter

Digital counter is a device used to count the objects at the industrial level and the domestic level, it stores and displays the number of times a particular event or process has occurred in relation to a clock. We are using Arduino for the design of a digital counter and hence the built-in clock of Arduino is used.  


  1. Arduino UNO
  2. 16×2 Liquid crystal display
  3. Potentiometer
  4.  Jumper wires
  5. IR sensor


Circuit Diagram

How to Install Library for LCD?

Before uploading the code install the library for Liquid Crystal Display. Open Arduino IDE, go to tools, click on manage library. The library manager will pop up. Search for Liquid Crystal library and install it. The figure below may help you. 

LCD Library


Upload the code to your Arduino UNO. 

					#include <LiquidCrystal.h>

#define rs 9 
#define en 8 
#define d4 7 
#define d5 6  
#define d6 5 
#define d7 4 
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int relay = 13;  
unsigned int ballcount = 0;
unsigned int Tballs = 0; // total balls
int ballf = 0; // ball flag.  
int resetb = 3; // to reset the relay , this can be laser or an infrared sensor. 

void setup(){
// set up the LCD's number of columns and rows: 
    lcd.begin(16, 2);
// Print a message to the LCD.
    lcd.print("Tballs     ");
    attachInterrupt(0, add, FALLING);  
    pinMode(resetb, INPUT); 
    digitalWrite(resetb, HIGH); 
    pinMode( relay, OUTPUT);
    digitalWrite(relay, LOW); 
    ballcount = 0;
    Tballs = 0; 

void loop(){
    if ( ballf == 1 ) // the lcd is updated only when ballf = 1, this way the controller won't be busy printing the values on lcd again and again. 
//Print out result to lcd
        lcd.clear(); // to clear the screen every time we reset the arduino 
        lcd.print("Tballs  ");
        lcd.setCursor(0,1);  // to set the cursor at zero column and 1st row of LCD
        ballf = 0;    
if ( digitalRead(resetb) == LOW)
    //digitalWrite(relay, LOW); 
    Tballs =0;
void add()
    ballf = 1; 
    Tballs = Tballs + 1;  
    if (ballcount >= 5) 
        digitalWrite(relay, HIGH);  
        ballcount = 0; 


The count will increase as the object passes from the IR sensor. 

Leave a Reply

Your email address will not be published.