Class 6 · Polish and showcase¶
The clock lamp is on the wall and runs by itself. Today you make it reliable and good to look at, get ready to show it, and, if there's time, add sound to the sunrise.
By the end of class
You can run a two-minute demo of the clock lamp that works the first time: the clock, a test sunrise, and a setting changed from a phone.
New parts today¶
| Part | What it's for |
|---|---|
| Stretch: DFPlayer Mini | Plays MP3 files from a microSD card |
| Stretch: small speaker (about 3 W) | Birdsong or white noise |
| Stretch: microSD card | Holds the sound files |
Mission 1 · Make it reliable
Go through this list and fix what fails. Each one is a real way a lamp like this lets you down.
- Power cut. Unplug it for a minute at a random time. Does it come back in the right mode, with your settings and the right time?
- Power-on flash. When it starts, does the strip flash or show random colours? Clear it at the very start of
setup(). - Brightness. Can the page set a brightness above your
MAX_BRIGHTNESS? It shouldn't. - Bad input. What if someone sets "off" earlier than "night light on"? The lamp should do something sensible, not get stuck.
- Clock drift. Compare the hands with your phone. Reset the ring if they're off, and note in your build log how much they drifted since Class 1.
- Dead RTC. If
rtc.lostPower()is true, say so on the page so you know to press "Set the lamp's clock".
Done when
Every item on the list passes, and your build log says which ones failed at first and how you fixed them.
Mission 2 · Showcase ready
Prepare the demo and the poster.
- Demo, two minutes: what it is, the clock (pull the ring to show how it's set), a test sunrise started from the phone, and one setting changed live.
- Poster or slide: the block diagram from the overview page in your own words, your power budget, one photo from each class, and what you'd change next time.
- Credits: Hollow Clock V by shiura (Instructables, CC BY-NC-SA), and the libraries you used. Put the same credits in a comment at the top of your code.
Done when
You run the full demo for Dr. Alvear in two minutes, from a cold start (unplugged), without touching the laptop.
Stretch: sound with the sunrise¶
Tool: DFPlayer Mini
The DFPlayer Mini is a small MP3 player with a microSD slot and a built-in amplifier for a small speaker. The ESP32 sends it commands over a serial connection ("play track 1", "volume 20"), the same kind of serial as the Serial Monitor, on two other pins.
Prepare the card: format the microSD as FAT32. Make a folder called mp3 and name the files 0001.mp3, 0002.mp3, and so on.
Wiring (power off first):
| From (DFPlayer) | To |
|---|---|
| VCC | 5 V supply + |
| GND | GND |
| TX | ESP32 GPIO 16 |
| RX | 1 kΩ resistor → ESP32 GPIO 17 |
| SPK_1, SPK_2 | The two speaker wires |
Add to lib_deps:
Example, not your project: a doorbell that plays track 1 when a button on GPIO 4 is pressed.
#include <Arduino.h>
#include <DFRobotDFPlayerMini.h>
DFRobotDFPlayerMini player;
const int BUTTON_PIN = 4;
void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP);
Serial2.begin(9600, SERIAL_8N1, 16, 17); // RX on 16, TX on 17
if (!player.begin(Serial2)) {
Serial.println("DFPlayer not found. Check wiring and the card.");
while (true) {}
}
player.volume(15); // 0 to 30
}
void loop() {
if (digitalRead(BUTTON_PIN) == LOW) {
player.playMp3Folder(1); // plays /mp3/0001.mp3
delay(1000); // crude: ignore the button for a second
}
}
player.stop() stops the sound. The speaker adds to your power budget: check it still fits.
Mission 3 (stretch) · Birds at sunrise
Find a birdsong or soft-noise track you're allowed to use (Dr. Alvear can help you find a free one), and play it when the sunrise starts. Stop it when the light reaches full, or after a set time. Add a sound on/off setting to the web page.
Done when
A test sunrise started from the phone plays the sound with the light and stops by itself, and turning sound off on the page keeps the next sunrise silent.
If you finish early¶
- Fade the sound in with the light: set the volume from the sunrise progress with
map(). - A "sleep" mode: night light with white noise that fades out over 15 minutes.
- Write the one-page "how to use it" card that would go in the box if you gave this lamp away.
Sign-off with Dr. Alvear
- Reliability list passes
- Two-minute demo from a cold start
- Credits on the poster and in the code
- Build log complete (photo + two sentences for every class)