top of page

Blinking An Led using A Push Button.

In this tutorial, I'm going to show you how to blink an led using a push button.


ITEMS REQUIRED

1 x LED

3 x Cables

1 x 330 Ω Resistor

1 x Push Button

1 x Arduino board

1 x USB cable

1 x Computer with Arduino software installed (http://www.arduino.cc/en/Main/software if you haven't already got it)

1 x Breadboard




Circuit Diagram 1

 

Step 1:

Connect the circuit as per the circuit diagram in figure 1


Circuit Discription:

In the the circuit diagram you can see that pin 2 is connected to the positive end of the diode followed by a resisitor, this is to limit the current passing through the diode so that the diode does not get damaged, here pin to must be declared as the output pin since it will be controlling the diode.The switch is used as an input by which we can control the led, It is connected to pin no 8 of the arduino.The pull up resistor is used to ensure a logic level at a pin, which results in state wherein the input/output voltage is nonexistence driving signal.



 

Step 2:

Open a new window in the arduino terminal and type the code.


 

/* sketch 1

turn on a LED when the button is pressed

turn it off when the button is not pressed (or released)

*/

int pinButton = 8; //the pin where we connect the button

int LED = 2; //the pin we connect the LED


void setup() {

pinMode(pinButton, INPUT); //set the button pin as INPUT

pinMode(LED, OUTPUT); //set the LED pin as OUTPUT

}


void loop() {

int stateButton = digitalRead(pinButton); //read the state of the button

if(stateButton == 1) { //if is pressed

digitalWrite(LED, HIGH); //Change the state of led to HIGH

} else { //if not pressed

digitalWrite(LED, LOW); //Change the state of led to LOW

}

}


 

Upload the code to the arduino and check the output.you can check out previous blog which only show how to blink an led using an arduino in this Link



25 views

Comments


bottom of page