Comparator boards
An MQ-2, a flame sensor, a TCRT5000 and an FC-51, each lighting a lamp from DO with no board. The same LM393 under four sensors, and DO goes low. There is no microcontroller in it: the simulator solves the 12 parts as a circuit, so it runs the moment you press Run, and nothing needs compiling.
Teaching? Assign it to your class in one click.
Beginner About 15 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $9.50. On Mokxi they're free.
What you'll learn
- Open collector outputs that sink current
- Comparators turning an analog sensor into on or off
- Lighting an LED from 5 V into a low output
- Active low signals: low means detected
- Difficulty: Beginner
- Time: About 15 minutes
- Parts: 14
How it works
Four sensor modules sit side by side, each with its own lamp. Under the sensor, every module carries the same comparator chip (an LM393). It checks the sensor against a trimmer setting and drives a digital output pin low when the sensor trips.
That output pin (DO, or OUT on the FC-51) is open collector, so it can pull its own lamp down. Each LED gets 5 V through a 330 ohm resistor, and the other end connects to the module output. When the output goes low, current flows and the lamp lights.
The MQ-2 trips on gas, and also while it warms up. The flame sensor trips on a close flame. The TCRT5000 trips over white, and the FC-51 trips when something is about 13 cm away.
Parts list
14 parts, plus the jumper wires. They retail for about $9.50; on Mokxi they're free.
- 1 × Full-size breadboard
- 1 × Power, 5 V
- 1 × Gas sensor, MQ-2
- 1 × Flame sensor
- 1 × Line sensor, TCRT5000In Robot Car Kit.
- 1 × Obstacle sensor, FC-51
- 1 × LED, redIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
- 4 × Resistor, 330 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × LED, yellowIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
- 1 × LED, greenIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
- 1 × LED, blueIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Gas sensor, MQ-2 pin VCC | 5 V |
| Flame sensor pin VCC | 5 V |
| Line sensor, TCRT5000 pin VCC | 5 V |
| Obstacle sensor, FC-51 pin VCC | 5 V |
| Resistor, 330 Ω (1) pin 2 | 5 V |
| Resistor, 330 Ω (2) pin 2 | 5 V |
| Resistor, 330 Ω (3) pin 2 | 5 V |
| Resistor, 330 Ω (4) pin 2 | 5 V |
| Gas sensor, MQ-2 pin GND | Ground |
| Flame sensor pin GND | Ground |
| Line sensor, TCRT5000 pin GND | Ground |
| Obstacle sensor, FC-51 pin GND | Ground |
| LED, red pin C | Gas sensor, MQ-2 pin DO |
| LED, yellow pin C | Flame sensor pin DO |
| LED, green pin C | Line sensor, TCRT5000 pin DO |
| LED, blue pin C | Obstacle sensor, FC-51 pin OUT |
| Resistor, 330 Ω (1) pin 1 | LED, red pin A |
| Resistor, 330 Ω (2) pin 1 | LED, yellow pin A |
| Resistor, 330 Ω (3) pin 1 | LED, green pin A |
| Resistor, 330 Ω (4) pin 1 | LED, blue pin A |
The notes that come with it
There is no microcontroller in this one, so nothing is compiled: the simulator solves the circuit itself. The file in the editor is the notes that come with it.
// Four comparator boards and four lamps. No board.
//
// Each sensor module is the same LM393 board under a different sensor. DO is
// an open collector: it pulls LOW when the sensor sees something, and it can
// sink a lamp's few milliamps on its own. So each lamp runs from 5 V through
// 330 ohm into a DO pin.
//
// MQ-2 DO low when AO rises past the trimmer: gas, and the warm-up
// flame DO low when a flame is close enough
// TCRT5000 DO low over white, high over the black line
// FC-51 OUT low when something is within about 13 cm
//
// Things to try: watch the MQ-2's lamp go out as it warms up; drag the flame
// in; click the TCRT5000's swatch to swap white for black; bring something up
// to the FC-51.
Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- A lamp never lights, whatever the sensor sees. This project
Check that the LED cathode (C) goes to the module output and the anode (A) goes to the 330 ohm resistor, which runs to 5 V. - The MQ-2 lamp is lit or out at the start and seems wrong. This project
The MQ-2 needs time to warm up, and its lamp changes as it does. Wait a bit before judging it. - A module does nothing at all. This project
Each module needs both VCC to 5 V and GND to ground. Check both pins. - The readings are high and unstable right after power on. Gas sensor
The heater needs time to warm up. Wait a few minutes, and for a fresh sensor preheat for 24 hours or more before trusting values. - The sensor reads wrong or the board drops out. Gas sensor
The heater draws about 150 mA at 5 V, so power it from 5 V with a good supply, and keep it away from breadboard rails that sag. - The sensor triggers all the time or never, even with a flame. Flame sensor
Turn the potentiometer to set the comparator threshold. DO goes low when a flame is detected, so test for LOW. Sunlight and incandescent bulbs also give infrared and cause false triggers. - Digital output is correct but the analog values look backwards. Flame sensor
AO usually falls as the flame gets closer or stronger. Read it with a pull and check VCC and GND pins. Power with 3.3 V to 5 V and match your board's logic level. - It cannot tell black from white. Line sensor
Keep the sensor about 2 mm to 10 mm above the surface. Set the trimmer on the module for the surface you use. Too far gives no change, and too close can saturate the eye.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.