Lesson 2: The comparator
Timers & comparatorsIn 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 slidesWhat 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.
+ bigger: output high.
− bigger: output low.
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
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.
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.
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.
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.
The whole circuit
It switches LED1 on when TH1 gets hot. There are five parts. Tap one to see it.
Supply
The +9 V and 0 V rails. Test points T1 and T2 check the supply.
Input divider
TH1 over VR1. Its output is Vin, on the + input (pin 3). It changes with temperature. Test point T3.
Reference divider
R2 over R3. Its output is Vref, on the − input (pin 2). It stays the same. Test point T4.
Comparator
IC1, a 741 op-amp. It compares Vin with Vref. Its power comes from the two rails.
Output
The output drives LED1. R4 protects LED1 by limiting the current. Test point T5.
| Test point | What it measures | What to expect |
|---|---|---|
| T1 | the +9 V rail | about 9 V |
| T2 | the 0 V rail | 0 V |
| T3 | Vin, the + input | changes with temperature |
| T4 | Vref, the − input | about 1.6 V, all the time |
| T5 | the output | close to 9 V when LED1 is on, close to 0 V when off |
LED1 is off. State the voltage you expect at T5.
Answer
You can now…
- find the input divider, the reference divider and the output on the diagram.
- say what each test point measures.
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.
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.
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Ω.
In Threshold Hunter, set VR1 so LED1 comes on at the target temperature, within 1.5 °C. Change the temperature to test it first. Get 4 of 5 on your first try to earn the Threshold Hunter badge.
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.
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
You can now…
- add voltmeters and a logic indicator to a Yenka circuit.
- read a logic indicator: red is high, white is low.
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.
Transistor switch
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
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.
A greenhouse heater must switch on at exactly 12 °C.
State whether a transistor switch or a comparator is better. Give a reason.
Answer
You can now…
- compare a comparator with a transistor switch.
- give a pro and a con of each.
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
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.
Reference voltage
The fixed voltage the input is compared with.
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.