Skip to content
MakerBuddy

Week 26 · Term 4 · 45 to 60 minutes

Sensor-Based Control: Condition Loops

Threshold comparison logic

Try it first, no kit needed

Sensor-Based Control: Condition Loops

Week 26 Term 4 45-60 minutes

Learning Objective

Discover the most powerful feature of the Rule Engine: Condition Loops. Learn how to trigger actions based on what the sensors are detecting, making the MakerBuddy truly autonomous — reacting to the real world on its own!

Theory: Teaching the MakerBuddy to React

What is a Condition Loop?

So far your MakerBuddy acts once, forever or on a timer. Now it learns to react to its surroundings.

A Condition Loop keeps checking a sensor in the background, with a fresh reading every second. When the reading crosses your threshold (the trigger number), it runs your steps, and repeats them while the condition stays true. When it stops being true, the rule finishes its current round, then stops. It is like a smoke alarm: silent all day, then the moment it smells smoke, BEEP BEEP BEEP!

Start with one sensor today. A Condition rule can also combine two different sensors with AND or OR. That comes in Week 27, with Range Logic.
Selecting Condition mode in the updated MakerBuddy Rule Engine

Select Condition to reveal the sensor, operator and threshold controls.

The Four Steps of Building a Condition Rule

Work through these four steps in order:

Step 1: Choose Sensor

1. Choose the Sensor (Input)

Pick the sensor to watch. There are ten: Temperature (DHT11), Humidity (DHT11), Probe Temp (DS18B20), Light Level (LDR), Gas Level (MQ2), Soil Moisture, Distance (HC-SR04), Potentiometer, Motion Sensor and Push Button. Motion Sensor and Push Button are yes/no inputs, so they use Equal to (==) with True or False.

Step 2: Choose Operator

2. Set the Operator

Choose a comparison: Greater than (>), Less than (<), Greater or equal (>=), Less or equal (<=), or Equal to (==). The MakerBuddy repeats this "test" on every new reading.

Step 3: Set Threshold

3. Define the Threshold

Pick the number that triggers the rule. For example, a Light Level less than 50 means dark. Check the Dashboard first for your sensor's normal reading.

Step 4: Combine it all

4. Set the Action Steps

Add the steps: what should the MakerBuddy do when the condition is true? For example: Action → LED On, Value → 255, Delay (ms) → 100.

For Teachers

Check students know > from <: mixing them up is the most common mistake. A handy trick: "The arrow always points to the smaller number."

Try It: Build a Condition Rule

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: The Automatic Nightlight

Build a light that turns on by itself when the room gets dark. The rule keeps repeating its steps while the room stays dark.

Step-by-Step Instructions:

  1. Check Ambient Light: Read the Light Level card on the Dashboard. What does the room read? (e.g., 80)
  2. Cover the Sensor: Shade the LDR (the light sensor) with your hand. What does it read now? (e.g., 20)
  3. Pick a Threshold: Choose a number halfway between bright and dark (e.g., 50). This is your trigger point.
  4. Create the Rule: Open the Rule Engine tab. In Create Rule, type "Nightlight" as the Rule Name and set Loop Mode to Condition.
  5. Configure Condition: Sensor → Light Level (LDR), Operator → Less than (<), Threshold → 50.
  6. Add the Step: Click Add Step, then Action → LED On, Value → 255, Delay (ms) → 100. Click Save Rule.
  7. Test it: Cover the sensor. Within about a second, the LED turns on. Remove your hand: it stays on, because the rule only has an On step. Turning it off needs a second rule, which comes next week.
  8. Take back control: While the rule is watching, the LED Control card shows "This control is used by Rule Engine. Manual control is overridden." and its switch is locked. To turn the LED off, press ⏹️ on the Nightlight row in the Rule Engine list. Its tooltip says Stop Monitoring, or Stop Rule while the rule is running. Then use the LED switch. Press ▶️ (Start Rule) to let the rule watch again.

Challenge: The Smart Fan

Cool Down the Room

You built a nightlight. Now can you build a smart thermostat?

  • First, with USB unplugged, plug the DHT11 into the connector marked 25 and the relay into the connector marked 23. Use only the low-voltage load supplied with the kit. Power up and check the Temperature (DHT) card shows a real temperature (0.0 means the sensor is not being read).
  • Create a Condition rule that listens to the Temperature (DHT11) sensor.
  • Operator → Greater than (>), Threshold → 30.
  • Step 1: Action → Relay On (to turn on a fan), Delay (ms) → 100. Click Save Rule.
  • Bonus: Make the reverse rule: if temperature drops below 26, Action → Relay Off. The gap between 26 and 30 is a threshold window that stops rapid on-off switching.

Coming Up Next Week:

Week 27: Range Logic, Multiple Sensors & Threshold Windows

Learning Support

Use this quick guide to help every learner understand, practice and explain Sensor-Based Control: Condition Loops.

For students

Try it in three steps

  1. Say it: explain the main idea in one simple sentence.
  2. Show it: Build an automatic nightlight: a Condition rule that turns the LED on when the Light Level (LDR) is less than 50.
  3. Stretch it: Build a smart fan: turn the relay on when Temperature (DHT11) is greater than 30°C, and off again below 26°C.

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: Unplug the USB cable before plugging the DHT11 into connector 25 or the relay into connector 23, and never force a plug. Use only the kit's low-voltage fan or lamp on the relay, never mains electricity.

Did you get it?

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

  1. 1What does a Condition rule keep doing in the background?

  2. 2The Nightlight rule turns the LED on in the dark. Why does it stay on when the room gets bright?

  3. 3Which sensor setting makes a nightlight come on when the room is dark?