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
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.
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...
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
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)
AlarmState = digitalRead(AlarmTriggerOnOff);
if(AlarmState == HIGH){
digitalWrite(AlarmWarningLedPin, HIGH); // sets the LED on to astable to flash
}else{
digitalWrite(AlarmWarningLedPin, LOW);
}