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

Make Some Noise

Your machines can shine. Today they learn to sing, beep and wail. The neighbours may comment.

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 Sound is just fast wiggling

Every sound you have ever heard is air wiggling. Wiggle it 440 times a second and you hear the note A. Wiggle it faster, the note rises. Your kit has two little speakers called buzzers, and your board can wiggle them at any speed you ask. Which means today you build a siren, then program an actual melody, note by note, and finish with a machine that plays it on demand.

Time: 45–60 minutes · Difficulty: 2/5 · You need: Lesson 03 done (buttons).

KIT What you need

Concept · The twins that are not twins

Your kit has an active buzzer and a passive buzzer. The active one has its own tiny musician inside: give it power and it plays its one note, forever, like a doorbell. The passive one is an empty instrument: silent until you wiggle it, but able to play any note. Tell them apart: the active one usually has a sticker on top and a sealed back; the passive one has an open green circuit board underneath. If it beeps the moment you power it, it is the active one.

Concept · tone(), your board's singing voice

tone(pin, frequency) wiggles a pin at any speed you choose, 440 for A, 262 for middle C, 1000 for a classic beep. noTone(pin) stops it. One rule: the board has one singing voice, it can only play one tone at a time. Chords are for Lesson 13, which does not exist, so improvise with rhythm instead.

BUILD Wire it

Unplug the USB. Start with the passive buzzer (the open-back one), it is today's star. Buzzers have a + marking on top; the + leg is often longer too.

FromToWhy
R3 pin 8Passive buzzer + legThe wiggle wire
Passive buzzer − legR3 GNDLoop complete
R3 pin 4Button leg · other leg to GNDThe play button, like Lesson 03

CODE Program it, siren first

// GAMERIFT Beginner Kit, Lesson 08: Make Some Noise
// Part 1: the classic rising-falling siren.

const int buzzerPin = 8;

void setup() { }

void loop() {
  for (int f = 400; f < 1200; f = f + 10) {  // pitch climbs...
    tone(buzzerPin, f);
    delay(5);
  }
  for (int f = 1200; f > 400; f = f - 10) {  // ...and falls
    tone(buzzerPin, f);
    delay(5);
  }
}

Upload. Siren. Enjoy it for exactly as long as your family allows. Now the real music, replace everything with:

// Part 2: a melody, note by note, on the button.

const int buzzerPin = 8;
const int buttonPin = 4;

// Frequencies for one octave (C D E F G A B C)
const int notes[8] = {262, 294, 330, 349, 392, 440, 494, 523};

// A tune as positions in the scale: change these and you change the song!
const int tune[]      = {0, 0, 4, 4, 5, 5, 4};
const int beats[]     = {1, 1, 1, 1, 1, 1, 2};
const int tuneLength  = 7;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(buttonPin) == LOW) {          // pressed: play!
    for (int i = 0; i < tuneLength; i++) {
      tone(buzzerPin, notes[tune[i]]);           // look up the note
      delay(300 * beats[i]);                     // hold it for its beats
      noTone(buzzerPin);                          // tiny gap between notes
      delay(40);
    }
  }
}
  1. Upload and press the button. Recognise it? (It is the opening of "Twinkle Twinkle", which is also, sneakily, the alphabet song.)
  2. Change the numbers in tune[] and press again. You are composing.

BREAK IT Now break it on purpose

  1. Swap in the active buzzer and run the siren. Instead of a smooth wail you get a strangled stutter, the built-in musician fights your wiggling. Right part, wrong job. Swap back.
  2. tone(buzzerPin, 40), then tone(buzzerPin, 15000). One is almost too low to hear, one almost too high (ask the nearest adult if they can hear 15000, they probably cannot, your ears lose the top notes with age).
  3. Delete the noTone() line. The notes now smear into each other like a robot slurring. Those 40 milliseconds of silence were doing more work than you thought.

REMIX Make it yours

LOG IT Show and tell

Record your composition for your lesson log (sound on, obviously). Stuck? Contact us with a photo and we will listen for the problem.

Next · Lesson 09: Weather Desk

Lights, numbers, sound, all outputs. Next lesson you meet your most grown-up sensor yet: one that measures the temperature and humidity of the actual air in your actual room, and reports it in real units.

All lessons