Sub topic 12
Logic Levels: Why 5V and 3.3V Matter
Assume you know basic voltage, current, and resistance, and that you can write an Arduino sketch with setup() and loop(). This chapter uses the 5V Arduino Uno R3 as the reference board.
A logic level is a voltage that represents a digital value. A LOW usually represents 0, and a HIGH usually represents 1. The voltage ranges that count as LOW or HIGH depend on the device's supply voltage and electrical specifications.
The Uno's 5V logic
The Uno's ATmega328P microcontroller normally operates at 5V. Its digital pins drive approximately:
- LOW: close to 0V
- HIGH: close to 5V
When an Uno input reads a signal, it does not require an exact 0V or 5V value. For ordinary digital inputs, a voltage below about 1.5V is guaranteed to read as LOW, and a voltage above about 3.0V is guaranteed to read as HIGH when the microcontroller operates at 5V. Voltages between these ranges are uncertain.
This explains why a 3.3V sensor output can usually drive an Uno input safely. The Uno sees 3.3V as HIGH. However, an Uno output can send nearly 5V to a 3.3V-only input. That voltage may exceed the input's maximum rating and damage the other device.
Logic voltage is not power voltage
A board's 5V pin supplies power. A digital pin carries a signal. Do not connect a signal pin directly to a power pin unless the circuit specifically requires that connection.
The Uno's 3.3V pin is a regulated power output for small external circuits. It does not change the Uno's digital pins to 3.3V logic. Signals from Uno pins remain approximately 5V.
A voltage divider can reduce a 5V signal for a high-impedance input. A level shifter is more appropriate for bidirectional signals or faster communication. For I2C, the pull-up resistors determine the bus voltage, so connect them to the lower device voltage when all devices support that arrangement.
Applying the rule in a sketch
The sketch below configures an Uno pin as an output. The selected pin produces a 5V-level HIGH and a 0V-level LOW. The code controls logic state, not an exact measured voltage.
const int signalPin = 7;
void setup() {
pinMode(signalPin, OUTPUT);
}
void loop() {
digitalWrite(signalPin, HIGH);
delay(1000);
digitalWrite(signalPin, LOW);
delay(1000);
}Choosing compatible devices
Before connecting two boards, compare:
| Question | Why it matters |
|---|---|
| What voltage powers each device? | It suggests, but does not prove, its signal voltage. |
| What input HIGH and LOW ranges are specified? | They determine whether the signal will be recognized. |
| Is the input 5V-tolerant? | It determines whether a 5V signal is safe. |
| Is the signal bidirectional? | Bidirectional buses often need a proper level shifter. |
Voltage compatibility is separate from current capacity. Even a signal with a safe voltage can be unsafe if a pin must source or sink too much current.
Exercise
An Uno sends a HIGH signal to a sensor powered at 3.3V. What should you check before connecting the wire?
Show answer
Check the sensor datasheet for its maximum input voltage and 5V tolerance. If it is not 5V-tolerant, use a level shifter or suitable voltage divider.