Button reacts very slowly

Hello, its me again. :o

My goal: I want to have a counter on my LCD (HD44780), which goes from 900 down, 1 per second, until I pull a cable, which was configured as input before. (So it takes approx. 15 min, accuracy is not important)

My problem: When I pull the cable it takes like 5 seconds until the Arduino reacts.

My code:

#include <LiquidCrystal.h>
int t1 = 900;

int inPin = 22;

int stopLCD = false;

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

void setup() {
  pinMode(inPin1, INPUT);
  lcd.begin(16, 2);
  lcd.home();
  lcd.print(t1);
}

void loop()
{
  if (digitalRead(inPin1) == HIGH) {
     lcd.home();  
     lcd.print(t1);  
     t1 -= 1;
     delay(1000);
   }
   else {
     if(!stopLCD) {
       lcd.clear();
       stopLCD = true; 
     }
   }
}

Everything is wired correctly, the LCD works great. The Digital input is simply a cable which goes from ground to 5V (via 10k pull-up resistor) and Digital input 22, so when I pull it, it should work as a button (I lack a real button at the moment :slight_smile: ).

Do you have any Idea why this is happening?

Goodbye and Thanks in advance!

     delay(1000);

Slowly, you say?

When I pull the cable it takes like 5 seconds until the Arduino reacts.

Like when you've got a floating input?

Yeah, but not one delay, but like 5 delays...

I know this is kinda bad programming, but at the moment it was the easiest way for me.

If it would react after one delay, that'd be okay for me.

AWOL:     delay(1000);

Slowly, you say? Like when you've got a floating input?

Yes, but the 10k should avoid that, shouldn't it? Do you recommened a debounce?

so when I pull it, it should work as a button …
Do you have any Idea why this is happening?

Yes when you pull the cable there is nothing connected to the input and so it is floating.
You need to keep the pull up resistor when the cable is disconnected, or enable the internal pull up resistor and have your cable connected to ground not 5V.

http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

Grumpy_Mike: Yes when you pull the cable there is nothing connected to the input and so it is floating. You need to keep the pull up resistor when the cable is disconnected, or enable the internal pull up resistor and have your cable connected to ground not 5V.

http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

That makes very much sense. Sorry, my bad. Gotta change the wiring and see if it works!

It works! Decided to use the internal Pull-up though. Great thanks to you all!