HOWTO · Arduino
Arduino Pull-Down Resistor
Learn how to wire an Arduino pull-down resistor and switch, choose a resistor value, and read the input in a sketch.
On this page
To wire an Arduino pull-down resistor, connect a resistor from a digital input junction to GND, then connect a switch between that junction and a supply voltage compatible with the board’s input pin. The input reads LOW while the switch is open and HIGH while it is closed. Use 5V only when the board’s input is 5V-tolerant; a 3.3V-only input needs a compatible 3.3V supply. This guide explains the wiring, resistor choice, and code for reading the switch.
Why a Pull-Down Resistor Is Needed
A microcontroller input draws very little current. When a switch leaves the input disconnected, electrical noise can change its voltage and produce unpredictable readings; this is called a floating input. A pull-down resistor connects the input to GND while the switch is open, holding it at LOW. Closing the switch connects the same input junction to the board supply, so the pin reads HIGH.
Wire an External Pull-Down Resistor to a Digital Input
Build the circuit so the input pin, one switch terminal, and one resistor terminal meet at a single junction:
- Choose a supply voltage that the board’s input pin can safely accept. Connect one terminal of a push button or switch to that supply. Use the board’s 5V pin only if the input is 5V-tolerant; for a 3.3V-only input, use a compatible 3.3V supply.
- Connect the other switch terminal to digital pin 2. This point is the input junction.
- Connect a resistor from that junction to GND.
The source article gives 1 kΩ to 100 kΩ as a starting range. The suitable value depends on the board and circuit, so check the board’s electrical specifications and account for noise and current requirements. A very low resistance can allow excessive current through the switch when it closes. The resistor belongs between the input junction and GND; do not connect the supply directly to GND. In the diagram below, the +5V label applies only when the board’s input is 5V-tolerant. Otherwise, use a board-compatible supply voltage at that switch connection.
Read the Switch in an Arduino Sketch
Set the pin mode to INPUT and read the switch with digitalRead. This complete sketch prints a message for each switch state. The small compatibility section lets the same source compile as a host-side demonstration; in the Arduino IDE, the board core supplies these names and the IDE supplies the program entry point. The host demonstration uses a fixed HIGH reading, so its printed line illustrates the closed-switch branch; it does not test hardware.
#ifndef ARDUINO
#include <iostream>
constexpr int INPUT = 0;
constexpr int LOW = 0;
constexpr int HIGH = 1;
struct SerialPort {
void begin(long) {}
void println(const char* message) { std::cout << message << '\n'; }
} Serial;
void pinMode(int, int) {}
int digitalRead(int) { return HIGH; }
void delay(unsigned long) {}
#endif
const int switchPin = 2;
void setup() {
pinMode(switchPin, INPUT);
Serial.begin(9600);
}
void loop() {
int switchState = digitalRead(switchPin);
if (switchState == HIGH) {
Serial.println("Switch closed");
} else {
Serial.println("Switch open");
}
delay(200);
}
#ifndef ARDUINO
int main() {
setup();
loop();
}
#endif
Switch closed
With the external pull-down wired as described, digitalRead returns LOW for an open switch and HIGH for a closed switch. Put the action for each state in its corresponding branch. For more conditional logic, see Arduino if Statement. If your sketch needs to wait for a user action, see How to Wait for Input in Arduino.
Use an Analog Input with an External Pull-Down Resistor
You can connect the same circuit to an analog input such as A0 instead of a digital pin. Keep the resistor between the input junction and GND, and connect the switch between that junction and a supply voltage compatible with the analog input. Use 5V only if that input is 5V-tolerant. The analog reading is near the ground end of the range with the switch open and rises toward the board’s supply reading when the switch closes. Exact counts depend on the board’s analog-to-digital converter and reference voltage.
For an Arduino sketch, read the pin with analogRead and compare the result with a threshold chosen for the board and circuit. For example, the condition reading >= threshold represents the closed switch when the switch connects the junction to the supply. Choose the threshold from measurements; a value such as 512 is not suitable for every setup. This analog example is board-specific and is not included in the host-side demonstration above.
Use the Internal Pull-Up as an Alternative
An internal pull-up is an alternative circuit, rather than an external pull-down. It uses the microcontroller’s built-in resistor. Connect the switch between the digital input and GND, then configure the pin with INPUT_PULLUP. The open switch reads HIGH; pressing it connects the pin to GND and reads LOW, reversing the external pull-down logic.
In the Arduino sketch, use pinMode(switchPin, INPUT_PULLUP) and treat digitalRead(switchPin) == LOW as the pressed state. This behavior depends on the Arduino core and physical wiring, so it is not represented by the host-side demonstration above.