Project tutorial
SoundBox 2.0

SoundBox 2.0 © GPL3+

Interface a Passive Buzzer playing a full song with a Liquid Crystal Display!

  • 110 views
  • 0 comments
  • 2 respects

Components and supplies

Necessary tools and machines

08wx9696 40
Tape, Electrical
Not necessary
Cardboard Box
Might be needed
Hy gluegun
Hot glue gun (generic)
Not necessary if you have tape

Apps and online services

Ide web
Arduino IDE
The main program for running code for Arduino Boards.
Ide web
Arduino Web Editor
An alternative to Arduino IDE that requires a free online account.

About this project

Intro

There are many amazing things that you could do with an Arduino Board, like play a song using a passive buzzer. However, to make things a bit more challenging, I decided to combine this buzzer and interface it with a 16:2 ratio Liquid Crystal Display. Using the same hardware schematic, you can play an 8 note song or one of the other songs provided. You can even program your own!

My "Happy Birthday" Song

If this project interested you, check out my other projects -

Step 1: Gather the Necessary Parts

For this project, you need -

  • An Arduino Board
  • Some jumper wires
  • A half-breadboard
  • A Passive Buzzer
  • A Liquid Crystal Display (16:2 ratio)

For non-Arduino related materials, you might need -

  • Cardboard
  • Box
  • Tape
  • Glue

This part is really up to you, and it has to do with how you want to make those last touches.

Step 2: Hardware Schematics

Step1: Preparing the Breadboard

For almost any Arduino project, one must start off by connecting the 5V to the positively charged row and by connecting GRND to the negatively charged row.

Step2: Passive Buzzer

The first major step for this project is attaching the passive buzzer. One side of the passive buzzer goes to the negatively charged row (GRND), and the other side goes to Digital Pin 8.

Step3: Liquid Crystal Display Setup

By far the most complicated part of this project, the LCD Display requires many connections. If the picture is not clear, they are listed below in order from the pin 1 to 16 in on the LCD.

Pin 1 --> GRND (Negatively charged row)

Pin 2 --> 5V (Positively charged row)

Pin 3 --> Digital Pin 6

Pin 4 --> Digital Pin 12

Pin 5 --> GRND (Negatively charged row)

Pin 6 --> Digital Pin 11

Pins 7-10 --> No Connections

Pin 11 --> Digital Pin 5

Pin 12 --> Digital Pin 4

Pin 13 --> Digital Pin 3

Pin 14 --> Digital Pin 2

Pin 15 --> 5V (Positively charged row)

Pin 16 --> GRND (Negatively charged row)

And there you have it! Give yourself a pat on the back, because you have officially finished the hardware portion of this project.

Step 3: Software

There are three different codes at the bottom of the page - one with an 8 note melody, one with a happy birthday song (made by me), and one with the melody of the Coffin Dance meme (melody notes and durations by Sohail 8 - here. I added onto the code to make it compatible with the soundbox.)

All of the codes are compatible with the same breadboard schematic, and their only major difference is the int melody part (where you write the notes) and the int noteDurations (where you say how long each note is). However, all of them say the same thing on the LCD (Song complete- Congratulations!) when the program ends.

Below is a step-by-step breakdown of what the code means for the first one (8 note melody).

#include "pitches.h"
#include <LiquidCrystal.h>
int melody[] = {
 NOTE_E5, NOTE_D5, NOTE_C5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_C5, NOTE_C5};
int noteDurations[] = {
 4, 4, 2, 4, 4, 2, 8, 4
};
int Contrast=75;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 

The first two lines here are including the libraries for pitches and the library for Liquid Crystal. The pitches library defines dozens of pitches already so you don't have to, while the Liquid Crystal Library lessens the amount of wires needed to achieve a working LCD display, freeing space and crucial ports on your board.

Int melody is saying the 8 notes in the melody. Think about piano note names. The number at the end is the number octave that it plays. Int Note Durations is saying how long each note is - Four means quarter note, 8 means eighth note, and 2 means quarter note. These two groups of code, int melody and int note durations, are what must be changed to alter how the song sounds.

Int Contrast is the amount of contrast on the Lcd screen. This can be adjusted. LiquidCrystal LCD is saying the pins that the LCD is connected to.

void setup() {
 for (int thisNote = 0; thisNote < 8; thisNote++) {
   int noteDuration = 1000 / noteDurations[thisNote];
   tone(8, melody[thisNote], noteDuration);
   int pauseBetweenNotes = noteDuration * 1.25;
   delay(pauseBetweenNotes);
   noTone(8);
 }
 analogWrite(6, Contrast);
 lcd.begin(16,2);
 lcd.setCursor(0,0);
 lcd.print("Song Complete");
 lcd.setCursor(0,1);
 lcd.print("Congratulations!");
}
void loop() { 
 //Nothing to see here :)
}

The first few lines of code here state that as long as all eight notes haven't been played, the buzzer should continue playing. After that, it says that the pause between notes is 25% greater than the duration of the previously played note itself. At this point, the buzzer has finished and the LCD is about to display its message.

AnalogWrite connects the contrast to pin 6, which is where we connected the contrast pin on the LCD to in the hardware schematics. Lcd.begin starts the LCD screen and says that we are working with one that has a 16:2 ratio. Lcd.set cursor sets the typing to the top left. The next line tells it to write "Song Complete". This process is repeated for the second row, except the second row says, "Congratulations!". These messages can be changed by altering the code under the double-quotes.

And then of course, we have the void loop function, usually the segment with the most code, now the segment with no code at all.

The difference with the 8 note melody and the two other songs can be seen in the int melody and the int noteDurations part.

Below is the int melody and the int NoteDurations for my Happy Birthday song.

int melody[] = {
 NOTE_D5, NOTE_D5, NOTE_E5, NOTE_D5, NOTE_G5, NOTE_FS5, NOTE_D5, NOTE_D5, NOTE_E5, NOTE_D5, NOTE_A5, NOTE_G5, NOTE_D5, NOTE_D5, NOTE_D6, NOTE_B5, NOTE_G5, NOTE_FS5, NOTE_E5, NOTE_C6, NOTE_C6, NOTE_B5, NOTE_G5, NOTE_A5, NOTE_G5};
int noteDurations[] = {
 8, 8, 4, 4, 4, 2, 8, 8, 4, 4, 4, 2, 8, 8, 4, 4, 4, 4, 4, 8, 8, 4, 4, 4, 2,
}; 

As you can see, the notes and note durations are different.

Below is the int melody and int noteDurations for the Coffin Dance meme.

//By sohail8
int melody[] = {
 NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
 NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
 NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
 NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
 NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
 NOTE_D5, NOTE_D5, NOTE_D5, NOTE_D5,
 NOTE_C5, NOTE_C5, NOTE_C5, NOTE_C5, 
 NOTE_F5, NOTE_F5, NOTE_F5, NOTE_F5, 
 NOTE_G5, NOTE_G5, NOTE_G5, NOTE_G5,
 NOTE_G5, NOTE_G5, NOTE_G5, NOTE_G5, 
 NOTE_G5, NOTE_G5, NOTE_G5, NOTE_G5, 
 NOTE_C5, NOTE_AS4, NOTE_A4, NOTE_F4,
 NOTE_G4, 0, NOTE_G4, NOTE_D5,
 NOTE_C5, 0, NOTE_AS4, 0,
 NOTE_A4, 0, NOTE_A4, NOTE_A4,
 NOTE_C5, 0, NOTE_AS4, NOTE_A4, 
 NOTE_G4,0, NOTE_G4, NOTE_AS5,
 NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5,
 NOTE_G4,0, NOTE_G4, NOTE_AS5,
 NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5,
 NOTE_G4, 0, NOTE_G4, NOTE_D5,
 NOTE_C5, 0, NOTE_AS4, 0,
 NOTE_A4, 0, NOTE_A4, NOTE_A4,
 NOTE_C5, 0, NOTE_AS4, NOTE_A4, 
 NOTE_G4,0, NOTE_G4, NOTE_AS5,
 NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5,
 NOTE_G4,0, NOTE_G4, NOTE_AS5,
 NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5};
int noteDurations[] = {
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
 4,4,4,4,
};

This is a full song. All you have to do to put in your own song is to edit this segment of any of the codes and insert the notes/note durations. Or, you can find one online that uses the pitches library.

Flash any of the three codes onto the Arduino and get ready for installation.

Step 4: Final touches and Installation

The final step is to put the whole project in a design. I used a box like this -

And used it to make this design -

I used a power bank attached to the sign and opened it to its on switch and its recharge plug. The final video playing Happy birthday is at the top of the page, but below is it playing coffin dance -

Coffin dance arduino. Code for melody notes and duration courtesy of sohail8

And that's it for now! I would love to see your feedback on the project in the comments section.

Code

8-Note CodeC/C++
The simplest code, an 8-note beat. A good first try to test if your buzzer works, but I recommend using one of the song codes for the project.
//By ShreyanR

#include "pitches.h"
#include <LiquidCrystal.h>

int melody[] = {
  NOTE_E5, NOTE_D5, NOTE_C5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_C5, NOTE_C5};

int noteDurations[] = {
  4, 4, 2, 4, 4, 2, 8, 4
};

int Contrast=75;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  for (int thisNote = 0; thisNote < 8; thisNote++) {
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(8, melody[thisNote], noteDuration);

    int pauseBetweenNotes = noteDuration * 1.25;
    delay(pauseBetweenNotes);
    noTone(8);
  }
  analogWrite(6, Contrast);
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Song Complete");

  lcd.setCursor(0,1);
  lcd.print("Congratulations!");

}

void loop() { 
  //Nothing to see here :)
 }
Happy Birthday CodeC/C++
A code I created that plays the song "Happy Birthday".
//By Shreyan R.

#include "pitches.h"
#include <LiquidCrystal.h>

int melody[] = {
  NOTE_D5, NOTE_D5, NOTE_E5, NOTE_D5, NOTE_G5, NOTE_FS5, NOTE_D5, NOTE_D5, NOTE_E5, NOTE_D5, NOTE_A5, NOTE_G5, NOTE_D5, NOTE_D5, NOTE_D6, NOTE_B5, NOTE_G5, NOTE_FS5, NOTE_E5, NOTE_C6, NOTE_C6, NOTE_B5, NOTE_G5, NOTE_A5, NOTE_G5};

int noteDurations[] = {
  8, 8, 4, 4, 4, 2, 8, 8, 4, 4, 4, 2, 8, 8, 4, 4, 4, 4, 4, 8, 8, 4, 4, 4, 2,
};

int Contrast=75;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  
  for (int thisNote = 0; thisNote < 25; thisNote++) {
    
    int noteDuration = 1250 / noteDurations[thisNote];
    tone(8, melody[thisNote], noteDuration);

    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    noTone(8);
  }
  
  analogWrite(6, Contrast);
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Song Complete");

  lcd.setCursor(0,1);
  lcd.print("Congratulations!");

}

void loop() { 
  //Nothing to see here :)
 }
Coffin Dance Melody NotesC/C++
It plays the Coffin Dance Melody, a full song. Notes and note durations by sohail8.
//Notes and note durations by sohail8

#include "pitches.h"
#include <LiquidCrystal.h>

int melody[] = {
  NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
  NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
  NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
  NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
  NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
  NOTE_D5, NOTE_D5, NOTE_D5, NOTE_D5,
  NOTE_C5, NOTE_C5, NOTE_C5, NOTE_C5, 
  NOTE_F5, NOTE_F5, NOTE_F5, NOTE_F5, 
  NOTE_G5, NOTE_G5, NOTE_G5, NOTE_G5,
  NOTE_G5, NOTE_G5, NOTE_G5, NOTE_G5, 
  NOTE_G5, NOTE_G5, NOTE_G5, NOTE_G5, 
  NOTE_C5, NOTE_AS4, NOTE_A4, NOTE_F4,
  NOTE_G4, 0, NOTE_G4, NOTE_D5,
  NOTE_C5, 0, NOTE_AS4, 0,
  NOTE_A4, 0, NOTE_A4, NOTE_A4,
  NOTE_C5, 0, NOTE_AS4, NOTE_A4, 
  NOTE_G4,0, NOTE_G4, NOTE_AS5,
  NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5,
  NOTE_G4,0, NOTE_G4, NOTE_AS5,
  NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5,
  NOTE_G4, 0, NOTE_G4, NOTE_D5,
  NOTE_C5, 0, NOTE_AS4, 0,
  NOTE_A4, 0, NOTE_A4, NOTE_A4,
  NOTE_C5, 0, NOTE_AS4, NOTE_A4, 
  NOTE_G4,0, NOTE_G4, NOTE_AS5,
  NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5,
  NOTE_G4,0, NOTE_G4, NOTE_AS5,
  NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5};

int noteDurations[] = {
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
  4,4,4,4,
};

int Contrast=75;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  
  for (int thisNote = 0; thisNote < 112; thisNote++) {
    
    int noteDuration = 750 / noteDurations[thisNote];
    tone(8, melody[thisNote], noteDuration);

    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    noTone(8);
  }
  
  analogWrite(6, Contrast);
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Song Complete");

  lcd.setCursor(0,1);
  lcd.print("Congratulations!");

}

void loop() { 
  //Nothing to see here :)
 }
LiquidCrystal.hC/C++
This is the Liquid Crystal Library used in the project. It was made by Arduino and Adafruit.
//By Arduino/Adafruit

#ifndef LiquidCrystal_h
#define LiquidCrystal_h

#include <inttypes.h>
#include "Print.h"

// commands
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80

// flags for display entry mode
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00

// flags for display on/off control
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00

// flags for display/cursor shift
#define LCD_DISPLAYMOVE 0x08
#define LCD_CURSORMOVE 0x00
#define LCD_MOVERIGHT 0x04
#define LCD_MOVELEFT 0x00

// flags for function set
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00

class LiquidCrystal : public Print {
public:
  LiquidCrystal(uint8_t rs, uint8_t enable,
		uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
		uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
  LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
		uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
		uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
  LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
		uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
  LiquidCrystal(uint8_t rs, uint8_t enable,
		uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);

  void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
	    uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
	    uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
    
  void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);

  void clear();
  void home();

  void noDisplay();
  void display();
  void noBlink();
  void blink();
  void noCursor();
  void cursor();
  void scrollDisplayLeft();
  void scrollDisplayRight();
  void leftToRight();
  void rightToLeft();
  void autoscroll();
  void noAutoscroll();

  void setRowOffsets(int row1, int row2, int row3, int row4);
  void createChar(uint8_t, uint8_t[]);
  void setCursor(uint8_t, uint8_t); 
  virtual size_t write(uint8_t);
  void command(uint8_t);
  
  using Print::write;
private:
  void send(uint8_t, uint8_t);
  void write4bits(uint8_t);
  void write8bits(uint8_t);
  void pulseEnable();

  uint8_t _rs_pin; // LOW: command.  HIGH: character.
  uint8_t _rw_pin; // LOW: write to LCD.  HIGH: read from LCD.
  uint8_t _enable_pin; // activated by a HIGH pulse.
  uint8_t _data_pins[8];

  uint8_t _displayfunction;
  uint8_t _displaycontrol;
  uint8_t _displaymode;

  uint8_t _initialized;

  uint8_t _numlines;
  uint8_t _row_offsets[4];
};

#endif
Pitches.hC/C++
The pitches library for the passive buzzer by Arduino.
//By Arduino

/*************************************************
 * Public Constants
 *************************************************/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978

Schematics

Full Project Schematics
Use this for the Hardware Portion
Screenshot 2020 05 16 at 2 56 40 pm db6wkgj8wo

Comments

Similar projects you might like

Arduino Bluetooth Robot for Android Device

Project showcase by aip06

  • 5,437 views
  • 2 comments
  • 20 respects

Morse Encoder & Displayer

Project showcase by rajdakin

  • 4,105 views
  • 4 comments
  • 14 respects

Android App-Based Home Automation System Using IOT

Project tutorial by Team Autoshack

  • 55,790 views
  • 22 comments
  • 151 respects

Arduino Tutorial : Mini Piano

Project tutorial by the lonely programmer

  • 21,414 views
  • 6 comments
  • 31 respects

Arduino Audio Reactive Desk Light

Project tutorial by Haziq Azri

  • 23,674 views
  • 6 comments
  • 48 respects

Unravel Preset Piano Easy Arduino (Even a Ghoul Can Make It)

Project in progress by ExeCuteLi

  • 16,285 views
  • 13 comments
  • 33 respects
Add projectSign up / Login