So I have connected a CNY70 photo sensor and a resistor to a LM339N comparator.
Whenever the voltage across the CNY70 exceeds the voltage across the resistor, the comparator sends out a HIGH, else a LOW.
The problem that I'm having is, that when I move VERY SLOWLY (but constantly in one and the same direction) over the threshold voltage, I get lots of alternating HIGHs and LOWs ...
Is this bouncing? How can I avoid this without using delays ???
You need a divider to set the reference voltage, like this:
R2/R3 set the reference point, and the much larger resistor R4 provides a bit of hysteresis.
Note that a comparator, like any other logic chip, requires 100nF ceramic decoupling capacitor right
close to the supply pin.
A stiff pullup of a few k ohms provides faster response than built-in pullups should this matter
(normally it won't and internal pullup is sufficient, but note that its only the pullup that drives
the feedback - Rpullup is a good idea so you can test the circuit without the Arduino connected)
Almost all comparators have open-collector/open-drain outputs, so they can be paralleled for
the window comparator circuit (and so they can have different supply voltage), hence the need for pullups on the outputs.
The CNY70 is represented by the photocell and the LM339N comparator is represented by the L293D IC, as I didn't find the correct parts in the Fritzing app.
So, in my project, the 2 potentiometer set 2 reference voltages (e.g. 500 Volt for potentiometer at the top, which is connected to negative input 1 and 1500 Volt for potentiometer at the bottom, which is connected to negative input 2). The CNY70 connects to pos. input 1 and pos input 2. Output 1 of the comparator then goes to digital pin 2 and output 3 goes to pin 3.
The problem: Too many consecutive starts and finishes.... I need only 1 of each, whenever I pass the thresholds!
And I don't want to use delays to achieve this!