Introduction: Arduino Button

HI friends. Today, in this instructables I am going to show you how to use a button with Arduino. It is a very baseic project which every Arduino beginner must know. So, lets start this easy project !!!

Step 1: Components Needed

1.) Arduino UNO

2.) USB B Type cable

3.) Laptop with Arduino IDE installed

4.) Breadboard

5.) 10k ohm resistor

6.) Pushbutton

7.) 3 Wires

8.) LED

Step 2: The Schematic

The following circuit diagram is made with the help of Express PCB software.

Step 3: The Code

Copy the following code in Arduino IDE and upload it in your Arduino.

/* Basic Digital Read
* ------------------ * * turns on and off a light emitting diode(LED) connected to digital * pin 13, when pressing a pushbutton attached to pin 7. */

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(){ 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 } }

Step 4: The Function

When the pushbutton is pressed, it sends a high or true signal to Arduino. The arduino then receives this data and give power to its 13 pin where the LED is attached. The LED then lights up. Same happens when the pushbutton is not pressed. It keeps sends a low or false signal to Arduino. The arduino then receives this data and does not give power to its 13 pin where the LED is attached. The LED, therefore, remains off.

Comments

About This Instructable

750views

10favorites

License:

More by soardr:Powering ESP8266-01 Using BatteriesSoil Water Level Status Using ESP8266Simple LED Blink Using ESP8266
Add instructable to: