GAMERIFTRobotics & Coding Shop kits
HomeKitsFor schoolsAboutGAMERIFT Store ↗
Beginner Kit · Lesson 10 of 12

The Clapper

Clap once, lamp on. Clap again, lamp off. The famous sci-fi gadget, built by you, working tonight.

Unlock your lessons

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.

LICENSED TO , PERSONAL USE · © GAMERIFT

BRIEF Give the machine ears

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).

KIT What you need

Concept · A sensor with its own opinion

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.

Concept · State, the machine's memory

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.

Concept · One clap is many bangs

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.

BUILD Wire it

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).

FromToWhy
Module DO pinR3 pin 7The yes/no answer wire
Module + pinR3 5VPower
Module G pinR3 GNDGround
R3 pin 13220Ω resistor → LED long legThe lamp
LED short legR3 GNDLoop complete

CODE Program it

// 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:

  1. Upload, open the Serial Monitor, and clap about a metre away. Nothing? The dial is set too strict.
  2. Give the blue dial a small turn with the little screwdriver (or ask an adult for one), then clap again. Repeat until a clap triggers it but talking does not.
  3. Some modules answer LOW instead of HIGH when they hear a spike. If your lamp toggles constantly and ignores claps, change == HIGH to == LOW. Reading the sensor's dialect is real engineering.

BREAK IT Now break it on purpose

  1. Turn the dial to maximum sensitivity. The lamp now flips when you speak, type, or exist. An over-sensitive sensor is as useless as a deaf one, calibration is a compromise, always.
  2. Remove the delay(400) and clap once. The lamp flickers through several flips and lands randomly. That is the "one clap is many bangs" problem, live. Put the cooldown back.
  3. Try triggering it without clapping: keys jangling? A whistle? A knock on the desk? You are mapping what "sharp sound" means to this microphone.

REMIX Make it yours

LOG IT Show and tell

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.

Next · Lesson 11: Guard Dog

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.

All lessons