Sound and audio on microcontrollers lesson plan
Make sound and hear it, on the Uno and the ESP32: square waves with tone(), a sine from PWM, an MCP4725 DAC and its speed limit, I2S to a MAX98357A, recorded clips on a DFPlayer, an INMP441 microphone, and a spaceship voice clock.
Objectives and materials
By the end, students can
- Square waves, PWM samples and a real voltage from a DAC.
- I2S out to a speaker, and recorded clips from a card.
- An I2S microphone: level, decibels and pitch.
- A talking clock built from recorded words.
Materials for the whole unit
- Arduino Uno R3
- Capacitor x 2
- DAC, MCP4725
- DFPlayer Mini MP3 module
- ESP32 DevKit V1
- Frequency counter x 2
- Half breadboard
- I2S amplifier, MAX98357A
- I2S microphone, INMP441
- Oscilloscope
- Piezo speaker
- Pushbutton x 2
- Resistor x 2
- Speaker, 8 ohm
Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.
Making a waveform
Square waves, PWM samples and a real voltage from a DAC.
| Lesson | Time | What students do |
|---|---|---|
| Tone and square wavesA piezo on pin 8 plays a coin pickup, a power-up and a laser sweep: tone() makes a square wave, and the piezo and a frequency counter read the pitch back, to the hundredth of a hertz. | 50 min |
|
| PWM audioA real sine from a pin that can only be HIGH or LOW: 62.5 kHz PWM, a sample table played 8000 times a second by a timer interrupt, and two RC stages that smooth it into 440 Hz. | 50 min |
|
| The MCP4725 DACA 12-bit DAC on I2C puts out a real voltage, no PWM and no filter. Then its speed limit: the sketch measures its own sample rate, and the pitch it can reach. | 45 min |
|
Materials
- Arduino Uno R3
- Capacitor x 2
- DAC, MCP4725
- Frequency counter x 2
- Oscilloscope
- Piezo speaker
- Resistor x 2
Check for understanding
Each student finishes "The MCP4725 DAC" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Fewer points, higher pitch".
Digital audio
I2S out to a speaker, and recorded clips from a card.
| Lesson | Time | What students do |
|---|---|---|
| I2S with the MAX98357AAn ESP32 sends a sine as 16-bit samples over I2S to a MAX98357A, which drives an 8 ohm speaker by itself. Then the amplifier’s gain and shutdown pins, wired on the canvas. | 50 min |
|
| DFPlayer clipsA DFPlayer Mini decodes recorded clips from a microSD card and drives the speaker itself; the Uno sends it commands over serial. Two buttons, a BUSY pin and a spaceship sound board. | 50 min |
|
Materials
- Arduino Uno R3
- DFPlayer Mini MP3 module
- ESP32 DevKit V1
- Half breadboard
- I2S amplifier, MAX98357A
- Pushbutton x 2
- Resistor
- Speaker, 8 ohm
Check for understanding
Each student finishes "DFPlayer clips" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Clips or synthesis".
Listening
An I2S microphone: level, decibels and pitch.
| Lesson | Time | What students do |
|---|---|---|
| The INMP441 microphoneSound in: an INMP441 sends 24-bit samples over I2S to an ESP32, which works out the level in dBFS from their RMS and the pitch from counting zero crossings, and flags when it gets loud. | 50 min |
|
Materials
- ESP32 DevKit V1
- I2S microphone, INMP441
Check for understanding
Each student finishes "The INMP441 microphone" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "What the microphone hears here".
Boss project
A talking clock built from recorded words.
| Lesson | Time | What students do |
|---|---|---|
| Boss: a talking clockA spaceship voice clock: a DFPlayer strings number clips into "ship time is eight o’clock", a button asks for the time, and a piezo chimes ding-dong on the hour. | 60 min |
|
Materials
- Arduino Uno R3
- DFPlayer Mini MP3 module
- Half breadboard
- Piezo speaker
- Pushbutton
- Resistor
- Speaker, 8 ohm
Check for understanding
Each student finishes "Boss: a talking clock" on their own, without opening the hints. The simulator checks 8 of its 8 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it yours".
Teach this unit as a class
Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.
The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.