Digital, Analog (ADC) & PWM (~) Arduino Pins
Digital pins (0–13) read or output strictly two states: HIGH (5V) or LOW (0V). Analog input pins (A0–A5) measure continuous sensor voltages from 0 to 1023, while PWM (~) pins output 0–255 duty cycles to dim LEDs or control motor speed.
How It Works & Why It Matters
Digital pins handle pushbuttons and on/off relays; analogRead() samples light sensors, temperature probes, and gas sensors.
Pins marked with a tilde (~) on UNO (3, 5, 6, 9, 10, 11) support analogWrite(pin, 0..255) via rapid Pulse-Width Modulation.
digitalWrite(8, HIGH); // 0 or 1 int btn = digitalRead(2); // HIGH / LOW int light = analogRead(A0); // 0 .. 1023 (10-bit ADC) analogWrite(9, 128); // 0 .. 255 PWM on ~ pins
🏫 Classroom Example
Use map(analogRead(A0), 0, 1023, 0, 255) to turn a sensor reading smoothly into LED brightness.
⚖️ Digital Signal vs. Analog Signal
Digital signals jump cleanly between 0 and 1; analog signals vary smoothly across a continuous range.
Calling analogWrite() on a non-PWM pin like pin 4—it only turns completely on (>=128) or off (<128).