Arduino Song Player Using 555 and Decade Counter
by ishreetgrewal1 in Circuits > Arduino
352 Views, 1 Favorites, 0 Comments
Arduino Song Player Using 555 and Decade Counter
Here we will be using a decade counter along with a 555 timer to accordingly light LEDS to the beat of the song Happy Birthday. It is a fun project that allows to grasp a full understanding of how these components work
Supplies
*Arduino
*Jumper Wires
*LCD Display
*Potentiometer
*555 timer
*4017 Johnson Decade Counter
*Capacitor
*10 LEDS
*Polarized Capacitor
* 13 1K resistors
*Buzzer
Step 1: Wiring
Here is a schematic that can be followed to build this circuit; or you could always refer to the tinkercad circuit.
1. 555 Timer
The 555 timer will produce pulses that will act as a clock to the decade counter. Here are what each of the pins should be connected to.
GND = Ground Rail
Power = Power Rail
Trigger = Threshold pin (on 555 timer)
Trigger = Also connected to Wiper pin on potentiometer
Out = Power Rail
Reset = Power Rail
Control Voltage = Capacitor pin 1
Discharge = Power Rail
Discharge = Terminal 2 in potentiometer
2. Decade Counter
pin 3 goes to the 1st resistor
pin 2 goes to the 2 nd resistor
pin 4 goes to the 3 rd resisitor
pin 7 goes to the 4 th resistor
pin 10 goes to the 5 th resisitor
pin 1 goes to the 6 th resistor
pin 5 goes ot the 7 th resistor
pin 6 goes to the 8 th resistor
pin 9 goes to the 9 th resisitor
pin 11 goes to the 10 th resistor
3. LEDS
Connect the + leg of the LED to the resistor and the negative leg to GND
4. Buzzer
connect the + side to an Arduino pin (I did pin 6) and the negative side to GND rail
5. LCD Display
Here are which each of the pins should be connected to for the LCD Display
pin 1 = GND
pin 2 = Power
pin 3 = GND
pin 4 = 12
pin 5 = GND
pin 6 = 11
pin 11 = 5
pin 12 = 4
pin 13 = 3
pin 14 = 2
pin 15 = Power
pin 16 = GND
6. Potentiometer, Capacitor, Polarized capacitor
Capacitor - Terminal 1 = Control Voltage in 555 timer
Terminal 2 = GND
Potentiometer -
Terminal 1 = Connected to terminal 2 (within the potentiometer)
Wiper = Positive side of Polarized capacitor
Terminal 2 = Discharge pin (555 timer)
Polarized Capacitor -
Negative Side = GND
Positive Side = Wiper (in potentiometer)
Step 2: Code
Here is the code. I decided to use a simple song for my code; happy birthday, but any song can be used (but the code will need to be altered accordingly).
The code is quite straight forward. Basically what is happening is that the notes for the Happy Birthday song are played through the buzzer while the LEDs are lighting up accordingly with "Happy Birthday" displaying on the LCD Display.
#include
LiquidCrystal lcd(12,11,5,4,3,2);
int speakerPin = 6;
int length = 28; // the number of notes
char notes[] = "GGAGcB GGAGdc GGxecBA yyecdc";
int beats[] = { 2, 2, 8, 8, 8, 16, 1, 2, 2, 8, 8,8, 16, 1, 2,2,8,8,8,8,16, 1,2,2,8,8,8,16 };
int tempo = 150;
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[] = {'C', 'D', 'E', 'F', 'G', 'A', 'B',
'c', 'd', 'e', 'f', 'g', 'a', 'b',
'x', 'y' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014,
956, 834, 765, 593, 468, 346, 224,
655 , 715 };
int SPEE = 5;
// play the tone corresponding to the note name
for (int i = 0; i < 17; i++) {
if (names[i] == note) { int newduration = duration/SPEE; playTone(tones[i], newduration);
}
}
}
void setup() {
pinMode(speakerPin, OUTPUT); lcd.begin(16,2);
}
void loop() { lcd.clear(); lcd.setCursor(0,0); 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
delay(tempo); lcd.print ("Happy Birthday!!"); lcd.setCursor(2,1); lcd.print(""); }
}