I am trying to make a speed monitoring system. I want to monitor motor RPM with an IR phototransistor sensor.

I am getting analog values and negative peaks when a sensor flashes on a reflective sticker:
enter image description here

I am capturing these peaks to count revolutions and with revolutions I can get RPMs, but reading raw ADC data and finding lowest point is not a good solution, so I am searching for a circuit to convert this signal into a single digital signal.

Capturing fronts with interrupts would be a way better solution, but I don't know how to convert this analog signal to digital.

I could use an AND gate which I have, but my signal would fall into the uncertain region of AND gate input levels.

Is there a simple circuit using transistors which would capture these peaks as a digital 0?

  • \$\begingroup\$ Op-amp "comparator" is the usual solution here. \$\endgroup\$
    – pjc50
    Commented Jul 5, 2023 at 8:40
  • \$\begingroup\$ @pjc50 Op-amps are poor comparators. The usual solution is to actually use a comparator instead of an op-amp. \$\endgroup\$
    – Justme
    Commented Jul 5, 2023 at 9:44

2 Answers 2


Usually this job is performed by a comparator, such as the LM393. If you have a 5V supply, for example, and your input signal can have any potential between 0V and 5V, then you must provide a "reference" potential for the comparator to compare against, to produce a digital high (+5V) or low (0V) output depending on which is higher, the reference or the input signal. This might be your circuit:


simulate this circuit – Schematic created using CircuitLab

Here I use R2 and R3 as a resistor potential divider to produce about +3.4V at node REF. This is the potential that the comparator treats as the switching threshold. When the input at IN rises above +3.4V, the comparator output goes high to +5V (with the help of R1, necessary due to the comparator's open-collector output). When the input potential falls below +3.4V, that output goes low.

C1 is optional, but recommended, to help keep REF steady in spite of power supply noise.

To find values for R2 and R3, use the following formula for the potential at REF:

$$ V_{REF} = V_{SUPPLY}\frac{R_3}{R_2+R_3} $$

In the above example this is:

$$ V_{REF} = +5V \times \frac{22k\Omega}{10k\Omega + 22k\Omega} = +3.4V $$

Comparators usually have some input hysteresis built in (a millivolt or so), which prevents the output from ever settling in between high and low, like an analogue amplifier might do, increase noise immunity, and to increase the transition speed of the output. It is this hysteresis which defines the comparator's output as "digital" in nature. Without hysteresis, it would be nothing more than a very high gain op-amp.

Hysteresis can be produced/increased by adding a small amount of positive feedback, which will be necessary if you use an ordinary op-amp in the role of comparator. Here I use the OPA990, with (exaggerated) positive feedback to produce similar behaviour to a real comparator:


simulate this circuit

R4 and R5 provide the positive feedback I mentioned, causing the switching threshold to shift depending on the current output state. This is what we call hysteresis. The two switching thresholds can be seen below, marked in green. The input is a sinusoid (but it could be any signal you care to provide), in blue, and the output is a clear digital +5V or 0V, in orange:

enter image description here

The hysteresis "gap" can be reduced by increasing R5, and vice versa. This technique would also work with a proper comparator, if you required more input hysteresis than the tiny amount already present.


A comparator will do this. Some examples from TI.

Connect your signal to the positive input and a threshold voltage to the negative input. The output will be a digital 1 if your signal is higher than the threshold voltage and a digital 0 if it is lower.

You can generate the threshold voltage from the midpoint of a potentiometer or a fixed voltage divider.

  • \$\begingroup\$ Could I use regular OP AMP ? I have this lying around OPA990SIDBVR. \$\endgroup\$
    – Dominykas
    Commented Jul 5, 2023 at 9:19
  • \$\begingroup\$ @Dominykas The OPA990 can be used as a comparator (it allows high differential voltages), but it will not be a good one. \$\endgroup\$
    – CL.
    Commented Jul 5, 2023 at 12:51

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.