Chapter 02: Base Security 101

RTTTL Alarm

The Sound of Safety

The abandoned research facility creaks around you as another dust storm batters the reinforced walls. Your makeshift base in the electronics lab feels secure enough, but the Wanderer threat grows stronger each day. The scavenged components scattered across your workbench tell a story of desperate survival: resistors pulled from defunct medical equipment, a speaker salvaged from an old intercom system, wires stripped from emergency lighting.

Security isn't just about barriers and locks. Sometimes it's about communication, about signals that cut through chaos. The HERO Board hums quietly in the dim emergency lighting as you examine the speaker in your hands. This simple device could become something more: an alarm system that plays recognizable melodies, a way to signal safety to other survivors, or even a psychological weapon against the Wanderers who fear the sounds of the old world.

RTTTL, the RingTone Text Transfer Language from the age of primitive mobile phones, holds the key. These simple text strings can encode entire melodies, storing them in the board's memory like musical DNA. Each note, each pause, each rhythm compressed into letters and numbers that your microcontroller can decode and transform into sound waves that pierce the apocalyptic silence.

The irony isn't lost on you. Rick Astley's "Never Gonna Give You Up" might be the most annoying song ever inflicted on humanity, but in this wasteland, its familiar melody could mean the difference between friend and foe. The Wanderers have never heard a Rickroll. They don't understand the cultural weight of those opening notes. But any human survivor would recognize it instantly, a beacon of the world that was.

What You'll Learn

When you finish this lesson, you'll be able to:

  • Connect a speaker to your HERO Board and make it produce musical tones
  • Understand how RTTTL (RingTone Text Transfer Language) encodes melodies as text strings
  • Use the tone() and noTone() functions to control audio output
  • Parse complex strings containing musical data and convert them to sound
  • Create an alarm system that plays recognizable melodies
  • Implement string parsing techniques to extract note data, durations, and timing
  • Build a foundation for more complex audio projects and communication systems

Understanding Musical Code

Think of music as a language your microcontroller can learn to speak. Just like human languages have alphabets, musical languages have notes. But here's the clever part: we can represent entire songs as simple text strings that computers understand.

RTTTL works like a recipe for sound. Imagine you're giving someone instructions to play a song on a piano, but you can only use text messages. You'd need to specify three things for each note: which key to press (the pitch), how hard to press it (the volume), and how long to hold it down (the duration). RTTTL does exactly this, but in a format so compact it could fit in the tiny memory of 1990s mobile phones.

The tone() function is your HERO Board's voice box. When you call tone(pin, frequency), you're telling a specific pin to vibrate at a certain speed. A speaker connected to that pin turns those vibrations into sound waves your ears can detect. Low frequencies create deep, bass sounds. High frequencies create sharp, treble sounds. The frequency 440 Hz produces the musical note A, the same note orchestras use to tune their instruments.

String parsing is like being a detective examining coded messages. Your program must scan through the RTTTL text character by character, looking for patterns and extracting meaning. When it sees "8g", it knows that means "play the note G for an eighth-note duration." When it encounters "d=4,o=5,b=200", it's reading the song's configuration: default duration of quarter notes, default octave 5, and tempo of 200 beats per minute.

Wiring Your Audio System

This circuit creates a simple but effective audio output system. The speaker needs protection from the digital pin's voltage, which is where the resistor becomes critical.

RTTTL Alarm Wiring Diagram
  1. Connect the 1kΩ resistor from HERO Board pin 24 to one terminal of the speaker. This resistor limits current flow and prevents damage to both the pin and speaker.
  2. Connect the speaker's other terminal directly to GND on the HERO Board. This completes the circuit and provides a return path for current.
  3. Verify your speaker impedance. Use an 8-ohm or higher speaker. Lower impedance speakers draw too much current and can damage your board.
Why This Works