Introduction: Arduino Birthday Cake

In this instructable, I'll make a very simple and basic arduino project : a birthday cake !

A birthday cake is displayed on the UTFT screen shield on the arduino and a speaker plays the "Happy birthday" music.

When you blow on the microphone, the candles turn off.

Step 1: Materials

Picture of Materials

For this simple project, you'll need :

- an arduino MEGA

- a speaker or a buzzer

- a microphone module

- a UTFT screen arduino shield

I decided to use an arduino MEGA board for this project for two reasons : it has a lot of memory and it has a lot of pins.

You can't use an arduino UNO for this project, because when the UTFT screen is plugged on it all the pins are hidden (no more are available for the microphone and the speaker), and it has not enough memory (the UTFT library is very big).

Step 2: Wiring

Picture of Wiring

The speaker plugs on pins D40 and GND of the arduino.

The microphone plugs on pins GND ("G"), 5V ("+") and A10 ("A0").

The UTFT screen plugs like a regular shield.

The UTFT screen shield is not fully compatible with the arduino MEGA : the USB plug of the arduino board is too big.

To fix this problem, I plugged the UTFT screen on an other arduino shield (with longer pins), then I plugged both on the arduino.

Step 3: Calibrate the Microphone

Picture of Calibrate the Microphone

To calibrate the microphone, you'll need a screwdriver and your computer.

First, upload the following code to your arduino :

int val = 0;

void setup() {
Serial.begin(9600);
}

void loop() {
val = analogRead(10);
Serial.println(val);
delay(100);
}

Then go to the serial monitor and calibrate the microphone by turning the potentiometer with the screwdriver when there is no sound, the value must be approximately 30~40.

When you blow on the microphone, the value must be higher than 100.

Make sure the value is smaller than 100 when you speak (even loud).

Step 4: The Code

Here's the code of the project.

It displays a birthday cake with candles on the UTFT and plays "Happy birthday" with the speaker. The cake is made with rectangles.

This program requires the UTFT library.

#include <utft.h>
extern uint8_t BigFont[];

//change these values according your screen model
UTFT myGLCD(ITDB28,A5,A4,A3,A2);

int melody[]= {196,196,220,196,262,247,196,196,220,196,294,262,196,196,392,330,262,247,220,349,349,330,262,294,262};
int noteDurations[] = {8,8,4,4,4,2,8,8,4,4,4,2,8,8,4,4,4,4,3,8,8,4,4,4,2};
int val = 0;

void setup() {
  myGLCD.InitLCD();
  myGLCD.setFont(BigFont);

  myGLCD.fillScr(20, 200, 150);        //blue background
  myGLCD.setColor(200, 125, 50);       //brown cake
  myGLCD.fillRect(100, 90, 220, 160);

  myGLCD.setColor(255,255, 255);       //white icing
  myGLCD.fillRect(100, 90, 220, 105);

  myGLCD.setColor(255,50, 50);         //red lines
  myGLCD.fillRect(100, 120, 220, 123);
  myGLCD.fillRect(100, 140, 220, 143);

  myGLCD.setColor(255,255, 0);         //yellow line
  myGLCD.fillRect(100, 130, 220, 133);

  myGLCD.setColor(255,170,255);        //pink candles
  myGLCD.fillRect(128, 70, 132, 90);
  myGLCD.fillRect(158, 70, 162, 90);
  myGLCD.fillRect(188, 70, 192, 90);

  myGLCD.setColor(255,255,0);          //fire of the candles
  myGLCD.fillCircle(130, 62, 5);
  myGLCD.fillCircle(160, 62, 5);
  myGLCD.fillCircle(190, 62, 5);

  myGLCD.setColor(0,255,0);            //happy birthday message
  myGLCD.print("HAPPY BIRTHDAY !",CENTER, 200);

  for (int thisNote = 0; thisNote < 26; thisNote++) {  //plays the melody
    int noteDuration = 1000/noteDurations[thisNote];
    tone(40, melody[thisNote],noteDuration);
    int pauseBetweenNotes = noteDuration * 1.60;
    delay(pauseBetweenNotes);
    noTone(40);
  }
}

void loop() {
  val = analogRead(10);                 //when you blow on the microphone
  if (val > 100) {
    myGLCD.setColor(20, 200, 150);      //turns off the candles
    myGLCD.fillCircle(130, 62, 5);
    myGLCD.fillCircle(160, 62, 5);
    myGLCD.fillCircle(190, 62, 5);

    myGLCD.setColor(255,255,255);       //and displays "congratulations" message
    myGLCD.print("CONGRATULATIONS !!!",CENTER, 10);
    delay(10000);
    myGLCD.clrScr();                    //clear screen after 10s
  }
}

Comments

DIY Hacks and How Tos (author)2015-10-03

That looks like a great idea. And it is reusable.

About This Instructable

1,401views

15favorites

License:

Bio: If you want to talk about electronics in general (more specifically arduino, RPi, ...), programming, 3D printing ... and find many interresting project ideas, you can join ... More »
More by Mr Fox:RGB Minecraft ore lampArduino Birthday Cake
Add instructable to: