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.
Components Used :
- Arduino Uno
- Button switch x 1
- LED Red x 1
- 220Ω Resistor x 1
- 10KΩ Resistor x 1
- Breadboard x 1
- Breadboard Jumper Wire x 5
- USB cable x 1
Circuit :
Connections are made according to the Circuit given
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 :