Tutorial.Pushbutton History

Show minor edits - Show changes to markup

April 09, 2006, at 04:00 PM by David A. Mellis - Revised to use pin 7, adding picture and description.
Changed lines 3-9 from:

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.

to:

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.)

Changed lines 13-14 from:

/* Pushbutton

 * -----------
to:

/* Basic Digital Read

 * ------------------ 
Changed lines 16-17 from:
 * Detects if the button has been pressed or not and
 * lights up the LED if so. 
to:
 * 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.
Changed lines 21-23 from:
 * Massimo Banzi
to:
 * Created 1 December 2005
 * copyleft 2005 DojoDave <http://www.0j0.org>
 * http://arduino.berlios.de
Changed lines 26-34 from:

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
to:

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
Changed lines 36-39 from:

void loop() {

  value = digitalRead(inPin);   // reads the value at a digital input 
  digitalWrite(ledPin, value);           
to:

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
  }
Changed line 44 from:

=]

to:
 =]
January 06, 2006, at 09:15 AM by 193.222.246.81 -
Changed lines 7-9 from:

The prototyping board has been populated with a 10K resitor to make the pull-down and the pushbutton itself.

to:

On the breadboard there is a 10K resitor connected between the input pin and ground.

January 04, 2006, at 01:25 PM by 193.222.246.39 -
Changed lines 5-6 from:
 We use a pull-down resistor and connect the pushbutton to a digital input pin that we will read when needed.
to:

We use a pull-down resistor and connect the pushbutton to a digital input pin that we will read when needed.

January 04, 2006, at 01:24 PM by 193.222.246.39 -
Added lines 1-36:

Pushbutton

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);           
}

Share