Button
Overview
Pushbuttons or switches connect two points in a circuit when you press them. This
example turns on the built-in LED on pin 13 when you press the button.
Specification
                                     za
Size: 6 x 6 x 5mm
Temperature: -30 ~ +70 Centigrade
                              ra
                   sm
Hardware required
      Material diagram              Material name                  Number
                                       Button                         1
                                    10KΩ resistor                     1
                                      USB Cable                       1
                                       UNO R3                         1
                                     Breadboard                       1
                                    Jumper wires                   Several
                                          1
Component Introduction
Actually, there are only really two electrical connections, as inside the switch
package pins B and C are connected together, as are A and D.
Principle
Button and number 13 port have the built-in LED simple circuit. To produce a
switch flasher, we can use connect the digital port 13 to the built-in LED and
connect the Button port to number2 port of Uno board. When the switch sensing,
LED twinkle light to the switch signal.
                                     za
Connection
Schematic
                              ra
                   sm
                                         2
Connection diagram
Connect three wires to the board. The first two, red and black, connect to the two long
vertical rows on the side of the breadboard to provide access to the 5 volt supply and
                                        za
ground. The third wire goes from digital pin 2 to one leg of the pushbutton. That same
leg of the button connects through a pull-down resistor (here 10K ohm) to ground. The
other leg of the button connects to the 5 volt supply.
                                ra
When the pushbutton is open (unpressed) there is no connection between the two legs
of the pushbutton, so the pin is connected to ground (through the pull-down resistor)
                    sm
and we read a LOW. When the button is closed (pressed), it makes a connection
between its two legs, connecting the pin to 5 volts, so that we read a HIGH.
You can also wire this circuit the opposite way, with a pullup resistor keeping the input
HIGH, and going LOW when the button is pressed. If so, the behavior of the sketch will
be reversed, with the LED normally on and turning off when you press the button.
If you disconnect the digital I/O pin from everything, the LED may blink erratically. This
is because the input is "floating" - that is, it will randomly return either HIGH or LOW.
That's why you need a pull-up or pull-down resistor in the circuit.
                                            3
Sample code
Note : sample code under the Sample code folder
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;      // the number of the pushbutton pin
const int ledPin = 13;      // the number of the LED pin
// variables will change:
int buttonState = 0;
void setup() {
     // initialize the LED pin as an output:
    pinMode(ledPin, OUTPUT);
    // initialize the pushbutton pin as an input:
    pinMode(buttonPin, INPUT);
}
void loop() {
    // read the state of the pushbutton value:
    buttonState = digitalRead(buttonPin);
    // check if the pushbutton is pressed.
    // if it is, the buttonState is HIGH:
                                         za
    if (buttonState == HIGH) {
         // turn LED on:
                                 ra
         digitalWrite(ledPin, HIGH);
    } else {
         // turn LED off:
                     sm
         digitalWrite(ledPin, LOW);
    }
}
                                               4
Example picture
                  za
                  ra
              sm
                   5
Language reference
Tips:click on the following name to jump to the web page.
If you fail to open, use the Adobe reader to open this document.
const
INPUT
Application effect
When you press the button, the built-in LED will light up, release is extinguished.
******************************************************************************************
* About Smraza:
* We are a leading manufacturer of electronic components for Arduino and Raspberry
Pi.
* Official website: http://www.smraza.com/
* We have a professional engineering team dedicated to providing tutorials and
support to help you get started.
* If you have any technical questions, please feel free to contact our support staff via
                                        za
email at support@smraza.com
* We truly hope you enjoy the product, for more great products please visit our
Amazon US store: http://www.amazon.com/shops/smraza
                                ra
Amazon CA store: https://www.amazon.ca/shops/AMIHZKLK542FQ
Amazon UK store: http://www.amazon.co.uk/shops/AVEAJYX3AHG8Q
                    sm
Amazon DE store: http://www.amazon.de/shops/AVEAJYX3AHG8Q
Amazon FR store: http://www.amazon.fr/shops/AVEAJYX3AHG8Q
Amazon IT store: http://www.amazon.it/shops/AVEAJYX3AHG8Q
Amazon ES store: https://www.amazon.es/shops/AVEAJYX3AHG8Q
******************************************************************************************