Please make the circuit as circuit below the following:
Led circuit Using the Push Button |
- 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.
- 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. - For the LED, connect the negative leg (pin shorter) to GND with a resistor
- 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); } }
0 Response to "Controlling LED with a pushbutton in Arduino"
Post a Comment