Spooky Box of Sweets
Description:
When the box is closed the LED lights flicker. When the lid is opened the LED lights stay switched and a spooky melody sounds.
Electronic parts:
- 1 Arduino
- 1 Protoboard
- 1 9V Battery
- Cables
- 4 LEDS
- 4 (200 ohm) resistors
- 1 (1 kohm) resistor
- 1 photoresistor
- 1 passive buzzer
Materials:
- Wooden box (20 x 20 x 9.5 cm)
- DIN A4 2mm thick plywood sheet
- Dark oak wood dye
- Duct tape
- Masking tape
- Clear wood glue
- Translucid DIN A5 PMMA sheet
Tools:
- Wide paint brush
- Sand paper
- Sanding machine
- Mechanical saw
- Drill with a bit
- Oscilating saw
- Metallic brush
- Laser cutting machine
Supplies
- Sand down the exterior surface of the box.
- Apply the wood dye to the exterior and interior of the box with a brush and let it dry.
- Brush the exterior with a metallic brush in the direction of the grain.
- Cut a rectangular hole into one of the sides of the box.
- Cut out the lettering "sweets" with a laser cutting machine.
- Stick the lettering on top of the hole.
- Cut a rectangular piece of translucid PMMA the size of the lettering and stick it from the inside of the box to the back of the letters.
- Place the arduino and all the setup on the bottom of the box and tape down the cables and the board so they don't move.
- Place the 4 LED's on the back of the PMMA sheet and secure them down with a piece of cardboard and duct tape.
- Place the photoresistor on one of the corners of the box and tape it down with duct tape.
- Cut out a piece of plywood the size of the inside bottom of the box and cut out a little gap on one of the sides so that it can be lifted easily with a finger.
- Dye the piece of plywood so it blends with the finish of the box.
- Cut out 2 1cm x 1cm pieces of plywood and stick them to the inner sides of the box so the plywood sheet can lay on top of them.
- Decorate the top of the box with the leftover letters from the laser cutting.
Arduino Setup
Arduino setup made with Fritzing online app.
Flow Diagram and Code
CODE:
#include "pitches.h" // Include library to make sounds with the buzzer
const int candle = 11; // LED pin number
const int candle1 = 5; // LED pin number
const int candle2 = 9; // LED pin number
const int candle3 = 3; // LED pin number
const int musiPin = 10; // Passive buzzer pin number
int melody[] = {NOTE_CS6, NOTE_FS5, NOTE_FS5, NOTE_CS6, NOTE_FS5, NOTE_FS5, NOTE_CS6, NOTE_D5, NOTE_FS5,
NOTE_CS6, NOTE_FS5, NOTE_FS5, NOTE_CS6, NOTE_FS5, NOTE_FS5, NOTE_CS6, NOTE_D5, NOTE_FS5,
NOTE_C6, NOTE_F5, NOTE_F5, NOTE_C6, NOTE_F5, NOTE_F5, NOTE_C6, NOTE_F5, NOTE_CS5, NOTE_F5,
NOTE_C6, NOTE_F5, NOTE_F5, NOTE_C6, NOTE_F5, NOTE_F5, NOTE_C6, NOTE_F5, NOTE_CS5, NOTE_F5,
NOTE_B5, NOTE_E5, NOTE_E5, NOTE_B5, NOTE_E5, NOTE_E5, NOTE_B5, NOTE_E5, NOTE_C6, NOTE_E5,
NOTE_B5, NOTE_E5, NOTE_E5, NOTE_B5, NOTE_E5, NOTE_E5, NOTE_B5, NOTE_E5, NOTE_C6, NOTE_E5
}; // Array with all the melody's notes
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
}; // Array with the intervals between each notes of the array from above int melody[]
void setup() { //Inicialize and ser initial values
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps. It's used for reading the photoresistor
}
void loop() { // Conecutively repeat this thread of code
int sensorvalue = analogRead (A0); // We recieve the data from the photoresistor and convert it into an integer
Serial.println(sensorvalue); // This is just to make sure that de photoresistor works
if (sensorvalue > 200) { // Condition set when there is light
analogWrite(candle, 255); // Sets the LED 1 to full brightness
analogWrite(candle1, 255); // Sets the LED 2 to full brightness
analogWrite(candle2, 255); // Sets the LED 3 to full brightness
analogWrite(candle3, 255); // Sets the LED 4 to full brightness
int musicPin = 10; // Declare the passive buzzer pin number
for (int thisNote = 0; thisNote < 58; thisNote++) { // Create a loop
// 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(musicPin, melody[thisNote], noteDuration); //Delivers sound to the music pin with the specified note duration and note sound.
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
sensorvalue = analogRead (A0); // We recieve the data from the photoresistor and convert it into an integer
if (sensorvalue < 150) // If the photoresistor is no longer exposed to light...
{
break; // Stop all the reading of the array so the music stops immediately.
}
}
}
else // Otherwise...
{
analogWrite(candle, random(0, 256)); //Set LED 1 to make random flicks of light so that it immitates a candle
delay(25); // A delay of 25ms seems to make it look more like a real candle
analogWrite(candle1, random(0, 256)); //Set LED 2 to make random flicks of light so that it immitates a candle
delay(25); // A delay of 25ms seems to make it look more like a real candle
analogWrite(candle2, random(0, 256)); //Set LED 3 to make random flicks of light so that it immitates a candle
delay(25); // A delay of 25ms seems to make it look more like a real candle
analogWrite(candle3, random(0, 256)); //Set LED 4 to make random flicks of light so that it immitates a candle
delay(25); // A delay of 25ms seems to make it look more like a real candle
}
}
Downloads
Brief Conclusion
The purpose of this project was to design and implement arduino coding and electronics into a functional design.
This project has been useful to understand the amount of code that is behind ordinary components that are used almost on a daily basis like flickering LED lights, simple buzzer speakers and sensors that detect light. We’ve really come to understand how, besides being all independently connected, the coding uploaded to the arduino brings all the components together to work as a whole in order to create a final product.