📘 CodingMarble Learn

Physical Computing: Making Code Sense and Move

Physical computing joins code to the real world. Sensors measure something (light, temperature, distance, button presses) and turn it into a number. A microcontroller runs a program that decides what to do with that number. Actuators (LEDs, buzzers, motors, screens) act on the world. This input–process–output cycle runs again and again in a loop. Using thresholds, conditions and feedback, we build night lights, smart plant waterers, wearables and interactive art.

🎬 Step-by-step story

  1. This green board is a microcontroller: a tiny computer on one chip. It has no screen or keyboard. It talks to the world through its pins.
  2. On the left is a light sensor. The sun's brightness becomes a number from 0 to 1023. The orange dot carries that reading to the board. This is the INPUT.
  3. Inside, the board runs a program: "if light < threshold → LED on". This is the PROCESS. The board compares the number with 400.
  4. Now the sun dims. The reading falls below 400. The rule becomes true and the LED glows red. This is the OUTPUT.
  5. A motor is added. It is an actuator: it changes the world by moving. When it is dark, the fan spins too. One input can drive many outputs.
  6. Your turn: move the light and threshold sliders. Find the exact point where the LED switches on.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Is a microcontroller the same as a computer?

It is a very small computer for one job. It has a processor and memory but no screen or keyboard; it uses pins instead.

Why does the reading go up to 1023 and not 100?

The board turns voltage into a 10-bit number, which has 1024 steps (0–1023).

Who decides the threshold value?

The programmer. You test in real light and choose a number that works; you can change it with the slider.

Why does the LED switch on only after the sun dims a lot?

The rule is true only when the reading drops below 400.

Can one sensor control many outputs?

Yes. The program can switch several actuators from the same reading, like the LED and the fan.

What happens if light and threshold are equal?

With "<" the rule is false, so the LED stays off. Try it with the sliders.

What is physical computing?

Physical computing means building systems where a program senses the real world and acts on it. It uses small boards called microcontrollers (for example micro:bit, Arduino or Raspberry Pi Pico). A microcontroller has a processor, a little memory and input/output pins on one chip.

Every system follows input → process → output, running inside a loop that repeats many times a second.

Sensors and actuators

Digital and analog signals

A digital input has only two values: 0 or 1 (button up or down). An analog input can take many values; the board's analog-to-digital converter turns a voltage into a number, often 0–1023 (10-bit). Outputs can be digital (LED on/off) or use PWM (quick on-off switching) to dim an LED or set motor speed.

Programming the behaviour

A typical program:

forever:
  light = read light sensor
  if light < 400:
    LED on
  else:
    LED off
  wait 100 ms

Key ideas: variables store readings, conditions compare with a threshold, the loop keeps checking. Real sensors are noisy, so we average readings or use two thresholds (hysteresis) to stop flickering. A feedback loop uses the result of an action as the next input – for example a fan that slows down once the room has cooled.

Design cycle

Define the problem → choose sensors and actuators → draw a circuit and flowchart → build and code → test with real conditions → improve.

Projects, wearables and art

Think about safety (low voltage, no mains wiring), power use (battery life), privacy (what data sensors collect) and accessibility.

Try it

No board? Be the microcontroller: a friend covers and uncovers a torch (sensor), you follow the rule "if it is dark, clap" (process), and your clap is the actuator. Then change the threshold: "only clap if it is very dark".

Key formulas and definitions

Worked examples

1. Name the input, process and output of an automatic night light.

Input: light sensor reading. Process: if the reading is below a threshold, switch on. Output: LED or lamp.

2. A 10-bit sensor reads 512. About what fraction of full scale is that?

512 / 1023 ≈ 0.5, so about half of the maximum.

3. Light readings near dusk jump between 395 and 405, so the lamp flickers with threshold 400. Fix it.

Use two thresholds: turn on below 380, turn off above 420 (hysteresis), or average several readings first.

4. Design a plant waterer.

Input: soil-moisture sensor. Process: if moisture < 30% then pump on for 3 s, then wait. Output: water pump through a relay. Loop and test.

5. An LED is driven by PWM at 25% duty cycle. How bright does it look compared with full on?

It is on only a quarter of the time, so it looks about one quarter as bright.

Common mistakes

Practice quiz

1. Which is a sensor?
2. Which is an actuator?
3. A 10-bit analog reading ranges from:
4. The part that runs the program is the:
5. Using the result of an action as the next input is called:

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is physical computing in simple words?

Using code with sensors and motors so a computer can feel and change the real world.

Which board is best for beginners?

Any board with block coding and built-in sensors, such as a micro:bit, is an easy start; Arduino and Pico are great next steps.

What is the difference between a sensor and an actuator?

A sensor measures (input); an actuator does something (output).

Where this is taught

NetherlandsHAVO 5 (eindexamenjaar)Elective theme: Physical computing
NetherlandsVWO 6 (eindexamenjaar)Elective theme: Physical computing
South Korea중학교 2학년Computing systems
South Korea중학교 3학년Computing systems
South Korea고등학교 2학년Computing systems
South Korea고등학교 2학년Software for creation
South Korea고등학교 3학년Computing systems
FrancePremièreDigital tools and languages
FrancePremière5. Construction solutions
FranceTerminale5. Construction solutions
China高三Sel.6 Open-source hardware projects

Learn first

Learn next

Related lessons

All Computer Science lessons