0

I make an automatic light that's triggered from a Visitor Counter. I use an LCD to show the actual counter state. The LCD does not anly show the actual count but also the numbers before. For Example:

If the counter is actual 2, it blinks between 1 and 2.

This behavior does not occur in the original project where the correct number is shown.

Please, can I know why, and how to fix it? Thank you!

My Setup

This is the code:

//Visitors Counter and Automatic Room Light
//Viral Science  www.youtube.com/c/viralscience

#include<LiquidCrystal.h>
LiquidCrystal lcd(13,12,11,10,9,8);

#define in 14
#define out 19
#define relay 2

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);

}
  • What is the actual program? What is the difference between the actual and your program? What is the code anyway? And do you mean by blinking it shows alternately 1 and 2? To fix it, probably you have to change the code, or the circuit, but high likely the code. But this 'answer' is as vague as your question I'm afraid. – Michel Keijzers Nov 29 '19 at 10:36
  • Yes sir @Michel Keijzers it keep blinking and shows alternately 1 and 2 . I will try compile a new coding and see what happen . Thank you sir ! – Afiq Nov 29 '19 at 11:03
  • Please add the code ( that is not working ) to the question. You asked why the code does not work and how to fix it. To answer we must know it. Simply, writing new code seems not to be the best strategy. Perhaps it works, but then you don't know why the first code did not. Or it does not work; what will you do then? Please do not report that your second code does also nor work, without showing it here. We can not guess what you have programmed so far. – Peter Paul Kiefer Nov 29 '19 at 12:34
  • I suggested to change the text and the title of the question as I edited it. If I understood it correctly, please accept die update. It hopefully make the question more understandable. (Although my English is bad.) I have not access to your code, so it remains to you to add it to make the question a lot more understandable. – Peter Paul Kiefer Nov 29 '19 at 12:37
  • No, please do not add the code to a comment. Just edit your question and add it at the end of your question. Then mark the code completely and press the {} button of the online editor. You'll get well formatted code. You have not enough space in a comment. And the code should be part of the question. – Peter Paul Kiefer Nov 29 '19 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.