View on GitHub

Kerala-IoT-Challenge

Experiment 4 : Button Controlled LED

Description :

In this experiment we use a button to control the LED. A Push Button switch is a type of switch which consists of a simple electric mechanism to turn something on or off.
button

Components Used :

Circuit :

Connections are made according to the Circuit given
Expriment 4

Code :

#define ledpin 11 // initialize pin 11
#define  inpin 6 // initialize pin 6
int val;// define val
void setup()
{
pinMode(ledpin,OUTPUT);// set LED pin as “output”
pinMode(inpin,INPUT);// set button pin as “input”
}
void loop()
{
val=digitalRead(inpin);// read the level value of pin 7 and assign if to val
if(val==LOW)// check if the button is pressed, if yes, turn on the LED
{ 
  digitalWrite(ledpin,LOW);
}
else
{ 
  digitalWrite(ledpin,HIGH);
}
}

Video :

The output of this experiment would be like this :