If it's dry, water it: IF, AND, OR, NOT
Write the rules for a smart sprinkler, porch light and fan using IF, AND, OR and NOT, then test them against every situation. This is how smart devices decide.
- Computational thinking
- Critical thinking
- Problem solving
🧰 You will need
- 1 × Piece of thin card (cereal box)
- 1 × Pencils and crayons
- 1 × Scissors
💡 How does a smart light know when to switch on?
A “smart” device isn’t really clever. It follows rules written by a programmer, like: IF it is dark AND someone is near the door, THEN switch the light on. Words like IF, AND, OR and NOT are how computers make decisions. They’re called logic.
🎮 Try it on the screen
Build a rule for each gadget. Then press Check my rule: it tests all 4 situations, and every row must be ✅, not just one.
Tap the grey and yellow boxes to change the rule.
Machine: turn the water ON ✅
| the soil is dry? | it is raining? | Your rule | Should | |
|---|---|---|---|---|
| no | no | off | off | ✅ |
| no | yes | ON | off | ❌ |
| yes | no | ON | ON | ✅ |
| yes | yes | ON | off | ❌ |
Some tests fail (❌). Change NOT, AND or OR until every row is ✅.
🛠️ Rule cards game
- Cut card into small cards. Write a situation on each: “raining”, “sunny”, “night”, “day”, “hungry”, “school day”, “weekend”.
- Write a rule on a big card, like: “IF sunny AND weekend, THEN go to the park”.
- Shuffle the situation cards and pick two. Does the rule say “go to the park”? Everyone shouts YES or NO!
- Change AND to OR. Play again. What changes?
- Add NOT: “IF NOT raining AND weekend”. Try every pair of cards.
- Now make up a rule for a real machine: an automatic door, a rice cooker, a phone alarm.
💡 What happened?
- AND means both things must be true. It’s strict.
- OR means at least one is true. It’s easy-going.
- NOT flips true to false.
Good programmers don’t just try their rule once. They test every possible situation. With 2 inputs there are 4 situations; that list is called a truth table.
Did it work?