Why Use Resistors with Push Buttons and Switches with Arduino
This tutorial explains why using a resistor with push buttons and switches connected to an Arduino is crucial for reliable operation. Understanding this concept is fundamental for any Arduino project involving user input. This knowledge prevents unexpected behavior and ensures your projects function correctly. Here are some project ideas where this knowledge is essential:
- Simple on/off switch for an LED
- Interactive game controller
- Remote control for home appliances
- Security system with push-button activation
Let's explore the reasons behind using resistors in these circuits.

Hardware/Components
The core components needed for this project are minimal: an Arduino board, a push-button switch, and a resistor (greater than 300 ohms). The resistor's value isn't critical; values like 1kΩ, 10kΩ, or even 100kΩ will generally work fine (in video at 00:41).
Wiring Guide
There are two primary wiring configurations (in video at 00:30):
- Configuration 1: Connect the push button between the Arduino pin and +5V. The other side of the push button is connected to ground through a resistor. When the button is pressed, the pin reads HIGH; when released, it reads LOW.
- Configuration 2: Connect the push button between the Arduino pin and ground. The other side of the push button is connected to +5V through a resistor. When the button is pressed, the pin reads LOW; when released, it reads HIGH.

A visual wiring diagram would be beneficial here.
Code Explanation
The Arduino code utilizes the pinMode() function to configure the pin as an input. The crucial part is the use of INPUT_PULLUP (in video at 04:06, 04:23). This internal pull-up resistor eliminates the need for an external resistor in certain configurations, simplifying the wiring. The digitalRead() function reads the state of the pin, and a simple if-else statement determines whether the button is pressed (LOW) or not (HIGH) (in video at 08:34).
pinMode(2, INPUT_PULLUP); // Configures pin 2 as input with internal pull-up resistor
int pushButton = digitalRead(2); // Reads the state of pin 2
if (pushButton == LOW) {
// Button is pressed
} else {
// Button is not pressed
}
Live Project/Demonstration
The video demonstrates both wiring configurations and their respective behaviors. It highlights the issues that can arise when the resistor is omitted, such as erratic readings due to noise and capacitive coupling (in video at 06:18, 06:39, 07:21). The demonstration clearly shows the stable and reliable operation achieved with the resistor in place (in video at 08:08).
Chapters
- [00:00] Introduction
- [00:30] Wiring Configurations
- [04:12] Code Explanation using INPUT_PULLUP
- [05:36] Removing the Resistor: Practical Demonstration
- [08:33] Code Explanation
Images
Things you might need
-
Amazon
Resources & references
No resources yet.
Files📁
No files available.
