Basic of Arduino..Interfacing Push Button to Arduino
- Circuit Diagram
- Components list:
- Program:
- Output:
1.Resisters (1k and 100ohm)
2.LED
3.Push button
4.Arduino uno board
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int buttonState = 0; // variable for reading the pushbutton status
void setup()
{
pinMode(13, OUTPUT);// initialize the LED pin as an output:
pinMode(2, INPUT);// initialize the pushbutton pin as an input:
}
void loop()
{
buttonState = digitalRead(buttonPin);// read the state of the pushbutton value:
if (buttonState == LOW)
{
digitalWrite(13, HIGH);// turn LED on:
}
else
{
digitalWrite(13, LOW); // turn LED off:
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
watch this video for output.
Comments
Post a Comment