I Need help in another project : i am using LDR and arduino uno and 2 relay module when LDR detects low light it trigger the relay my problem is when slight change in LDR value the relay gets flickering like fast on/ off how to get steady on or steady off ?? the relay module pin is connected to pin 12 on arduino uno... i am using the code below ..
I have checked all values that mach but new success .. i need the output as on or off not fluctuating if so the relay also fluctuates and make flickering or chirping sound ..any idea ?
Hey !! seadanzig You given the perfect answer what i am looking for now my Relay project is perfectly does what i need you genius.. and i have added the delay for the ON state of relay also for 10 Secs... by the way i am now using following revised code .. thanks for perfect solution thanks ... bye.
------------------------------------------code from here -------------------------------------------------------------------------------------------------
void setup() {
//pinMode(4, OUTPUT);
pinMode(12, OUTPUT); //Serial.begin(9600);
}
ganeshkubade:
Hi , Klaus_ww please tell me some information about hysteresis its new concept for me thanks.
Hysteresis is where there is a dead band in your logic, for instance you could switch on at a reading of 590 and switch off at say 610 giving a dead band of +-10. Your original code could be rewritten as follows:
int reading;
int deadband = 10;
int setpoint = 600;
reading = analogRead(0);
if(reading < (setpoint - deadband)){
digitalWrite(12, LOW);
} else if(reading > (setpoint + deadband)){
digitalWrite(12, HIGH);
}