Need help with LDR controlling LED

Hi, I'm very new to programming and arduino. i am trying to make a led turn on when the LDR is covered(dark) and off when uncovered. I am using a potentiometer to control the threshold but the led flicker's when very close to this theshold. I've been googling and there is something called hysteresis to stop this but there is no explaination of what this is anywhere.

any help would be appreciated.

meado87

Hysteresis in this context can be used to modify the decision statement in your program for when the LED should be turned off or on. With no hysteresis the decision would be based on a specific value of a analog input value being read. If the decision point was at say 50% of range, any reading at or above 50% of input range would turn the LED off and any reading below 50% would turn it on.

The problem in the real world is that normal variation in signal noise, etc will often cause a reading to wander around a given value by a few counts, so if the reading is right at the decision point, 50%, it will often cause the decision to change state and oscillate with each cycle of the decision loop, causing the LED to appear to dim or blink. Hysteresis gives the concept of a 'gap' decision where one might state that the LED should be turned off when the the analog read value is 55% or higher and turned off at 50% or lower, any reading from 51-54 should result in no change from the present state. This range of no change in a 4% range may have to be increased depending on the amount of variation or noise in the measurement system.

That make sense?

that does make sense. thanks

is this done by doing calculations in the code? e.g.

(value/100)*10 for say 10% either side of the threshold

or is there specific code to use?

meado87

It's done in your program, with your decision steps by anyway you wish to implement it, no built in functions.

Lefty