Digital vs Analog
The difference between a light switch and a dimmer — and why your Arduino cares.
In 10 seconds
- • Digital = on or off. Analog = a whole range.
- • digitalRead/Write handle on-off. analogRead gives 0–1023.
- • analogWrite uses PWM to fake in-between levels.
This is one of those ideas that sounds technical until somebody gives you the right picture, and then it never confuses you again. So here is the picture: a digital signal is a light switch, and an analog signal is a dimmer knob.
A light switch has exactly two positions. Up or down. On or off. There is no such thing as slightly on. In Arduino language we call those two states HIGH and LOW, and HIGH usually means about 5 volts while LOW means 0 volts.
A dimmer knob is different. You can set it anywhere between fully off and fully bright, including all the fuzzy in-between places. Most things in the real world behave like this: temperature, brightness, loudness, how far you have turned a knob. None of those are on-or-off questions.
Digital pins
The numbered pins along the edge of your Arduino are digital. You use digitalWrite(pin, HIGH) to switch something on, and digitalRead(pin) to check whether a button is pressed. The answer will always be one of two things, which makes digital pins simple and reliable.
Analog inputs
The pins labelled A0 to A5 can measure a voltage anywhere between 0 and 5 volts. When you call analogRead(A0) the Arduino gives you a whole number from 0 to 1023. Zero means no voltage at all, 1023 means the full five volts, and 512 means roughly halfway — about 2.5 volts.
Why 1023 and not 100? Because the chip measures in steps, and it has 1024 of them. More steps means finer detail, the same way a ruler with millimetre marks is more precise than one with only centimetres.
The clever trick: PWM
Here is a puzzle. If digital pins can only be on or off, how can an LED fade? The answer is a trick called PWM, or pulse width modulation. The Arduino switches the pin on and off extremely fast — hundreds of times a second — and changes how much of each cycle is spent on. Spend 90% of the time on and the LED looks bright; spend 10% and it looks dim. Your eyes cannot see the flickering, so you just see brightness.
You use it with analogWrite(pin, value) where value goes from 0 to 255. Confusingly the function is called analogWrite even though the pin is digital, and it only works on pins marked with a little ~ symbol. Look for them on your board now: 3, 5, 6, 9, 10 and 11 on an Uno.
Quick summary
- digitalWrite — switch an output fully on or off.
- digitalRead — is this input HIGH or LOW?
- analogRead — measure an input, get 0 to 1023.
- analogWrite — fake an in-between output using PWM, 0 to 255.
Quick quiz: Digital vs Analog
3 questions to check it stuck.
Next lesson
⚡ Voltage and Current
Ready to try it for real?
Reading is good. Wiring is better. Pick a project and put this to work.
Explore projects