Level 1Unit C · Session 24
24

Unit C · Circuits and sensing

Sense, decide, act

What we are making: the whole chain, in one machine. Something changes in the world, your rule decides what it means, and something physically moves because of it.

Photo: a light sensor triggering a servo gate to swing open
Photo: a light sensor triggering a servo gate to swing open

The idea

Nothing new today. Everything you need you already built:

  • Sense — the light sensor from Session 6, giving a number.
  • Decide — the threshold you measured in Session 8.
  • Act — the servo from Session 9, moving to a named position.

This is the shape of every January project, and of every machine in this programme for the next seven years. Once you have built it once, you have built the pattern.

💡 Tip
Say your machine out loud as one sentence before you start: when the light drops below 380, the gate opens to 90 degrees. If you cannot say it, you are not ready to build it.

Wire it up

1
Light sensor
1
Resistor 10kΩ
1
Servo
6
Jumper wires
+−+−jihgfedcba151015202530light sensor5VA0GNDSERVOGND5Vpin 6
Sensor on the left, servo on the right, with plenty of space between them.
Pins usedA065VGND

The code

Your program
when the board starts up
forever
if < (read analog pin (A0)) < (380) > then
set servo pin (6) angle to (90)
else
set servo pin (6) angle to (0)
Screenshot: the full sense-decide-act program in mBlock
Screenshot: the full sense-decide-act program in mBlock

Try it — fifteen times

One success proves nothing. Trigger it fifteen times and count how many times it did exactly what your sentence said.

  • Fifteen out of fifteen — good. Change something. Move it near the window and try again.
  • Twelve out of fifteen — find out what the other three had in common. That is the fault.
  • It works but hesitates — the servo may be starved of power while it moves.
🔮 Try this
Swap the servo for the buzzer, or the light sensor for the ultrasonic. The middle of your program barely changes. That is the whole point of the pattern — the sensing and the acting are interchangeable, and the rule in the middle is yours.

End of Unit B

You can now read a real measurement, decide what it means using a number you chose from your own data, and make something move because of it.

In January you will pick one project from a list of ten and build it properly. Every one of those ten is made from exactly the parts of this unit. There is nothing on that list you have not already done at least once.

Challenge optional — only if you finish early
  • Add a second sensor so your machine has two reasons to act, not one.
23. The servo