Musical Message Board


My latest Arduino project is a lcd message board that plays a short tune on power up.

I used the 16×2 lcd with I2C communication and the tone() command.

It plays a few bars of the Little Mermaid tune when powered up and then begins cycling through a series of messages stored in an array. I have tried to explain it in the program comments.

The definition of the notes for the tone command are in an included file call pitches.h

Below is the program and a link to the files on github.


 * project_2014)A002b
 * Use a arduino as a message board
 * Print the messages to a SainSmart IIC/I2C/TWI 
 * 1602 Serial LCD Module Display For Arduino
 * Play a short tune to get attention 

  I2C Connection
 *GND (ground)
 *VCC  (+5)
 *SDA  A4
 *SCL  A5

include libraries and declare initialize commands before void setup()

// include the library code:
#include <Wire.h> //
#include <LiquidCrystal_I2C.h> // A version of the LCD library that allows I2C communication

 * Library for LCD display //
 * see this for how to use
 * new LiquidCrystal is not needed but may be faster
 * Liquidcrystal library at

 *some settings for I2C that works with this LCD from 
 *define I2C variables for LiquidCrystal_I2C.h
 *Address of LCD (Sainsmat shows 0x3f but I found via 
 * it was 0x27
#define I2C_ADDR 0x27 
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

//Initialize LCD
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

#include "pitches.h" // The tone description file

// notes in the melody:
int melody[] = {

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  8, 8, 8, 4,4,8,4,4,4,4,8,8,8,4,4,8,4,4,4  };

void setup() {

  Serial.begin(115200); //setup serial communications for monitoring

  // set up the LCD's number of columns and rows: 
  lcd.begin (16,2,LCD_5x8DOTS);
  // Iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 19; thisNote++) {

    // to calculate the note duration, take one second 
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000/noteDurations[thisNote];
    tone(8, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    // stop the tone playing:
    // initialize the digital pin as an output.
 pinMode(led, OUTPUT);  
void loop() {
   // A guage to tell where you are in the messge display
   // Setup an array with the messge text for each line as a element of the array
  // 1234567890123456
  char* message[]={
    "Welcome to the ",
    "Arduino Badge",
    "message board",
    "It displays two ",
    "lines of text",
    "and sixteen ",
/* Above is the message array. Add elements to increase messages displayed    

int number = 10; // The number of message lines to display
for (int x=0; x < number; x++){
  Serial.println (message[x]); //Print message line #x to serial port
  lcd.clear();// clear LCD 
  lcd.setCursor(0, 0);  //cursor to top left of row 0
  lcd.print(message[x]);     // Print messge line  #x from array
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  lcd.setCursor(0, 1);  //cursor to top left of row 1
  lcd.print(message[x+1]);     // Print messge line #x+1 from array
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW




About jcoffey
This entry was posted in Arduino and tagged , , . Bookmark the permalink.