Lab 1 Blinking LED

Posted by icheung

icheung's picture

 

Description

Use the Arduino to control a light emitting diode and make it blink in different rate.

Components Used

  • Light Emitting Diode (LED)
  • Resistor

Arduino Code

 

/*
  blink_slow
  Turns on an LED on for 4 seconds, then off for 4 seconds, repeatedly.
 */
 
void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);     
}
 
void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  delay(4000);              // wait for 4 seconds
  digitalWrite(13, LOW);    // set the LED off
  delay(4000);              // wait for 4 seconds
}
 
/*
  blink_fast
  Turns on an LED on for 1/5 of a second, then off for 1/5 of a second, repeatedly.
 */
 
void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);     
}
 
void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  delay(200);              // wait for 1/5 a second
  digitalWrite(13, LOW);    // set the LED off
  delay(200);              // wait for 1/5 a second
}
Lab1 Blinking LED
0
Your rating: None