The finished recorder
Build a voice recorder runs every lesson on the same board:
- The voice: a function generator, a 220 Hz sine, 2 V peak, standing in for a microphone module's output.
- The input: a 1 uF capacitor into A0, held at 2.5 V by two 10 k resistors: the bias.
- The brain: an Arduino Uno, its ADC running free on A0 and Timer 2 interrupting at the sample rate.
- The memory: a 24LC256 EEPROM, 32 KB on I2C (SDA A4, SCL A5) with a 4.7 k pull-up on each line.
- The card: a microSD card on SPI: CS 10, MOSI 11, MISO 12, SCK 13.
- The output: 8-bit PWM at 62.5 kHz on pin 9, smoothed by 1 k and 100 nF, then 1 uF to a piezo that shows the pitch it hears.
- Controls: two pushbuttons, REC on pin 2 and PLAY on pin 3, and a red LED on pin 4 while recording.
The course uses an analog microphone module because the Uno has no I2S. An I2S microphone such as the INMP441 has its own converter and sends finished samples to a board that reads I2S in hardware, like the ESP32.
How it works
Sampling. ADLAR leaves the top 8 bits of each reading in ADCH, so one register read is one sample. The bias puts silence at 128, which is also what silence is in an 8-bit WAV file, so samples go into the file as they are.
Double buffering. Two buffers: the interrupt fills one while loop() stores the other, then they swap. Bigger buffers ride out slow moments; nothing fixes a store that is slower on average than the samples arrive.
Storage limits. One byte a sample, so the bytes a second is the sample rate: 8000 at 8 kHz. On this Uno both buses run in software. The EEPROM takes 64-byte pages at about 3000 bytes a second; the card about 1000. So the recorder samples at 2000 a second into the chip (16 seconds of room), then copies the finished memo to the card.
WAV files. A 44-byte header: RIFF and the size of the rest, WAVE, a fmt chunk (PCM, 1 channel, 2000 Hz, 2000 bytes a second, 8 bits) and a data chunk with the number of sound bytes. Every number is little-endian.
Playback. The player reads the header, runs Timer 2 at its rate and writes each sample to OCR1A. Play it faster and the pitch rises with the speed. At the end it goes back to 128 and takes the PWM off the pin.
Buttons. Internal pull-ups, a 20 ms debounce, and one pressed or released event per change. The pen scans the card at start, so memo numbers only grow.
The course
- The microphone: the bias, the swing, pitch from crossings, too quiet, clipping, aliasing, and how I2S differs.
- Double buffering: the swap, a slow store, overruns, buffer size and the RAM it costs.
- Storage limits: bytes a second, the chip and the card measured, how long a memo fits, and picking a rate.
- WAV files: recording into the chip and saving a real WAV file, the header byte by byte.
- Playback: the header's rate, PWM and the filter, double and half speed, and a quiet end.
- Buttons: pull-ups, hold to record, bounce, and hold to listen.
- Project: a memo pen: numbered memos, a list, playing, room left and deleting.
Every checked step is tested against the running circuit.