brambi001
Published © GPL3+

Cool Happy birthday

"Happy Birthday" song with LCD screen 16x2, passive buzzer and colourful leds!

IntermediateProtip1,992
Cool Happy birthday

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Alphanumeric LCD, 16 x 2
Alphanumeric LCD, 16 x 2
×1
Rotary Potentiometer, 10 kohm
Rotary Potentiometer, 10 kohm
×1
Buzzer
Buzzer
×1
LED (generic)
LED (generic)
×4
Resistor 220 ohm
Resistor 220 ohm
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×2
Male/Male Jumper Wires
×22

Story

Read more

Schematics

wiring scheme

Code

Happy Birthday

C/C++
#include <LiquidCrystal.h>
#include "pitches.h"
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int speakerPin = 5; // the speaker attach to
int length = 26; // the nuber of notes
char notes[] = "aabacdaabaecaahfcndbggfcec "; // a space represents a rest
int beats[] = {2, 2, 4, 4, 4, 8, 2, 2, 4, 4, 4, 8, 2, 2, 4, 4, 4, 4, 0, 4, 3, 1, 4, 4, 4, 8, 16 };
int tempo = 75;


void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}
void playNote(char note, int duration) {
char names[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'n' };
int tones[] = { 1515, 1351, 1136, 1205, 1012, 903, 852, 759 }; // play the tone corresponding to the note name

for (int i = 0; i < 8; i++) {
if (names[i] == note) {
playTone(tones[i], duration);
}
}
}
void setup() {
  lcd.begin(16, 2);
  lcd.print("EPPI BORDAI TO");
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(speakerPin, OUTPUT); // initialize the speaker as an output
  pinMode(2, INPUT);
  digitalWrite(2, HIGH);
}

void loop() {
  lcd.setCursor(0, 1);
  lcd.print("MI");
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(2000);
  for (int i = 0; i < length; i++) {
if (notes[i] == ' ') {
delay(beats[i] * tempo); // rest
}
else {
playNote(notes[i], beats[i] * tempo);
// pause between notes

  if (notes[i + 1] != 'n') {
    delay(tempo );
  }
  else {
    i += 2;
  int digitalVal = digitalRead(2);
  if(HIGH == digitalVal)
  {
    digitalWrite(speakerPin, HIGH); // turn the speaker off
  }
  else
  {
    digitalWrite(speakerPin, LOW); // turn the speaker on
  }
}
}
}
}

Credits

brambi001
6 projects • 3 followers

Comments