Skip to content
Tactiverge

School/◇ Explorer/Week 31

The rules inside your machine

A plant waterer that waters whenever there's water in the tank sounds fine, until you ask what happens when the soil is already wet.

About 30 min · 3 goals · Checked by automated tests; not yet reviewed by an educator

1.Why should I care?

'Simple logical reasoning (a rule or flowchart)' is a capstone requirement. A flowchart is a conceptual prototype of your machine's brain: you can test it completely on paper, before any code or circuit exists.

  • ◇ Write a machine's decision as an if-then rule and as a flowchart.
  • ◇ Test a rule by checking every combination of inputs in a truth table.
  • ◇ Find and fix a logic bug in a simple flowchart.

2.Predict

The rule is 'if the tank has water, open the valve'. The soil is wet and the tank is full. What does the machine do?

Guess first. Being wrong here is how the surprise works.

3.Discover

Set the two sensors to each of the four combinations and trace the intended flowchart. Then switch to the buggy version and find the combination where it does the wrong thing. Use the truth table to check you've found every mismatch.

Interactive

Trace the machine's rules

Every 10 minutes the plant waterer reads its soil sensor and its tank sensor, then follows a flowchart. Set the sensor readings and trace which way the flowchart goes. Then switch to the buggy version and find the case where it goes wrong.

Soil sensor says dry?
Tank has water?
Which flowchart?
  1. Start: read both sensors
  2. ◇ Is there water in the tank? Yes
  3. ◇ Is the soil dry? Yes
  4. Action: Open the valve for 10 seconds, then wait 10 minutes
Every combination (a truth table)
Soil dry?Tank water?IntendedBuggy
yesyeswaterwater
yesnowarnwarn
noyeswaitwater ✗ mismatch
nonowarnwarn
The intended rule warns when the tank is empty, and waters only when the tank has water AND the soil is dry.

A rule like this is the 'think' part of sense, think, act. Checking every combination of inputs is how you test logic without hardware.

Can't use the interactive? Read a description instead

Flowchart as text: every 10 minutes, read the sensors. Question 1: is there water in the tank? If no, light the refill warning and wait. If yes, question 2: is the soil dry? If no, wait 10 minutes. If yes, open the valve for 10 seconds, then wait. The buggy version skips question 2, so it waters whenever the tank has water, including when the soil is already wet.

4.Understand

Rules as if-then

A machine's decisions can usually be written as if-then rules: if the tank is empty, then light the warning. If the tank has water and the soil is dry, then open the valve for 10 seconds. Write them in plain language first; they can become code or a circuit later.

Flowcharts

A flowchart draws the rules. Diamonds are yes/no questions. Rectangles are actions. Arrows show the order. Most machines loop: after acting, they wait and start again. Trace it with your finger for one situation at a time.

Test every combination

Two yes/no inputs give 2 × 2 = 4 combinations; three give 8. List them all in a truth table with what the machine should do and what your flowchart does. Any row where they differ is a bug. This tests your logic completely, for free.

Explain it another way

A flowchart is a choose-your-own-adventure book for the machine: each answer sends it to a different page.

Worked example 1

Write a rule for a night light that comes on when it's dark and someone is moving.

If dark AND movement, switch the lamp on for 2 minutes. Truth table: dark + moving → on; dark + still → off; light + moving → off; light + still → off.

Common mix-ups

  • If the rule works in the normal case, it works.
    ✓ Check every combination. Bugs hide in unusual cases.
  • Flowcharts are only for programmers.
    ✓ Any machine that decides something has rules, and a flowchart shows them to anyone.

5.Practice

Practice, not a test. Wrong answers get a hint and another try.

Practice 1

A rule uses 3 yes/no inputs. How many rows does its truth table have?

rows

Practice 2

In a flowchart, what does a diamond mean?

Practice 3

Rule: 'If the soil is dry OR the tank has water, open the valve.' The soil is wet and the tank is full. What happens?

Practice 4

Which test proves a two-input rule is right in every case?

6.Apply it

Write your capstone machine's rules as if-then sentences, draw them as a flowchart, and fill in a truth table for every combination of inputs. Mark any row where the flowchart does the wrong thing, and fix it. Add the flowchart, in words, to your Design Studio project.

7.Reflect

Concepts: Decisions and loops · Logic gates and Boolean algebra