Lesson 2: The comparator

Timers & comparators

In this lesson

  • Say when a comparator's output is high.
  • Calculate a voltage from a divider.
  • Describe how a thermistor comparator works.
  • Test a comparator in Yenka.
  • Compare a comparator with a transistor switch.

Booklet and slides

Lesson 2 is the second lesson in the booklet. Your tasks and exam questions are there.

Block 6 booklet (PDF) Lesson slides
Concept 1

What a comparator does

Key words

Comparator
compares two voltages and switches its output.
Op-amp
the chip used as a comparator. Ours is the 741.
+ input
pin 3. Also called the non-inverting input.
− input
pin 2. Also called the inverting input.

A comparator has two inputs. It looks at which input has the bigger voltage.

  • The + input is bigger: the output is high, close to +9 V.
  • The − input is bigger: the output is low, close to 0 V.

The output has only these two states. It switches from one to the other. It is a digital output.

Pin 7 goes to +9 V and pin 4 to 0 V. These power the chip.

−+ 741 − input+ input 23 6 74 +9 V0 V output
The 741 op-amp. Pin numbers in green.
−+ 2.0 V3.0 V HIGH

+ bigger: output high.

−+ 2.0 V1.0 V LOW

− bigger: output low.

Practice 1

A comparator has these input voltages:

  • + input = 4.5 V
  • − input = 5.0 V

State whether the output is high or low. Give a reason.

Answer
Low. The − input is bigger than the + input.

You can now…

  • name the + input, the − input and the output of a 741.
  • say when the output is high and when it is low.
Concept 2

Two voltage dividers

Key words

Voltage divider
two resistors that share the supply voltage.
Thermistor
its resistance falls as it warms up.
Vin
the input voltage. It changes with temperature.
Vref
the reference voltage. It stays the same. Exam papers may call it Vx.

Each input of the comparator comes from a voltage divider.

  • TH1 over VR1 makes Vin. It goes to the + input.
  • R2 over R3 makes Vref. It goes to the − input.

In a divider, the bigger resistor gets the bigger share of the supply.

When TH1 warms up, its resistance falls. VR1 now gets a bigger share. So Vin rises.

R2 and R3 are fixed. So Vref stays the same.

+9 V0 V TH1VR1 Vinto + R210 k R32.2 k Vrefto −
The input divider (left) and the reference divider (right).
Voltage across the bottom resistor
V2 = R2R1 + R2 × Vs
R1 = top resistor (Ω) · R2 = bottom resistor (Ω) · Vs = supply voltage (V) · V2 = voltage across the bottom resistor (V)
Worked example A reference divider has 10 kΩ on top and 5.0 kΩ below. The supply is 12 V. Calculate Vref.
Vref=R2R1 + R2 × Vs
Vref=(5.0 ÷ (10 + 5.0)) × 12both in kΩ, so no need to convert
Vref=4.0 V
Practice 2

An input divider is on a 9.0 V supply:

  • TH1 (top) = 6.0 kΩ
  • VR1 (bottom) = 3.0 kΩ

(a) Calculate Vin.

(b) State whether the output is high or low when Vref = 1.6 V.

Answer

(a) Vin = (3.0 ÷ (6.0 + 3.0)) × 9.0 = 3.0 V

(b) High. Vin (3.0 V) is bigger than Vref (1.6 V).

You can now…

  • calculate the voltage from a divider.
  • say why Vin rises as TH1 warms up.
Concept 3

Read the circuit diagram

This is the circuit in your booklet. Tap each part to see what it does.

The whole circuit

It switches LED1 on when TH1 gets hot. There are five parts. Tap one to see it.

+9 V0 V T1T2 TH1 VR110 k Vin T3 R210 k R32.2 k Vref T4 −+ IC1741 R4680 LED1 T5 25 °C 10.0 kΩ 2.00 kΩ 0 V 1.62 V logic indicator 0 V
The booklet circuit, with test points T1 to T5.
Test pointWhat it measuresWhat to expect
T1the +9 V railabout 9 V
T2the 0 V rail0 V
T3Vin, the + inputchanges with temperature
T4Vref, the − inputabout 1.6 V, all the time
T5the outputclose to 9 V when LED1 is on, close to 0 V when off
Practice 3

LED1 is off. State the voltage you expect at T5.

Answer
Close to 0 V. The output is low, so LED1 is off.

You can now…

  • find the input divider, the reference divider and the output on the diagram.
  • say what each test point measures.
Concept 4

How the circuit works

Key words

Variable resistor
a resistor you can adjust. VR1 sets the temperature at which LED1 comes on.
Describe
give the steps in order. Each step is worth one mark.

To describe how it works, follow the chain from the sensor to the output:

  • As the temperature rises, the resistance of TH1 falls.
  • So Vin rises.
  • When Vin is bigger than Vref, the output goes high and LED1 comes on.

VR1 sets the temperature at which this happens. Turn VR1 up: Vin is bigger at every temperature, so LED1 comes on when it is colder.

Temperature rises TH1 resistance falls Vin rises Vin bigger than Vref Output high: LED1 on
Describe it as a chain: one step, one mark.

Another way to build it

Swap TH1 for a fixed resistor, R1. Swap VR1 for an LDR. Now LED1 comes on when it gets dark, like a night light.

The rest of the circuit stays the same.

+9 V0 V R110 k LDR Vinto +
The night-light version: R1 over an LDR.
Practice 4

Describe how the night-light version switches LED1 on as it gets dark. (3)

Answer
  • As it gets darker, the resistance of the LDR rises (1).
  • So Vin rises (1).
  • When Vin is bigger than Vref, the output goes high and LED1 comes on (1).

You can now…

  • describe how the circuit works, one step for each mark.
  • say what VR1 does.

Comparator bench

The booklet circuit, live

Change the temperature and VR1. Watch Vin, Vref and the logic indicator.

Predict when LED1 comes on if VR1 is turned up from 2 kΩ to 5 kΩ.

Logic indicator: red = high, white = low, as in Yenka.
TH1 resistance–
Vin (T3)–
Vref (T4)–
Output (T5)–
LED1 comes on at–
Where the lines cross, LED1 switches.

Concept 5

Test it in Yenka

Key words

Voltmeter
measures the voltage at a point. Connect it from the point to 0 V.
Logic indicator
shows the logic level. In Yenka, red = high and white = low.

In Yenka you can't touch a test point with a probe. Add meters to the circuit instead.

  • A voltmeter on Vin (where T3 is).
  • A voltmeter on Vref (where T4 is).
  • A logic indicator on the output (where T5 is).

Change the temperature of TH1. Vref should not move. Vin should rise as it warms. The logic indicator turns red when Vin passes Vref.

+9 V0 V TH1VR1 R2R3 V Vref V Vin −+ IC1741 logic indicator R4LED1
The Yenka set-up: two voltmeters and a logic indicator. Here the indicator is red: the output is high.
Practice 5

In Yenka, the meters read:

  • Vin = 1.2 V
  • Vref = 1.6 V

State the colour of the logic indicator, and whether LED1 is on.

Answer
White, and LED1 is off. Vin is smaller than Vref, so the output is low.

You can now…

  • add voltmeters and a logic indicator to a Yenka circuit.
  • read a logic indicator: red is high, white is low.
Concept 6

Comparator or transistor switch?

Key words

Transistor switch
a divider feeds the base of a transistor. It turns on when the base reaches about 0.7 V.
Switching point
the temperature (or light level) at which the output comes on.

A transistor switch can do the same job. The same divider, TH1 over VR1, feeds the base of transistor TR1 through a base resistor.

As TH1 warms up, the base voltage rises. At about 0.7 V, TR1 turns on and LED1 lights.

So the transistor always switches at about 0.7 V. The comparator switches at Vref, a voltage you choose.

See Transistor switching circuits for more.

+9 V0 V TH1VR1 base resistor turns on atabout 0.7 V TR1 R4 680LED1
The same job done by a transistor switch.

Transistor switch

LED brightnesstemperature

Pros

  • Fewer parts, so it is cheaper and simpler to build.
  • It can switch a bigger current, such as a relay.

Cons

  • It turns on gradually. LED1 can glow dimly near the switching point.
  • It always switches at about 0.7 V on the base.
  • The switching point drifts as the transistor itself warms up.

Comparator

LED brightnesstemperature

Pros

  • It switches sharply: the output is fully high or fully low.
  • It switches at Vref, any voltage you choose.
  • The switching point is precise and easy to set with VR1.

Cons

  • More parts: an IC and a reference divider. It costs more.
  • Its output current is small. It can light an LED, but a relay or motor needs a transistor after it.

Many circuits use both. The comparator decides when to switch. A transistor after it drives the big load.

Practice 6

A greenhouse heater must switch on at exactly 12 °C.

State whether a transistor switch or a comparator is better. Give a reason.

Answer
A comparator. It switches sharply at a set point, and VR1 lets you set that point precisely. (The heater itself would need a transistor or relay after the comparator.)

You can now…

  • compare a comparator with a transistor switch.
  • give a pro and a con of each.
Check

Check your understanding

Pick an answer to see feedback on it. You can then try the others. Your score counts first tries only.

Fill the gaps

The output of a comparator is when the + input is bigger than the − input. Vref comes from . As TH1 warms up, Vin . In Yenka, a white logic indicator means .

RAG self-check

Tap Red, Amber or Green for how sure you feel.

Booklet answers: Lesson 2

Try the task in your booklet first. Then tap to check.

Task 1: Read the diagram
  • 1. The thermistor, TH1.
  • 2. T3 measures Vin. T4 measures Vref.
  • 3. Vref = (2.2 ÷ (10 + 2.2)) × 9 = 1.6 V (1.62 V).
  • 4. Vin rises.
  • 5. When Vin is bigger than Vref.
Task 2: Yenka build and test

Your numbers depend on how VR1 is set. Check the pattern:

  • Vref stays at about 1.6 V at every temperature.
  • Vin rises as TH1 warms up.
  • Once Vin is bigger than Vref, the logic indicator is red and LED1 is on. Below that, it is white and LED1 is off.
Task 3: Threshold Hunter

At 30 °C, Vin should be just above Vref, about 1.6 V.

Purpose of VR1: it sets the temperature at which LED1 comes on.

Exam question 1: three errors
  • The supply voltage is too small: 9 mV. It should be 9 V.
  • A diode is used, not an LED.
  • The LED's protective resistor is too large: 680 kΩ. ("Resistor too big" on its own is not enough.)
Exam question 2 (2019 Q7)
  • (a) Vx = (4000 ÷ 5000) × 6 = 4.8 V (3 marks: formula, substitution, answer).
  • (b) 20 kΩ. Give the unit.
  • (c) As the temperature falls, the thermistor's resistance rises (1). The voltage across the thermistor rises (1). When it is bigger than Vx, the comparator output switches high and the buzzer sounds (1).
Exam question 3: pre-power-up checks

Any three of:

  • The IC is the right way round.
  • The LED is the right way round.
  • The resistor values are correct (10 kΩ, 330 Ω).
  • The supply is connected the right way round.
  • No short circuit across the supply.
  • The thermistor value is correct.
Key words
1. comparator · 2. divider · 3. reference · 4. high · 5. thermistor · 6. variable resistor

Picture glossary

−+

Comparator

Compares two voltages. Output high when the + input is bigger.

Thermistor

Its resistance falls as it warms up.

Variable resistor

A resistor you can adjust. VR1 sets the switching temperature.

Voltage divider

Two resistors that share the supply. The output is between them.

Vref

Reference voltage

The fixed voltage the input is compared with.

highlow

Logic indicator

In Yenka: red for high, white for low.

Sources & credits: booklet answers to 2019 Q7 follow the National 5 Practical Electronics marking instructions, © Qualifications Scotland (SQA). Text, drawings, simulator and booklet by R Stewart. R Stewart - October 2026.