I was thinking of using multiple analog light sensors (variable resistance by light), but basically I only need to know if there is "a lot of light" or "not a lot of light". And would like to use interrupts.

Since I'm using multiple analog inputs, I can't set the ADC module to interrupt on a specific voltage, for each of the (5?) sensors? I'd like to do this withouth using a external comparator.

I've checked the ATMega328p datasheet (going to use Arduino Nano probably).

enter image description here

The fun thing, however, is that on 5V a high signal is >2.6V and a low signal is <2.2V

What does this mean for the grey area? Would my inputs be glitching randomly? Would they maintain high, until below 2.2V and maintain low until above 2.6V? Or can the switching point be any where between that (and is it different per chip or pin?

EDIT: I've checked, my voltage divider circuit has 0.6V for "nothing" and 3V for "interrupted", so it should work neverthless. Though, I'm still interested in how the grey threshold area behaves.

  • Consider adding a differential amplifier like LM741 or LM341 with the sensor input connected to the non-inverting terminal and the inverting input connected to a potentiometer. This is always the best arrangement that I have found that works..when it comes to light sensors. You may adjust the potentiometer to such that the op-amp produces the desired output at the desired conditions. This has also the advantage that you easily adjust the threshold if the lighting conditions change by changing the potentiometer than changing the code.
    – Aswin P J
    Commented Apr 24, 2016 at 17:16

1 Answer 1


The titles of the graphs are actually saying what happens: the hysteresis.

In other words:

  • if the input level is high (greater than 2.6V), it will be considered high through the hysteresis area (until it goes below 2.2V)

  • if the input level is low (below 2.2V), it will be considered low through the hysteresis area (until it goes above 2.6V)

According to the description you gave, this should work for your case. In case it doesn't, you have to condition it until the values you want to consider 0 and 1 are respectively below 2.2V and above 2.6V, with a safety margin, for good measure (say 30%).

The hysteresis is meant to prevent noise from causing unwanted spurious transitions: without safety margin, it should be greater than 0.4V.

You can dimension the safety margin to meet your needs.

But, for the sake of completeness, I'll say that it might be preferable to have a timer to trigger periodic sampling with the ADC.

If you know the maximum frequency at which every input can vary, you can sample it at twice that frequency and be sure that you will not miss anything. Again, this is theory, I would probably make it 4 times, to allow for unforeseen variations.

This works as long as the conversion time of the ADC is shorter than the maximum combined frequency at which you need to read the values.

The GPIOs, of course, are faster, but might require additional circuitry for the conditioning I mentioned earlier.

  • Good, I was worried the input might go random when it's on 2.4V. But you're saying the 2.4V will leave it in the current state, only if it goes higher as 2.6V or lower as 2.2V it will cause a "transition". So one could say that the grey area is "stable".
    – aaa
    Commented Apr 24, 2016 at 9:01
  • After setting my voltage divider right, I've got a 0.6V for low and 3V for high. I might shift it a little higher, but that would indeed work, withouth having to worry about the "grey area", but it's good to know what the values in the datasheet mean.
    – aaa
    Commented Apr 24, 2016 at 9:03
  • 1
    It is designed exactly for that purpose, to increase the resilience of the circuit to noise and variation in components (think of the tolerances in the industrial manufacturing processes) and environments where they operate. Commented Apr 24, 2016 at 9:03
  • The challenge modern electronics face is that the physical world is not really changing, while the circuits are becoming low power (lower max voltage). So the 0 and 1 thresholds are getting closer: just compare an "old school" 5V circuit with Arduino, with a modern SoC that has Vdd=1.8V. The entire range of the modern circuit is smaller than the range allowed for logic 0 on the Arduino! Commented Apr 24, 2016 at 9:07
  • 1
    This is now digressing, but on long lines you do not usually put normal signal, you want to have something that has better S/N ratio. Example: differential signals used in old telephone lines. For modern, more complex cases, one uses complex modulations (that's what a DSL modem does, for example.) As reference, check out this: en.wikipedia.org/wiki/Phase-shift_keying Commented Apr 24, 2016 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.