# Voltage comparator

I have a circuit where I have to read high and low logic level through a micro-controller.

Condition:

• When the input voltage is above 15V, it should be HIGH logic (2V to 5V.)
• When the input voltage is below 12V, it should be LOW logic (0 volt.)

I don't have ADC PIN, so I have to use some external circuit for this. Someone suggested a voltage comparator, but I don't know how.

• How accurate does this need to be? What power supply rail voltages do you have available? Please update your question with this information. Commented Feb 24, 2020 at 5:26
• You use a resistor divider to produce a voltage reference that you feed to either the + or - input of the comparator. Your other signal goes to the remaining input. When a comparator's + input is higher than the - input, it outputs a HI. Can you work out yourself what you need to do from there? Commented Feb 24, 2020 at 5:28
• @DwayneReid there are 3.3v and 5v both power supply available. accuracy 0.5v allowable. Commented Feb 24, 2020 at 9:24
• @DKNguyen thank you for your response. Commented Feb 24, 2020 at 9:26

## 2 Answers

Since you do not have a ADC pin, I assume you have GPIO which cna be configures a input pin. First you have to condition the input signal. You can use a voltage divider to bring down the actual input voltage by 5times. So, the signal from 15 V and 12 V will be brought down to 3 and 2.4 V respectively.

to downconvert the higher 15V to a lower value, you can use voltage divider:

You can put a Schmidt trigger ( the below one is in the inverting configuration) circuit to use. Assuming you have a 3.3 V rail and MCU is also running at 3.3 V, you can make it work.
Example from here:

1. The input might go above 15 V too. in that case, you should clamp the input signal a the GPIO using diodes OR you can use a TVS or a Zener diode.
2. The resistors might be not practical if the signal is fast changing. in that case, you may have to add a buffer circuit.
• Can I use voltage comparator instead of Schmidt trigger ? btw thank you for valuable response. Commented Feb 24, 2020 at 9:29
• Do you mean the internal comparator present in the MCU? Or the external comparator? Can you provide datasheet of the MCU you are using? Commented Feb 24, 2020 at 10:50
• @AaravSoni A Schmitt trigger is just a comparator circuit wired to have hysteresis. That triangle with the + and - is a comparator. R3 going from the output to the + input gives it positive feedback which makes it a comparator with hysteresis, which makes it a Schmitt trigger. Commented Feb 24, 2020 at 18:29

The following is a classic discrete 4-transistor comparator with TTL output. Threshold voltage is about 14V. Q1 and Q2 are not very sensitive to mismatch and thermal drift. D1 and R11 provide hysteresis.

simulate this circuit – Schematic created using CircuitLab

For this fairly low-precision application, we can make a comparator with just 3 transistors:

simulate this circuit

Both circuits will conservatively drive at least 1 TTL input.

Given easy availability of components, these circuits have perhaps one benefit over integrated solutions - if you can't get the parts, the civilization has ended and you don't need to worry about comparators anymore :)