Print Friendly, PDF & Email

Components Required:

1. Arduino Uno – Buy
2. Linux PC/Windows PC (Tested with Windows 10, Ubuntu 14.04 LTS)
3. USB cable A to B –  Buy
4. Breadboard
5. 5 mm LED – Buy
6. 220 Ohms Resistor (color code – Red, Red, Brown)
7. Momentary button or Switch
8. 10K Ohms Resistor (color code – Brown, Black, Orange)
9. Jumper Wires

Procedure:

1. Connect Arduino Uno to PC via the USB cable.

2. Write the following sketches in the Arduino IDE, and upload them one by one.

LEDControl.ino

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(3000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(2000);              // wait for a second
}

ButtonLEDControl.ino

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the 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);
  }
}

 Hardware Connections:

1. LED to Arduino Uno

LEDControl_schem

LEDControl_bb2. Button to Arduino Uno

LEDButtonControl_schem

LEDButtonControl_bb