Lesson 4: Coding Meets Hardware
Physical computing means using code to control real-world hardware — lights, motors, sensors. Platforms like Arduino and Raspberry Pi let you write code that interacts with the physical world.
Key Concepts
Microcontrollers
A microcontroller is a tiny computer on a single chip. It reads inputs (buttons, sensors, temperature) and controls outputs (LEDs, motors, screens) based on code you write. Arduino uses C/C++; MicroPython runs Python on microcontrollers.
Digital and Analog Signals
Digital signals are binary — on or off, HIGH or LOW. An LED is either on or off. Analog signals have a continuous range — a temperature sensor might read 72.4 degrees. Analog-to-digital converters (ADCs) translate analog signals into numbers a microcontroller can use.
Sensors and Actuators
Sensors read the world: temperature, light, distance, motion. Actuators change the world: motors, servos, LEDs, buzzers. A physical computing project usually has sensors as inputs and actuators as outputs, with code connecting them.
🆕 Virtual Arduino Simulator
Simulate a simple Arduino LED blink and sensor read in Python-style pseudocode.
LED_PIN = 13
SENSOR_PIN = A0
def setup():
pinMode(LED_PIN, OUTPUT)
def loop():
light = analogRead(SENSOR_PIN)
if light < 500: # dark
digitalWrite(LED_PIN, HIGH) # LED on
else:
digitalWrite(LED_PIN, LOW) # LED off
✅ Check Your Understanding
1. What is a microcontroller?
2. What is the difference between a sensor and an actuator?
3. What does analogRead() do?