Menu
CoddyTech

Pull-Down Resistor

Part of the Inputs section of Coddy's Arduino journey. Lesson 2 of 22.

An input pin connected to nothing is floating. It picks up electrical noise from the air and from your hand, so it reads HIGH or LOW at random. On this simulated board a floating pin reads LOW, but a real one flickers. Every input needs something that holds it at a known level.

This circuit wires the button the other way round: it joins pin 2 to 5V. A 10k ohm resistor joins pin 2 to GND. That resistor is a pull-down: with the button up, it gently pulls the pin LOW. Pressing the button connects the pin straight to 5V, which is much stronger than the resistor, so the pin reads HIGH.

The resistor does the holding, so the pin is a plain input:

pinMode(2, INPUT);

if (digitalRead(2) == HIGH) {
  // pressed: the button joins the pin to 5V
}
challenge icon

Challenge

Easy

The button joins pin 2 to 5V, with a 10k ohm pull-down to GND. The LED is on pin 13. Light the LED while the button is held:

  • set pin 2 to INPUT
  • when pin 2 reads HIGH, turn the LED on, otherwise turn it off

Press Run, hold the button, then Check.

Try it yourself

const int buttonPin = 2;
const int ledPin = 13;

void setup() {
  pinMode(ledPin, OUTPUT);
  // set the button pin to INPUT
}

void loop() {
  // light the LED while pin 2 reads HIGH
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Inputs

Practice on your own: Arduino playground