Skip to content
If this is your first visit, please click here to learn about shipping and delivery.
If this is your first visit, please touch here to learn about shipping and delivery.
LM311 comparator integrated circuit in a dual in-line package

Build a Stable Sensor Threshold with a Comparator: Pull-Ups, Hysteresis and First Tests

A sensor that produces an analogue voltage often needs a simple decision: above or below a limit. A comparator can make that decision without repeatedly reading an ADC in software. It is useful for light-level indicators, threshold alarms and event detection, provided the electrical range and switching behaviour are designed deliberately.

The common frustration is a circuit that works when the sensor is far from the threshold but chatters as the reading approaches it. Another is an output that never goes high. These symptoms usually point to two practical topics: hysteresis and the output connection.

Write the switching requirement first

Describe the wanted behaviour in terms of sensor voltage. For example, an indicator might activate when the voltage rises above 2.10 V and remain active until it falls below 1.90 V. Between those limits it retains its previous state. These are illustrative thresholds, not a claim about any particular sensor.

Also decide what should happen at power-up, after a disconnected sensor and when the supply is outside its normal range. A simple comparator does not automatically give a useful output during every startup condition. If the result controls equipment rather than an indicator, the surrounding system must define its inactive and fault states.

PMD Way’s LM311/UA311 comparator IC listing provides a familiar discrete example. Confirm the manufacturer, suffix and package of the actual device before using a datasheet or footprint.

Keep both inputs inside their permitted range

A comparator compares two voltages, but its inputs still have operating limits. The difference between the inputs can be small while both sit outside the valid common-mode range. That is a different problem from exceeding an absolute maximum rating.

For example, TI’s LM311 datasheet gives a recommended input range from VCC− plus 0.5 V to VCC+ minus 1.5 V under its stated supply conditions. On a 0 V/5 V supply, that means 0.5 V to 3.5 V. It is not a rail-to-rail input device. Check the actual manufacturer’s limits.

Include the sensor’s complete range, the reference range and any startup excursions in this check. A divider can scale a voltage, but its resistance also interacts with input bias current and the sensor’s output impedance. If the required input range does not fit, select a more suitable comparator or redesign the signal conditioning.

Recognise an open-collector output

The LM311 exposes separate output collector and emitter connections. In a conventional ground-referenced open-collector arrangement, the output can pull low but needs an external pull-up to produce a high level. Follow its pinout and the documented treatment of balance/strobe pins; grounding the strobe can disable the output.

A pull-up is selected for the receiving logic voltage, allowed output current and required rise time. A lower resistance gives more current when low and can charge wiring capacitance faster; a higher resistance reduces that current but may make transitions slower. Check the comparator’s output limits and the receiver’s high/low thresholds together.

As a rough current calculation, a 10 kΩ pull-up to 3.3 V draws about 0.33 mA when the output is near ground. This is an arithmetic example, not a universal resistor recommendation. Additional loads and the actual low-state voltage must be included in a finished design.

Do not assume that powering a comparator from one rail makes every connected microcontroller pin tolerant of that rail. Check output pull-up voltage, shared reference and power sequencing before joining the circuits.

Add a deliberate gap between switch-on and switch-off

A single ideal threshold changes state whenever the input crosses it. Real sensor signals contain noise, and slowly changing signals can cross the same boundary repeatedly. Hysteresis creates separate rising and falling thresholds so small fluctuations do not repeatedly reverse the decision.

Analog Devices’ explanation of comparator hysteresis describes this behaviour and positive feedback. In the illustrative 2.10 V/1.90 V requirement, the hysteresis width is 0.20 V. Choose that width from the expected noise and acceptable switching uncertainty rather than an arbitrary favourite resistor value.

Feedback changes the reference according to the output state. Its effect depends on the reference divider, feedback resistance, sensor impedance and actual output levels. With an open-collector device, the pull-up also affects the high-state network.

TI’s comparator-with-hysteresis reference design includes an open-collector modification and explains why a design calculated for a push-pull output needs attention when adapted. Use the appropriate equations or simulation for your topology, then calculate both thresholds separately.

Build a controlled test before connecting the sensor

Use an adjustable low-voltage source or a suitable potentiometer divider to represent the sensor. Restrict its range so neither comparator input leaves the permitted operating region. This makes it easier to separate a circuit fault from a sensor or environmental problem.

  1. Verify the device orientation, supply wiring and output configuration with power removed.
  2. Fit local supply bypassing according to the datasheet and keep input wiring away from the switching output.
  3. Apply power and measure both input voltages before interpreting the output.
  4. Move the simulated sensor voltage slowly upward and record the switching point.
  5. Move it slowly downward and record the return point.
  6. Repeat several times, then connect the actual sensor and repeat under realistic conditions.

Use a meter for the static thresholds and an oscilloscope or appropriate logic instrument when investigating rapid transitions. A steady-looking meter display can hide bursts of output chatter.

Diagnose the symptom in the right order

Comparator symptoms and useful next checks
Symptom Check first
Output never goes high Pull-up, output load, collector/emitter wiring and strobe state
Output remains in one state Actual voltages at both inputs and their permitted range
Repeated transitions near the limit Hysteresis width, noise, reference stability and layout
Threshold differs from calculation Resistor tolerance, output levels, loading and input errors
Works until another module starts Supply disturbance and shared-ground routing

Record measured rising and falling thresholds alongside the chosen resistor values and supply conditions. When selecting from comparator ICs, prioritise the input range, output interface and required decision speed. A dependable threshold circuit comes from defining both switching boundaries and verifying them in the conditions the sensor will actually encounter.

Previous article Battery Power for Arduino Projects: Voltage Range, Runtime and Regulator Heat