Bidirectional Visitor Counter Project with Arduino UNO



Code

#include<LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);

#define in 8
#define out 9
#define fan 10

int count=0;

void setup()
{
  lcd.begin(16,2);
  lcd.print("Visitor Counter");
  delay(2000);
  pinMode(in, INPUT);
  pinMode(out, INPUT);
  pinMode(fan, OUTPUT);
  lcd.clear();
  lcd.print("Person In Room:");
  lcd.setCursor(0,1);
  lcd.print(count);
}

void loop()
{  

  int in_value = digitalRead(in);
  int out_value = digitalRead(out);

  if(in_value == LOW)
  {
    count++;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
  }

  if(out_value == LOW)
  {
    count--;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
  }


  if(count==0)
  {
    lcd.clear();
    digitalWrite(fan, LOW);
    lcd.clear();
    lcd.print("Nobody In Room");
    lcd.setCursor(0,1);
    lcd.print("Fan is Off");
    delay(200);
  }

  else
  {
    digitalWrite(fan, HIGH);
  }
}

  




Comments

  1. Count is fluctuating between 1 and 0 initially.

    ReplyDelete
    Replies
    1. yes, i also faced the same pblm

      Delete

    2. #include
      LiquidCrystal lcd(12,11,5,4,3,2);

      #define in 8
      #define out 9
      #define relay 10

      int count=0;

      void IN()
      {
      count++;
      lcd.clear();
      lcd.print("Person In Room:");
      lcd.setCursor(0,1);
      lcd.print(count);
      delay(1000);
      }

      void OUT()
      {
      count--;
      lcd.clear();
      lcd.print("Person In Room:");
      lcd.setCursor(0,1);
      lcd.print(count);
      delay(1000);
      }

      void setup()
      {
      lcd.begin(16,2);
      lcd.print("Visitor Counter");
      delay(2000);
      pinMode(in, INPUT);
      pinMode(out, INPUT);
      pinMode(relay, OUTPUT);
      lcd.clear();
      lcd.print("Person In Room:");
      lcd.setCursor(0,1);
      lcd.print(count);
      }

      void loop()
      {

      if(digitalRead(in)){
      IN();}
      if(digitalRead(out)){
      OUT();}

      if(count<=0)
      {
      lcd.clear();
      digitalWrite(relay, LOW);
      lcd.clear();
      lcd.print("Nobody In Room");
      lcd.setCursor(0,1);
      lcd.print("Light Is Off");
      delay(200);
      }

      else
      digitalWrite(relay, HIGH);

      }

      Delete
  2. Hey!
    What is the total approximate cost of this project
    I'm thinking of making it for my college

    ReplyDelete
  3. Good Job, thanks for sharing code

    ReplyDelete
    Replies
    1. this is correct code




      #include
      LiquidCrystal lcd(12,11,5,4,3,2);

      #define in 8
      #define out 9
      #define relay 10

      int count=0;

      void IN()
      {
      count++;
      lcd.clear();
      lcd.print("Person In Room:");
      lcd.setCursor(0,1);
      lcd.print(count);
      delay(1000);
      }

      void OUT()
      {
      count--;
      lcd.clear();
      lcd.print("Person In Room:");
      lcd.setCursor(0,1);
      lcd.print(count);
      delay(1000);
      }

      void setup()
      {
      lcd.begin(16,2);
      lcd.print("Visitor Counter");
      delay(2000);
      pinMode(in, INPUT);
      pinMode(out, INPUT);
      pinMode(relay, OUTPUT);
      lcd.clear();
      lcd.print("Person In Room:");
      lcd.setCursor(0,1);
      lcd.print(count);
      }

      void loop()
      {

      if(digitalRead(in)){
      IN();}
      if(digitalRead(out)){
      OUT();}

      if(count<=0)
      {
      lcd.clear();
      digitalWrite(relay, LOW);
      lcd.clear();
      lcd.print("Nobody In Room");
      lcd.setCursor(0,1);
      lcd.print("Light Is Off");
      delay(200);
      }

      else
      digitalWrite(relay, HIGH);

      }

      Delete

  4. #include
    LiquidCrystal lcd(12,11,5,4,3,2);

    #define in 8
    #define out 9
    #define relay 10

    int count=0;

    void IN()
    {
    count++;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
    }

    void OUT()
    {
    count--;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
    }

    void setup()
    {
    lcd.begin(16,2);
    lcd.print("Visitor Counter");
    delay(2000);
    pinMode(in, INPUT);
    pinMode(out, INPUT);
    pinMode(relay, OUTPUT);
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    }

    void loop()
    {

    if(digitalRead(in)){
    IN();}
    if(digitalRead(out)){
    OUT();}

    if(count<=0)
    {
    lcd.clear();
    digitalWrite(relay, LOW);
    lcd.clear();
    lcd.print("Nobody In Room");
    lcd.setCursor(0,1);
    lcd.print("Light Is Off");
    delay(200);
    }

    else
    digitalWrite(relay, HIGH);

    }

    ReplyDelete
  5. Bro here we are useing fan not light with relay and pin layout is also different

    ReplyDelete
  6. Code wrong hai ☺️ please help me

    ReplyDelete

Post a Comment

Popular

How to Make Call, Send and Receive Message using GSM Module

How to interface Ultrasonic sensor with Arduino UNO (Arduino Series - Part 05)