Sensors

Turning light, distance, motion or force into a number your code can use

Recap

  • physical computing opens with input: a microcontroller reading the world, not writing to it yet
  • “reading a sensor” is a loop, not a one-off event — the board checks again and again
  • a walkthrough of two or three common sensor types, and where each is a good fit
  • today’s crit looks at Studio Brief 1 — a digitizing technique combined with Programming I

Wiring a sensor

An analog pin is for a continuously varying signal — light or distance — where the value can sit anywhere across a range. A digital pin is for something that’s simply on or off, like a button or some motion sensors. The pin type you choose has to match what the sensor actually produces.

Reading the raw value

Read the pin in a loop, and print whatever comes back before you do anything else with it. A value you can see on screen is a value you can trust — one you can’t see is a guess.

int raw = analogRead(A0);
Serial.println(raw);

Scaling it to what you need

The raw range a pin reports rarely matches the range something else wants, so scale it with map().

int brightness = map(raw, 0, 1023, 0, 255);

Only build anything else on top once that printed, scaled number moves the way you’d expect when you wave a hand or change the light.

What this can build toward: a presence-aware installation

A distance sensor watching the space in front of a small installation — the piece stays still until someone steps close, then responds. The whole behaviour is one scaled sensor reading, checked in a loop.

What this can build toward: a quietly reactive object

A light or sound sensor reading driving a subtle, visible change in an otherwise ordinary object — colour, brightness, or a small shift in tone — proof that a sensor doesn’t need a dramatic output to be worth wiring up.