//IOT PR - 3
//Interfacing of Switch with Arduino Uno
int buttonstate = 0;
int ledpin = 9;
void setup ()
{
pinMode(2,INPUT); // declare the switch pin as input pin
pinMode(ledpin, OUTPUT);
}
void loop()
{
//read the state of pushbutton value
buttonstate = digitalRead(2);
//check if pushbutton is pressed. if it is the
//buttonstate is high
if (buttonstate == HIGH) {
//turn LED on
digitalWrite(ledpin , HIGH);
} else {
//turn LED off
digitalWrite(ledpin, LOW);
}
delay(10); //Delay a little bit to improve performance
}