Sub topic 1
Digital signals: what HIGH and LOW mean
A digital input pin turns a voltage into one of two answers. This chapter explains how that conversion works, where the voltage limits are, and what digitalRead returns. Later chapters rely on this model when they wire up a push button.
Prerequisites
This chapter assumes you already know the following:
- The basic structure of an Arduino sketch, with
setup()andloop(). - Voltage, current, and resistance, including Ohm's law (V = I × R).
- How to use a breadboard and jumper wires.
- How to drive an LED with
digitalWrite.
The examples use an Arduino Uno (ATmega328P, 5 V logic). Where a different board changes the numbers, the text says so.
Two states from a continuous voltage
The voltage on a wire can take any value. A digital input ignores most of that detail. It asks only whether the voltage is high enough to count as one state or low enough to count as the other.
- LOW means the voltage is close to ground (0 V). It represents logical 0.
- HIGH means the voltage is close to the board's supply voltage. It represents logical 1.
In the Arduino core, HIGH is defined as 1 and LOW as 0. digitalRead returns one of those two values, so a comparison like digitalRead(pin) == HIGH is a numeric comparison.
The supply voltage is often written Vcc. On an Uno it is about 5 V. On many newer boards, such as the Due, the Nano 33 family, and ESP32 boards, it is 3.3 V. HIGH is therefore not a fixed voltage. It means "near Vcc for this board".
Thresholds and the undefined region
The microcontroller does not compare the pin to a single cutoff. Its input circuit has two thresholds with a gap between them.
For the ATmega328P, the datasheet gives these limits for supply voltages from 2.4 V to 5.5 V:
- A voltage at or below 0.3 × Vcc is guaranteed to read as LOW.
- A voltage at or above 0.6 × Vcc is guaranteed to read as HIGH.
| Supply (Vcc) | Guaranteed LOW | Undefined | Guaranteed HIGH |
|---|---|---|---|
| 5 V | 0 V to 1.5 V | 1.5 V to 3.0 V | 3.0 V to 5 V |
| 3.3 V | 0 V to 0.99 V | 0.99 V to 1.98 V | 1.98 V to 3.3 V |
Between the two thresholds the result is not guaranteed. The pin may read HIGH, LOW, or change between them from one reading to the next. The result can depend on temperature, supply voltage, and the individual chip. A signal that sits in this band is the root of many "my button works sometimes" problems.
Good digital design keeps the signal out of the undefined region. It does this by making sure every input is always connected to a source that holds it near 0 V or near Vcc. The next chapters build on this rule.
What an input pin electrically is
A pin set as INPUT has very high impedance. It draws almost no current: the datasheet lists a leakage of about 1 µA or less. The pin is a sensor that watches a voltage and barely disturbs it.
Two consequences follow:
- A very weak source can drive an input. A tiny current is enough to hold the voltage steady, provided the pin is connected to something.
- A pin connected to nothing does not sit at 0 V. With almost no current draining it, stray charge and electrical noise can push its voltage anywhere. This is a floating input, covered in a later chapter.
Reading a pin in code
Two calls cover the basics:
pinMode(pin, INPUT)configures the pin as a high-impedance input.digitalRead(pin)samples the pin and returnsHIGHorLOW.
This sketch prints the level of pin 2 twice a second:
const int inputPin = 2;
void setup() {
Serial.begin(9600);
pinMode(inputPin, INPUT);
}
void loop() {
int level = digitalRead(inputPin);
if (level == HIGH) {
Serial.println("HIGH");
} else {
Serial.println("LOW");
}
delay(500);
}To test it, connect one end of a jumper wire to pin 2. Touch the other end to the 5V pin, and the Serial Monitor shows HIGH. Move it to a GND pin, and it shows LOW.
A pin reads a moment, not a duration
digitalRead takes a single sample. It returns the level at the instant it runs. It says nothing about how long that level has lasted or whether the level just changed. Your sketch must keep that history in variables if it needs it. Detecting a press, as opposed to a held button, depends on this idea.
On the Uno, one digitalRead takes a few microseconds, so loop() can sample a pin thousands of times per second. A delay(500) as in the sketch above means you sample only twice per second and can miss short events.
Matching voltage to the board
The input limits tie directly to the supply voltage:
- On a 5 V board, a signal from 0 V to 5 V is fine.
- On a 3.3 V board, the pins are generally not 5 V tolerant. Feeding 5 V into one can damage it. The ESP32 and the Due are common examples. Check the documentation for your exact board.
- The datasheet's absolute maximum for a pin is about Vcc + 0.5 V. Values beyond that can cause permanent damage even if the chip still seems to work.
Outputs follow the same convention. A pin driven HIGH by digitalWrite sits near Vcc under light load, and a LOW pin sits near 0 V. The recommended current per pin on the ATmega328P is 20 mA, with an absolute maximum of 40 mA. As the load pulls more current, a HIGH output sags below Vcc.
Mirroring an input on an LED
This sketch makes the LED on pin 13 follow the level on pin 2. It combines input and output, and the next chapters build on it.
const int inputPin = 2;
const int ledPin = 13;
void setup() {
pinMode(inputPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int level = digitalRead(inputPin);
digitalWrite(ledPin, level);
}digitalWrite(ledPin, level) works because level already holds HIGH (1) or LOW (0). Use the same jumper test as before. With the jumper on 5V the LED lights, and on GND it turns off.
Common mistakes
| Mistake | Symptom | Fix |
|---|---|---|
| Treating HIGH as exactly 5 V | Confusion on 3.3 V boards | Think of HIGH as "near Vcc" |
| Forgetting `pinMode` | Pin may not behave as expected | Set the mode explicitly in `setup()` |
| Leaving an input unconnected | Random or flickering readings | Always tie the input to a defined level |
| Feeding 5 V to a 3.3 V board | Damage to the pin or chip | Use a level shifter or voltage divider |
| Holding a signal between thresholds | Unreliable readings | Use a source that reaches near 0 V or near Vcc |
By default, pins on the Uno are inputs after reset. Calling pinMode(pin, INPUT) anyway documents your intent and protects you if the pin's mode was changed elsewhere.
Where this leads
A push button is a switch. It connects or disconnects two points, but it does not generate a voltage by itself. Wired the wrong way, it leaves the pin floating whenever it is open. The rest of the tutorial fixes this with pull-down and pull-up resistors, and then deals with contact bounce.
Exercise
An Uno input pin sees 2.2 V. What does digitalRead return, and why is this a poor design?
Show answer
The result is not guaranteed. 2.2 V lies between the guaranteed LOW limit (1.5 V) and the guaranteed HIGH limit (3.0 V) for a 5 V supply, so the pin may read either value and may change between readings. A reliable design holds the signal at or below 1.5 V, or at or above 3.0 V.
Exercise
You change the board from an Uno (5 V) to a 3.3 V board. What is the minimum voltage guaranteed to read as HIGH on a pin with a 0.6 × Vcc threshold, and what must you check before connecting a 5 V signal?
Show answer
The minimum is 0.6 × 3.3 V = 1.98 V. Before connecting a 5 V signal, check whether the board's pins are 5 V tolerant. Many 3.3 V boards are not, so you need a level shifter or voltage divider.
Exercise
Why does the mirror sketch work with digitalWrite(ledPin, level) without comparing level to HIGH?
Show answer
digitalRead returns HIGH or LOW, which are the integers 1 and 0. digitalWrite accepts those same values, so the result of the read can be passed straight through.