Show minor edits - Show changes to markup
The pushbutton is a component that connects two points in a circuit when you press it.
We use a pull-down resistor and connect the pushbutton to a digital input pin that we will read when needed.
On the breadboard there is a 10K resitor connected between the input pin and ground.
The pushbutton is a component that connects two points in a circuit when you press it. The example turns on an LED when you press the button.
We connect three wires to the Arduino board. The first goes from one leg of the pushbutton through a pull-up resistor (here 2.2 KOhms) to the 5 volt supply. The second goes from the corresponding leg of the pushbutton to ground. The third connects to a digital i/o pin (here pin 7) which reads the button's state.
When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to 5 volts (through the pull-up resistor) and we read a HIGH. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to ground, so that we read a LOW. (The pin is still connected to 5 volts, but the resistor in-between them means that the pin is "closer" to ground.)

/* Pushbutton
* -----------
/* Basic Digital Read
* ------------------
* Detects if the button has been pressed or not and * lights up the LED if so.
* turns on and off a light emitting diode(LED) connected to digital * pin 13, when pressing a pushbutton attached to pin 7. It illustrates the * concept of Active-Low, which consists in connecting buttons using a * 1K to 10K pull-up resistor.
* Massimo Banzi
* Created 1 December 2005
* copyleft 2005 DojoDave <http://www.0j0.org>
* http://arduino.berlios.de
int LED = 13; int Button = 10; int value = 0;
void setup() {
pinMode(LED, OUTPUT); // initializes digital pin 13 as output pinMode(Button, INPUT); // initializes digital pin 10 as input
int ledPin = 13; // choose the pin for the LED int inPin = 7; // choose the input pin (for a pushbutton) int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output pinMode(inPin, INPUT); // declare pushbutton as input
void loop() {
value = digitalRead(inPin); // reads the value at a digital input digitalWrite(ledPin, value);
void loop(){
val = digitalRead(inPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
}
=]
=]
The prototyping board has been populated with a 10K resitor to make the pull-down and the pushbutton itself.
On the breadboard there is a 10K resitor connected between the input pin and ground.
We use a pull-down resistor and connect the pushbutton to a digital input pin that we will read when needed.
We use a pull-down resistor and connect the pushbutton to a digital input pin that we will read when needed.
The pushbutton is a component that connects two points in a circuit when you press it.
We use a pull-down resistor and connect the pushbutton to a digital input pin that we will read when needed.
The prototyping board has been populated with a 10K resitor to make the pull-down and the pushbutton itself.
/* Pushbutton
* -----------
*
* Detects if the button has been pressed or not and
* lights up the LED if so.
*
* Massimo Banzi
*
*/
int LED = 13;
int Button = 10;
int value = 0;
void setup()
{
pinMode(LED, OUTPUT); // initializes digital pin 13 as output
pinMode(Button, INPUT); // initializes digital pin 10 as input
}
void loop()
{
value = digitalRead(inPin); // reads the value at a digital input
digitalWrite(ledPin, value);
}