Sub topic 1
Why a digital pin can't output a steady in-between voltage
Prerequisites
This chapter assumes that you know the basic Arduino sketch structure, including setup() and loop(). You should also know how pinMode() and digitalWrite() work, have basic breadboard wiring experience, and understand introductory Ohm’s law.
Digital pins have two output states
A digital pin represents information with two states:
LOW, which is near 0 voltsHIGH, which is near the board’s logic supply voltage, about 5 volts on a typical Uno
The pin does not contain a digital-to-analog converter that can directly produce every voltage between those values. When configured as an output, internal transistors connect the pin either toward ground or toward the supply voltage.
The output state is selected with digitalWrite():
const uint8_t LED_PIN = 13;
void setup() {
pinMode(LED_PIN, OUTPUT);
}
void loop() {
digitalWrite(LED_PIN, HIGH);
delay(1000);
digitalWrite(LED_PIN, LOW);
delay(1000);
}This sketch makes the pin switch between its two output states. It does not make the pin output 2 volts, 3 volts, or another stable intermediate value.
| Arduino command | Intended pin state | Typical Uno voltage |
|---|---|---|
| `digitalWrite(pin, LOW)` | Off or logic low | Near 0 V |
| `digitalWrite(pin, HIGH)` | On or logic high | Near 5 V |
The exact voltage is not guaranteed to be perfect. It depends on the supply voltage, the current flowing through the pin, and the electrical characteristics of the board.
Why the pin cannot simply choose 2 volts
A digital output is designed to switch reliably, not to regulate an arbitrary voltage. A simplified output circuit contains a high-side transistor that connects the pin to the supply and a low-side transistor that connects it to ground.
When the high-side transistor is on, the pin is pulled high. When the low-side transistor is on, the pin is pulled low. The microcontroller controls which transistor conducts.
The output transistors have a limited resistance when they are on, but they are not intended to operate as a precision adjustable resistor. Trying to hold an intermediate voltage by partially turning on a transistor would produce an unstable voltage that changes with temperature, load current, and manufacturing variation.
A resistor divider can create an intermediate voltage outside the pin, but that voltage is not a regulated analog output. Connecting a load changes the divider’s voltage. A separate voltage regulator or amplifier is needed when a circuit requires a stable adjustable voltage.
Rapid switching creates analog-like behavior
Although a digital pin has only high and low states, it can switch very quickly. If a load responds to the average power over many switching cycles, the result can resemble an intermediate output.
For example, a pin that is high half of the time and low half of the time delivers about half the ideal average voltage to a suitable load. The pin is still never actually holding a steady halfway voltage.
This technique is called pulse-width modulation, or PWM. The proportion of each cycle spent high is the duty cycle. A 25% duty cycle means the signal is high for one quarter of every cycle. A 75% duty cycle means it is high for three quarters.
An LED responds to the average current and the human eye combines the rapid flashes into an apparent brightness level. A motor’s mechanical inertia can also smooth rapid changes in power. Other loads, such as a sensitive analog circuit, may need filtering before a PWM signal is useful.
The distinction matters: PWM produces a changing digital waveform, while a true analog output produces a continuously adjustable voltage. The next sections of the tutorial use PWM to control LED brightness.
Exercise
If an Arduino Uno pin is configured as an output, can digitalWrite(pin, HIGH) make it produce a stable 2.5 V output?
Show answer
No. It drives the pin toward its logic-high supply voltage. A stable intermediate voltage requires another circuit, or it can be approximated for some loads by rapidly switching the pin with PWM.