Sing happy birthday with LEDs

Description

Learning about blinking LED using Arduino, I wanted to create something that could deliver value/benefit to an observer. A thought came to my mind: sing a song for him/her! By varying the tempo, I was able to make the LEDs blink along with the song, Happy Birthday.  One obstacle I found was that the LED bulbs were too bright to a naked eye and, thus, are in need of appropriate/decorative cover.

 

Components

  • 1 Arduino Uno
  • 1 Breadboard
  • 2 LEDs
  • Jumper wires
  • 1 USB cable
  • 1 220 ohm resistor

Code

// 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); // Happy birthday to you
delay(375);
digitalWrite(13, LOW);
delay(50);
digitalWrite(13, HIGH); //turn the LED on (HIGH is the voltage level)
delay(125); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(50); // wait for a second
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(50);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(50);
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(50);

digitalWrite(13, HIGH); // Happy birthday to you
delay(375);
digitalWrite(13, LOW);
delay(50);
digitalWrite(13, HIGH);
delay(125);
digitalWrite(13, LOW);
delay(50);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(50);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(50);
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(50);

digitalWrite(13, HIGH); // Happy birthday dear my friend
delay(375);
digitalWrite(13, LOW);
delay(50);
digitalWrite(13, HIGH);
delay(125);
digitalWrite(13, LOW);
delay(50);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(50);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(50);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(50);
delay(500);
digitalWrite(13, LOW);
delay(50);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(50);

digitalWrite(13, HIGH); // Happy birthday to you
delay(375);
digitalWrite(13, LOW);
delay(50);
digitalWrite(13, HIGH);
delay(125);
digitalWrite(13, LOW);
delay(50);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(50);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(50);
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(50);
}

 

image1 image2

Lab 01 – Sandeep

Description

The lab was about the basic task of blinking an LED. I connected the output pin 13 and the ground pin to the breadboard. Next I placed a resistor (220 ohms) on the breadboard and connected it to the jumper cable connecting output pin 13. The long leg of the LED was connected to the resistor and the shorter was connected to the jumper cable connecting to the ground pin. I wrote a code to vary the duration of LED blinking using a for loop. This reminded me of the lights we have up at diwali (festival of lights) where a similar random repeating set of LEDs are lit.

Components

  • 1 Arduino Uno R3
  • 1 Breadboard
  • 1 LED
  • 5 jumper cables
  • 1 USB power cable

Code


/*
 * Lab 01: LED Blink
 * Sandeep Pal
 * Prof : Kimiko Ryokai
 * TA : Noura Howell
 * 
 * Description: 
 *  
 * The following code is a modification of the basic example of LED blinking using and Arduino
 * I have made the LEDs blink at a varying rate over time by using a for loop
 * 
 * Materials:
 * 
 * 1 Arduino Uno R3
 * 1 Breadboard
 * 1 LED
 * 5 jumper cables
 * 1 USB power cable
 * 
 * 
 */

 /*
  * Defining output pin
  */
int ledPin = 13;

/*
 * Writing the setup function to initialize the output pin to 13
 */
void setup() {
  pinMode( ledPin, OUTPUT);
}

void loop() {
  // writing a for loop to vary the duration for which the LED should blink
  for(int j =0; j<5;j++){
    int jVal = j*200;
    //writing high voltage to the digital output : 13
    digitalWrite(ledPin, HIGH);
    //modifying the delay based on the loop variable
    delay(1000-jVal);
    //writing low voltage to the digital output : 13
    digitalWrite(ledPin, LOW);
    delay(jVal);
  }
}
 

IMG_20160831_153346