Every Arduino has two kinds of pins — digital and analog — and using the wrong kind is a classic beginner trip-up. Here’s the difference in plain terms, and how to know which to use.
Digital pins: on or off
Digital pins deal in two states only — HIGH (on) or LOW (off). That’s perfect for things that are either/or: a button pressed or not, an LED on or off, a relay open or closed. You read them with digitalRead() and control them with digitalWrite(). The Uno has 14 digital pins (0–13).
Analog input pins: the in-between
Some sensors don’t give a clean on/off — a light sensor gets gradually brighter, a dial turns smoothly. Analog input pins (A0–A5 on the Uno) read that range and give you a number from 0 to 1023 with analogRead(). An LDR in a dim room might read 200; in bright light, 900.
The confusing bit: PWM (“analog output”)
Here’s what trips people up. Digital pins can’t produce a true analog output — but the six PWM pins (marked ~: 3, 5, 6, 9, 10, 11) fake it by switching on and off very fast. analogWrite() on a ~ pin can dim an LED or set a motor speed. So “analogWrite” actually happens on special digital pins, while “analogRead” happens on the analog pins. Different jobs, similar names.
Quick reference
| You want to⦠| Use | Function |
|---|---|---|
| Read a button | Digital pin | digitalRead() |
| Turn an LED on/off | Digital pin | digitalWrite() |
| Read a dial / light sensor | Analog pin (A0–A5) | analogRead() |
| Dim an LED / set motor speed | PWM pin (~) | analogWrite() |
A worked example
Say you want a knob to control an LED’s brightness. The knob (potentiometer) is analog, so you read it on A0 with analogRead() (0–1023). The LED brightness is a PWM output, so you write it on a ~ pin with analogWrite() (0–255). You map one range to the other. That single project uses both pin types — and once it clicks, the whole distinction makes sense.
Frequently asked questions
Can a digital pin read an analog sensor?
Only as on/off past a threshold. To read the actual value, use an analog input pin (A0–A5).
Why is analogRead 0–1023 but analogWrite 0–255?
Reading uses a 10-bit converter (2ΒΉβ° = 1024 steps); PWM writing uses 8-bit (256 steps). Just remember the two ranges.
Which pins are PWM?
On the Uno, the ones marked with a ~: 3, 5, 6, 9, 10 and 11. See our Uno pinout guide.
Related guides
Get parts to try it
Grab an Arduino Uno, an LDR, an LED and a breadboard, or browse Arduino boards and components. Visit us at Shaheen Market, DAV College Road, Rawalpindi or order online.