Object counter

Object counter using ir sensor with arduino uno

Source code for Arduino 

Ir Sensor based object counter 

//@BigEdx youtube channel for electrical and electronics project.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

int input = 7;
int n     = 0;
int state = 0;

LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
  lcd.init(); // initialize the lcd

  // Print message to the LCD
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print(" Objects counting ");
  lcd.setCursor(0, 1);
  lcd.print(n);
  lcd.print("     = Units ");
}
void loop()
{
  int counter = digitalRead(7);
  if (state == 0)
  {
switch (counter) {
case 1 : state = 1;
lcd.setCursor (0, 1); n = n + 1; lcd.print(n); break;
case 0 : state = 0; break;

  }
   }

  if (counter == LOW) {
    state = 0;
  }
}


Post a Comment (0)
Previous Post Next Post