Summary of Input Pullup Serial using Arduino
This project demonstrates how to use Arduino's INPUT_PULLUP mode to monitor a pushbutton state. When the button is not pressed, the input reads HIGH due to the internal pull-up resistor, turning the onboard LED on pin 13 on. Pressing the button connects the pin to ground, reading LOW and turning the LED off. Serial communication at 9600 baud is established to send input state data to a computer. The circuit involves connecting one side of the button to ground and the other to digital pin 2 with the pull-up resistor enabled.
Parts used in the INPUT_PULLUP with Arduino Project:
- Arduino Board
- Momentary switch, button, or toggle switch
- Breadboard
- Hook-up wire
This example demonstrates the use of INPUT_PULLUP with pinMode(). It monitors the state of a switch by establishingserial communication between your Arduino and your computer over USB.
Additionally, when the input is HIGH, the onboard LED attached to pin 13 will turn on; when LOW, the LED will turn off.
Circuit
image developed using Fritzing. For more circuit examples, see the Fritzing project page
Connect two wires to the Arduino board. The black wire connects ground to one leg of the pushbutton. The second wire goes from digital pin 2 to the other leg of the pushbutton.
Pushbuttons or switches connect two points in a circuit when you press them. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton. Because the internal pull-up on pin 2 is active and connected to 5V, we read HIGH when the button is open. When the button is closed, the Arduino reads LOW because a connection to ground is completed.
Schematic
Code
In the program below, the very first thing that you do will in the setup function is to begin serial communications, at 9600 bits of data per second, between your Arduino and your computer with the line:
Serial.begin(9600);
Next, initialize digital pin 2 as an input with the internal pull-up resistor enabled:
pinMode(2,INPUT_PULLUP);
The following line make pin 13, with the onboard LED, an output :
pinMode(13, OUTPUT);
Hardware Required
- Arduino Board
- A momentary switch, button, or toggle switch
- breadboard
- hook-up wire
For more detail: Input Pullup Serial using Arduino