Double-clap light switch
Clap twice and the lights come on. Clap twice again to switch them off.
Shop by category
Shop all componentsThe MKR Zero has a microSD slot and an I2S audio bus built in, so it can play WAV files without an MP3 chip. A MAX98357 I2S amplifier turns the digital audio into up to 3 W for a small speaker. The MKR Proto Shield gives a solderable area on top of the board for the amplifier, button and speaker wires, so the build stays neat inside a box.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB 5 V from a phone charger.
doorbell.inoVerify & upload in Electrolark#include <SD.h>
#include <ArduinoSound.h>
SDWaveFile wav;
const int BTN = 7;
void setup() {
pinMode(BTN, INPUT_PULLUP);
Serial.begin(9600);
if (!SD.begin(SDCARD_SS_PIN)) { Serial.println("No SD card"); while (1); }
wav = SDWaveFile("BELL.WAV");
if (!wav) { Serial.println("BELL.WAV missing"); while (1); }
AudioOutI2S.volume(80);
if (!AudioOutI2S.canPlay(wav)) { Serial.println("Unsupported WAV format"); while (1); }
}
void loop() {
if (digitalRead(BTN) == LOW && !AudioOutI2S.isPlaying()) {
AudioOutI2S.play(wav);
delay(300);
}
}
Export again as 16-bit PCM WAV; compressed or 24-bit files are not supported.
Check BCLK, LRC and DIN; swapping BCLK and LRC gives silence.
Raise the volume in the sketch or use a bigger 4 ohm speaker in a box.
Not with this library; convert the sound to WAV first.
Yes, store several WAV files and pick one at random or by day.
Yes, the MKR has a LiPo connector, but a doorbell is best on a charger.
5 parts: Arduino MKR Zero ABX00012 with I2S Audio & SD Card, Arduino MKR Proto Shield TSX00002, MAX98357 I2S 3W Class D Amplifier Module, Speaker 4Ω 3W 2 Inch and Tactile Push Button Switch. On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 2 hours. The build on this page has 5 steps.
No. This page has the complete, tested code (doorbell.ino).
About ₹4,369 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
I2S digital audio; Reading WAV files from SD; Building on an MKR proto shield.
Clap twice and the lights come on. Clap twice again to switch them off.
Plays a friendly ding-dong whenever someone walks into the shop or room.
Beeps and flashes any message in Morse, or key your own by hand.
Turn a membrane keypad into a two-octave piano.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.