# digitalWrite Takes along time to change state to low

**URL:** <https://forum.arduino.cc/t/digitalwrite-takes-along-time-to-change-state-to-low/67957>\
**Category:** Programming\
**Created:** [August 4, 2011, 3:32pm UTC](https://forum.arduino.cc/t/digitalwrite-takes-along-time-to-change-state-to-low/67957 "2011-08-04T15:32:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon65329010](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@anon65329010](https://forum.arduino.cc/u/anon65329010)\
**Post date:** [August 4, 2011, 3:32pm UTC](https://forum.arduino.cc/t/digitalwrite-takes-along-time-to-change-state-to-low/67957/1 "2011-08-04T15:32:48Z")

</div>

**code**

```cpp
int AlarmWarningLedPin = 7;
int AlarmTriggerOnOff = 4;
int Power = 12;
int AlarmState = 0;

void setup(){
  pinMode(AlarmWarningLedPin, OUTPUT);
  pinMode(AlarmTriggerOnOff, INPUT);
  pinMode(Power, OUTPUT);
  Serial.begin(9600);
  digitalWrite(Power, HIGH);//POWER
}

void loop(){
  AlarmState = digitalRead(AlarmTriggerOnOff);
  if(AlarmState == HIGH){   
        digitalWrite(AlarmWarningLedPin, HIGH);   // sets the LED on to astable to flash 
  }else{
     digitalWrite(AlarmWarningLedPin, LOW);
  }
}

```

**Problem**  
As the title says

I pull pin 4 up high the led turns on straight ways but when i come to take the high off pin 4 (pull down to 0V) the led takes a good time to turn off :~

**Out Come**  
it is even wierder as if i keep the led on for  
LED on for 1 second it takes 6 seconds to turn off  
LED on for 5 second it takes 10 seconds to turn off  
LED on for 20 second it takes 18 seconds to turn off  
LED on for 40 second it takes 20 seconds to turn off  
LED on for 60 second it takes 18 seconds to turn off

They are very rough values but you get the point there is no real pattern

**What i want really**  
I really just want to the led to trun off ALOT quicker that like 20 seconds later LOL

Thanks alot every one  
I have looked around for an ans but can find one any where

if you dont under stand me please say so and ill upload a video of the outcome Thanks 😝

---

<div class="post-metadata">

**Author:** ![retrolefty](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@retrolefty](https://forum.arduino.cc/u/retrolefty)\
**Post date:** [August 4, 2011, 3:48pm UTC](https://forum.arduino.cc/t/digitalwrite-takes-along-time-to-change-state-to-low/67957/2 "2011-08-04T15:48:01Z")

</div>

What is wired to pin 4, a push button? If so you probably are fighting a floating input when you release the button. What is required in that case is to wire a pull-down resistor from pin 4 to ground, then when you release the switch button the resistor will supply a clean logic low electrical value. A 1k to 20k ohm resistor will work fine.

Lefty

---

<div class="post-metadata">

**Author:** ![MarkT](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@MarkT](https://forum.arduino.cc/u/MarkT)\
**Post date:** [August 4, 2011, 4:49pm UTC](https://forum.arduino.cc/t/digitalwrite-takes-along-time-to-change-state-to-low/67957/3 "2011-08-04T16:49:55Z")

</div>

To a first approximation the input resistance of an Arduino pin (when pinMode set to INPUT) is _infinity_.... That means if nothing is connected to it the voltage stays put - this is why its taking long times to switch off and why you must always have a pullup or pulldown for a push-button circuit.

In reality the input resistance may be something like a million million ohms...

---

<div class="post-metadata">

**Author:** ![anon65329010](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@anon65329010](https://forum.arduino.cc/u/anon65329010)\
**Post date:** [August 4, 2011, 4:51pm UTC](https://forum.arduino.cc/t/digitalwrite-takes-along-time-to-change-state-to-low/67957/4 "2011-08-04T16:51:06Z")

</div>

Man u got it WOW both of you thanks for the exsplanation  
how stupid of me lol i was so exsited i just dived in lol uno just arrived this morning  
i truely did not think that leaving the pin flowing would make a difference as i am quering if it is high

any ways thanks alot 😛

---

<div class="post-metadata">

**Author:** ![MarkT](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@MarkT](https://forum.arduino.cc/u/MarkT)\
**Post date:** [August 4, 2011, 4:53pm UTC](https://forum.arduino.cc/t/digitalwrite-takes-along-time-to-change-state-to-low/67957/5 "2011-08-04T16:53:53Z")

</div>

Incidentally this was never a problem with old TTL logic which pulled high by default. (But CMOS is so much better these days, faster, less power, less noise sensitive)

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [August 4, 2011, 7:06pm UTC](https://forum.arduino.cc/t/digitalwrite-takes-along-time-to-change-state-to-low/67957/6 "2011-08-04T19:06:05Z")

</div>

The Arduino has built-in pull-up resistors you can enable:

```cpp
const int AlarmTriggerOnOff = 4;

void setup(){
  pinMode(AlarmTriggerOnOff, INPUT);
  digitalWrite(AlarmTriggerOnOff, HIGH);  // Enable pull-up resistor

```

If you do that the input pin will read HIGH until something (like a button or switch) connects it to Ground.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 4, 2011, 7:11pm UTC](https://forum.arduino.cc/t/digitalwrite-takes-along-time-to-change-state-to-low/67957/7 "2011-08-04T19:11:41Z")

</div>

```cpp
AlarmState = digitalRead(AlarmTriggerOnOff);
  if(AlarmState == HIGH){   
        digitalWrite(AlarmWarningLedPin, HIGH);  // sets the LED on to astable to flash 
  }else{
    digitalWrite(AlarmWarningLedPin, LOW);
  }

```

Do PHP coders get paid by LOCs?

```cpp
 digitalWrite(AlarmWarningLedPin, digitalRead(AlarmTriggerOnOff));

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 7:34pm UTC](https://forum.arduino.cc/t/digitalwrite-takes-along-time-to-change-state-to-low/67957/8 "2021-05-05T19:34:26Z")

</div>


