Sensor-Based Control: Condition Loops
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!

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:

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.

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.

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.

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:
- Check Ambient Light: Read the Light Level card on the Dashboard. What does the room read? (e.g., 80)
- Cover the Sensor: Shade the LDR (the light sensor) with your hand. What does it read now? (e.g., 20)
- Pick a Threshold: Choose a number halfway between bright and dark (e.g., 50). This is your trigger point.
- Create the Rule: Open the Rule Engine tab. In Create Rule, type "Nightlight" as the Rule Name and set Loop Mode to Condition.
- Configure Condition: Sensor → Light Level (LDR), Operator → Less than (<), Threshold → 50.
- Add the Step: Click Add Step, then Action → LED On, Value → 255, Delay (ms) → 100. Click Save Rule.
- 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.
- 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
- Say it: explain the main idea in one simple sentence.
- Show it: Build an automatic nightlight: a Condition rule that turns the LED on when the Light Level (LDR) is less than 50.
- 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.
Did you get it?
Three quick questions. Pick an answer to see whether it is right, and why.
1What does a Condition rule keep doing in the background?
2The Nightlight rule turns the LED on in the dark. Why does it stay on when the room gets bright?
3Which sensor setting makes a nightlight come on when the room is dark?
