Data Sheet

ARDUINO CODE
LESSON 5
| 29
*Open Button example (File - Examples - 02.Digital -
Button).
const int buttonPin = 3;
const int ledPin = 13;
int buttonState = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if(buttonState == LOW) // Push button is pressed
digitalWrite(ledPin, HIGH);
else digitalWrite(ledPin, LOW);
}
RESULT
If push button is pressed, LED on Maker UNO will turn on and if push button is released,
LED will turn o.
*Note : You may use the built-in push button on pin number 2 by using
pinMode(2,INPUT_PULLUP);