Controlling LED with a pushbutton in Arduino

              This experiment is to control the on / off switch with its LED pushbutton switch. If the button is pressed, the LED will light up, if released, LED back extinguished.

              Please make the circuit as circuit below the following:

Led circuit Using the Push Button

Led circuit Using the Push Button



  1.  Prepare the LED and pushbutton on the project board. Because as pushbutton has 4 legs, each separately, then please plug pushbutton in the middle lane project-kainya board so that the legs are not connected.
  2.  One leg pushbutton connected to the GDN on board the project, while the partner's feet is connected to pin 2 on the Arduino board. How do I know a couple of the legs on a pushbutton? You can check with AVO meter.

     Setting AVO meter to calculate the resistance, then check each pin pushbutton with the probe. If the button is pressed the needle moves deviate AVO meter, meaning the pair of legs.
  3.  For the LED, connect the negative leg (pin shorter) to GND with a resistor
  4. Walking positive (longer leg) is connected to pin 8 on the Arduino board with a jumper.


Let's try the following program:

Controlling LED with a pushbutton 


// www.IOISALMAN.com
// Pin 2 as an input and as an output pin 8
const int pinButton = 2;
const int pinLED = 8;

void setup () {
   pinMode (pinButton, INPUT);
   pinMode (pinLED, OUTPUT);
  
   // Turn on pull-up resistor
   digitalWrite (pinButton, HIGH);
}

void loop () {
   if (digitalRead (pinButton) == LOW) {
     digitalWrite (pinLED, HIGH);
   } Else {
     digitalWrite (pinLED, LOW);
   }
}

for an explanation of the above program I will explain in the next post

Subscribe to receive free email updates:

0 Response to "Controlling LED with a pushbutton in Arduino"

Post a Comment