From readings to decisions
A sorting machine sees thousands of parts an hour and never gets bored. How does it decide where each one goes?
About 25 min · 3 goals · Checked by automated tests; not yet reviewed by an educator
1.Why should I care?
Sensors give numbers; machines need decisions. The bridge between them is often a threshold and a rule table, the same logic behind sorting machines, thermostats and automatic lights.
- ◇ Use a threshold to turn a sensor reading into a yes/no decision.
- ◇ Combine several yes/no answers into a rule table.
- ◇ Explain why noise near a threshold causes wrong decisions, and one way to reduce them.
2.Predict
A red-detector says 'red' if its reading is above 65. A part reads 58. What does the machine decide?
Guess first. Being wrong here is how the surprise works.
3.Discover
Do Level 2 of the sorting-machine Build: turn the client's brief into a rule table with a row for every combination of red, large and metal. Watch the belt follow your table. Did any row surprise you?
Can't use the interactive? Read a description instead
The sorting-machine rule table has eight rows, one for every combination of red or not, large or not, and metal or not. For each row you choose the bin. A part whose reading sits close to a threshold can be misjudged if the sensor is noisy, which is why thresholds are chosen with care.
4.Understand
Thresholds
A threshold is a line you draw across a sensor's range: above it means yes, below it means no. Is it red? Reading > 65. Is it dark? Light < 30. Too hot? Temperature > 24 °C. One number becomes one clear answer a controller can act on.
Rule tables
With several yes/no answers, list every combination in a rule table. Three sensors (red? large? metal?) give 2 × 2 × 2 = 8 rows. For each row you choose an action: which bin. Writing every row stops you forgetting a case, a common cause of machines doing something silly.
Noise near the line
A reading close to the threshold can flip between yes and no just from noise. A thermostat might click on and off every few seconds. Fixes: average readings first, or use two thresholds: heater on below 19.5 °C, off above 20.5 °C. The gap between them is called hysteresis, and it stops the flicker.
Explain it another way
A height line at a theme park ride is a threshold: taller than the line, you ride; shorter, you don't. A rule table is like a recipe card for every possible situation.
Thresholding classifies a continuous reading into categories. Combining binary features gives 2ⁿ cases for n features. Hysteresis (separate on and off thresholds) prevents rapid switching, called chattering, when a noisy signal hovers near one threshold.
Street lights switch on when a light sensor reads below a threshold and off at a higher threshold, so passing car headlights or a cloud don't make them flicker.
Worked example 1
A plant-watering rule: water if soil moisture < 30%. Readings over a minute: 31, 29, 32, 28, 30%. What goes wrong, and how would you fix it?
The readings hover around 30%, so a single-reading rule would switch the pump on and off repeatedly. Fix: average (here: 150 ÷ 5 = 30% → no watering yet), or use two thresholds: start below 28%, stop above 35%.
Common mix-ups
- Once you pick a threshold, decisions are always right.
✓ Noise near the threshold can still cause wrong calls. Averaging and hysteresis reduce them. - You only need rules for the common cases.
✓ Machines meet rare cases too. A complete rule table gives every case a planned action.
5.Practice
Practice, not a test. Wrong answers get a hint and another try.
Practice 1
A night light turns on if the light reading is below 40. The reading is 52. What happens?
Practice 2
A machine uses four yes/no sensors. How many rows does a complete rule table need?
Practice 3
A heater keeps clicking on and off every few seconds when the room is near 20 °C. Which fix works best?
Practice 4
Why write out every row of a rule table, even unlikely ones?
6.Apply it
Design the rules for an automatic plant-watering helper with two sensors: soil moisture and light level (don't water in full midday sun). Choose thresholds, write the full rule table (4 rows), and add hysteresis to the moisture rule. Test your rules on five made-up sets of readings.
7.Reflect
Concepts: Thresholding and simple classification · The sense–think–act loop