Clap once, lamp on. Clap again, lamp off. The famous sci-fi gadget, built by you, working tonight.
Enter the access code from the card inside your Beginner Kit (or from your GAMERIFT order email). Your name appears on every page and printout as the licensee.
Don't have a kit yet? Get the Beginner Kit, the code ships inside. Lost your code? Contact us with your order number.
In 1985 a gadget called The Clapper sold millions: clap twice and your lamp obeyed. People thought it was magic. It was a microphone, a threshold and a switch, three things you already understand. Today you build it: the kit's sound sensor hears the sharp crack of a clap, and your code flips the lamp. You will also meet a genuinely important idea, state, the machine's memory of where things stand.
Time: 45–60 minutes · Difficulty: 3/5 · You need: Lesson 03 done (the toggle remix helps a lot).
This module does not send you a raw number. It has a tiny comparator circuit and a sensitivity dial (the blue square with a cross-head screw). It listens, compares the sound to the dial's setting, and answers a simple yes or no on its DO (digital out) pin. You met analog sensors that mumble numbers; this one has made up its mind before it speaks. Both kinds exist everywhere in industry.
A clap is a moment, but "the lamp is on" is a situation that lasts. Your program needs a variable that remembers the situation between claps: bool lampOn. Flipping it with lampOn = !lampOn (the ! means "not") is called toggling state. Every light switch, pause button and door lock in software works exactly like this.
To your ear a clap is one sound. To a sensor checking thousands of times a second, it is a burst of many spikes, and a naive program toggles the lamp ten times per clap, ending wherever it pleases. The fix is a cooldown: after acting once, ignore the sensor for a moment. You saw this with the button bounce; sound is bouncier.
Unplug the USB. Push the module's pins into the breadboard, wire from its rows. The pins are labelled on the board, read YOURS (usually DO, +, G, and sometimes AO which we ignore today).
| From | To | Why |
|---|---|---|
| Module DO pin | R3 pin 7 | The yes/no answer wire |
| Module + pin | R3 5V | Power |
| Module G pin | R3 GND | Ground |
| R3 pin 13 | 220Ω resistor → LED long leg | The lamp |
| LED short leg | R3 GND | Loop complete |
// GAMERIFT Beginner Kit, Lesson 10: The Clapper // A clap toggles the lamp. State + cooldown do the real work. const int soundPin = 7; const int lampPin = 13; bool lampOn = false; // the machine's memory void setup() { pinMode(soundPin, INPUT); pinMode(lampPin, OUTPUT); Serial.begin(9600); } void loop() { if (digitalRead(soundPin) == HIGH) { // the sensor heard something sharp lampOn = !lampOn; // flip the memory digitalWrite(lampPin, lampOn); // make the lamp match it Serial.println(lampOn ? "CLAP! Lamp on" : "CLAP! Lamp off"); delay(400); // cooldown: one clap = one flip } }
Now tune it, this is the important part:
== HIGH to == LOW. Reading the sensor's dialect is real engineering.millis(), look it up, it is a timestamp in milliseconds.Film the clap-on, clap-off moment for your lesson log, it is the most demo-able build in the course. Stuck? Contact us with a photo and tell us what the Serial Monitor says.
Ears, done. Next lesson your machine gets a watchful eye: an invisible infrared beam that notices when something comes close, and barks about it. The last skill before your final build.