Skip to content
MakerBuddy

Week 28 · Term 4 · 45 to 60 minutes

Smart Safety Systems: MQ-2 Gas Alerts

Critical hazard mitigation

Try it first, no kit needed

Smart Safety Systems: MQ-2 Gas Alerts

Week 28 Term 4 45-60 minutes

Learning Objective

Apply everything you have learned about Condition rules and Threshold Windows to build a real-world safety system: a gas leak detector that automatically triggers a multi-stage alarm.

Theory: Designing for Safety

When Code Saves Lives

Safety systems use sensors to watch for danger, like smoke, fire, floods or toxic gas.

A safety system must be reliable. It cannot miss a danger, and it cannot give false alarms every second.

The Gas Sensor (MQ-2)

The MQ-2 is an electronic nose. It reacts to smoke and to gases that burn, like LPG. MakerBuddy shows a relative reading from 0 to 100. Your clean-air reading in your own room is your baseline. Near a suitable test vapor the number should rise, so the rule watches for a value clearly above it.

For Teachers

Discuss Fail-Safe design: if the power fails or a cable is cut, the system should fall back to the safest state, not the easiest one.

Try It: Build a Gas Alarm

Interactive demo · no kit needed

Play with a pretend MakerBuddy board and its web page, right here.

Follow the steps one at a time. Got the kit? You can switch to the real board inside.

Activity: Building the Gas Alarm

Make a gas detector with a threshold window, so it does not alarm all the time.

Step-by-Step Instructions:

  1. Find the Baseline: With the USB cable unplugged, plug the MQ-2 into the connector marked 33. Power up and wait about 3 minutes while its heater warms up. Note the Gas Level (MQ-2) reading in clean air (0 to 100). Do not touch its metal cover: it gets hot.
  2. Set the Danger Zone: Pick a threshold well above your baseline, e.g. 60 for a baseline of 20.
  3. Rule 1 — Alarm: Create a Condition rule named "GasDanger". Sensor → 💨 Gas Level (MQ2), Operator → Greater or equal (>=), Threshold → your danger value. Step 1: Action → 🔊 Buzzer On, Delay (ms) → 100. Step 2: Action → 🔴 RGB Red, Delay (ms) → 100. Save!
  4. Rule 2 — All Clear: Create a Condition rule named "GasClear". Sensor → 💨 Gas Level (MQ2), Operator → Less than (<), Threshold → your clear value. Step 1: Action → 🔇 Buzzer Off, Delay (ms) → 100. Step 2: Action → 🟢 RGB Green, Delay (ms) → 100. Save!
    Leave a gap between the clear and danger values so small changes do not make the alarm flicker. Inside the gap neither rule runs, so the alarm keeps sounding until the air is properly clear.
  5. Test it: In a room with good airflow, your teacher may hold a tissue with a little alcohol-based hand sanitizer 10–15 cm from the sensor. Never use flames, lighters or released fuel gas. Does the alarm sound?
Important: this is a classroom model for learning. It is not a certified smoke, gas or carbon-monoxide alarm, and must never replace one.

Challenge: The Multi-Stage Alert

Early Warning System

Good safety systems warn you before danger. Build a three-stage alert:

Stage 1 — Safe (Gas < 25):   🟢 RGB Green + 🔇 Buzzer Off
Stage 2 — Warning (Gas > 30 AND < 55):   🟡 RGB Yellow + 🔇 Buzzer Off
Stage 3 — Danger (Gas ≥ 60):   🔴 RGB Red + 🔊 Buzzer On

A rule that stops leaves its last step in place, so every quieter stage must switch the buzzer off itself.

Use three separate Condition rules. The Warning rule tests the same MQ-2 twice, so it does not overlap Danger. Adjust all values to your baseline.

Coming Up Next Week:

Week 29: Complex Automation: The Parking Gate (Part 1)

Learning Support

Use this quick guide to help every learner understand, practice and explain Smart Safety Systems: MQ-2 Gas Alerts.

For students

Try it in three steps

  1. Say it: explain the main idea in one simple sentence.
  2. Show it: Build a gas alarm: one Condition rule sounds the buzzer and shows red when Gas Level (MQ2) rises well above your clean-air reading, and a second rule silences it and shows green when the air is clear again.
  3. Stretch it: Build a three-stage early warning: green when safe, yellow in a warning band, and red with the buzzer for danger.

Checkpoint: What was your input, what decision or process happened, and what was the output?

For teachers & parents

Coach without taking over

  • Before: ask the learner to predict what will happen and why.
  • During: use prompts such as “What changed?” and “What could you test next?” instead of giving the answer.
  • After: ask for a 30-second explanation, one piece of evidence and one improvement.

Look for: safe handling, correct vocabulary, a result the learner can demonstrate, and an explanation in their own words.

Safety reminder: Treat this as a model alarm, not a certified life-safety device. Plug the MQ-2 into connector 33 only while the USB cable is unplugged. It gets hot: don't touch its metal cover. Use only a teacher-approved vapor demonstration in a ventilated room, never flames, lighters or fuel gas.

Did you get it?

Three quick questions. Pick an answer to see whether it is right, and why.

  1. 1What should a good safety system avoid doing?

  2. 2Why is there a gap between the gas alarm's danger and all-clear values?

  3. 3In the three-stage alert, why must each quieter stage switch the buzzer off itself?