Skip to content
MakerBuddy

Term 4 · Weeks 25–32

Creating smart automated systems with complex rules, capstone projects and a final expo. Each lesson includes its full classroom material, activity and challenge.

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

Automating a nightlight is fun, but automating safety systems is critical. In factories, hospitals, and homes, sensors are constantly watching for danger — smoke, fire, flooding, or toxic gases.

A safety system must be reliable — it cannot miss a danger, and it cannot give false alarms every second. This is exactly why Condition rules + Threshold Windows are so important!

The Gas Sensor (MQ-2)

The MQ-2 is our "electronic nose". It can detect invisible gases in the air — like LPG, smoke, and combustible gases. In clean air, the sensor reads a low number (around 100–200). As gas concentration rises, the number goes up. We will use the Rule Engine to watch this number and sound the alarm when it gets dangerously high.

For Teachers

This is an excellent time to discuss "Fail-Safe" design. What happens if the power goes out during an emergency? What happens if the sensor cable is cut? Real safety engineers plan for these worst-case scenarios — the system should default to the safest state, not the most convenient one.

Activity: Building the Gas Alarm

Let's program our MakerBuddy to be a vigilant gas detector with a threshold window so it doesn't alarm constantly.

Step-by-Step Instructions:

  1. Find the Baseline: Check the Dashboard and record the clean-air reading on its 0–100 scale.
  2. Set the Danger Zone: Pick a threshold clearly higher than your classroom baseline (for example, a baseline of 20 might use a danger threshold of 60).
  3. Rule 1 — Alarm: Create a Condition rule named "GasDanger". Sensor → Gas (MQ-2), Operator → , Threshold → your danger value. Step 1: Action → Buzzer On, Delay → 100 ms. Step 2: Action → RGB Red, Delay → 100 ms. Save!
  4. Rule 2 — All Clear: Create a Condition rule named "GasClear". Sensor → Gas (MQ-2), Operator → <, Threshold → your clear value. Step 1: Action → Buzzer Off, Delay → 100 ms. Step 2: Action → RGB Green, Delay → 100 ms. Save!
    Leave a gap between the clear and danger values so small changes do not make the alarm flicker.
  5. Test it: Your teacher will show you how to safely trigger the sensor (e.g., briefly holding a marker near it). Does the alarm sound?

Challenge: The Multi-Stage Alert

Early Warning System

A good safety system warns you before things get dangerous — not just when it's already critical. Can you build a three-stage alert system?

Stage 1 — Safe (MQ-2 < 25):   RGB Green
Stage 2 — Warning (MQ-2 > 30 AND < 60):   RGB Yellow
Stage 3 — Danger (MQ-2 ≥ 60):   RGB Red + Buzzer On

You will need three separate Condition rules. The Warning rule uses two comparisons of the same MQ-2 sensor so it does not overlap the Danger rule. Adjust all example values after measuring your own baseline.

Coming Up Next Week:

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