Control The Led’s on the breadboard with a push button.

As of earlier I forgot to put this post up which shows how you can control any number of LED’s on your breadboard with a push button. My earlier post was also related to a push-button but that tutorial taught you only about the LED on the pin 13, not an external LED.


  1. Arduino.
  2. Resistors 10k and 1k.
  3. Jumper cables.
  4. breadboard.
  5. LED’s.

The CODE :-

int switchPin = 3;

int LEDpin = 12;

int switchState = 0;

void setup()

pinMode(switchPin, INPUT);
pinMode(LEDpin, OUTPUT);


void loop()

switchState = digitalRead(switchPin);

if(switchState == HIGH)





The integer constants ‘switchPin’ and “LEDpin” are initialized with values 3 and 12. Therefore, the setup function declares the digital pins 3 and 12 as ‘INPUT’ and OUTPUT pins respectively. We need to digitally read pin 3 to check the current status of push button i.e whether it is pressed or not. A variable “switchState” is declared to read the current state of the switch. If the push button is pressed, variable ‘switchState’ becomes HIGH or in binary we say ‘1’. i.e ON on pin 12.


Very simple assemble setup. Connect the 10k ohm resistor to the switch and the 1k to the LED. Don’t forget to ground the circuit. You’re ready to go!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s