By Kevin McAleer, 4 Minutes
Page last updated November 24, 2026

Sense three is voice. The Modulino Buzzer lets the robot make sounds: a warning beep, a startup jingle, or a sad little “uh oh” when you pick it up. Sound also makes debugging easier. If a robot can say “I saw something”, you don’t need a cable attached to know it.
The module is a piezo buzzer with a small processor onboard. You give it a frequency in hertz and a length in milliseconds, and it plays a tone. A higher number is a higher note. For reference, 440 Hz is the note A4.
This is a complete program that plays a note and stops.
from time import sleep_ms
from machine import I2C, Pin
from modulino import ModulinoBuzzer
i2c = I2C(0, scl=Pin(9), sda=Pin(8), freq=400_000)
buzzer = ModulinoBuzzer(i2c_bus=i2c)
buzzer.tone(440, 500, blocking=True) # A4 for half a second
buzzer.no_tone() # make sure it is silent
sleep_ms(300)
buzzer.tone(880, 150, blocking=True) # a short, higher beep
buzzer.no_tone()
tone(frequency, duration_ms, blocking=...) plays the note. no_tone() stops it.
The blocking argument decides what your program does while the note plays.
blocking=True waits for the note to finish before moving to the next line.On a bench that’s a small detail. On a moving robot it’s huge. A half-second blocking beep means half a second of driving blind. At cruising speed, that’s far enough to hit the thing the robot was about to see.
Kev’s helper code makes quick beeps non-blocking by default, and only waits when the robot is standing still, such as during the startup tune.
The library has a table of named notes, ModulinoBuzzer.NOTES, and Kev’s repository uses names such as "C4" and "G5" with it. Here is the startup jingle from his robot, as a complete program.
from time import sleep_ms
from machine import I2C, Pin
from modulino import ModulinoBuzzer
i2c = I2C(0, scl=Pin(9), sda=Pin(8), freq=400_000)
buzzer = ModulinoBuzzer(i2c_bus=i2c)
NOTES = ModulinoBuzzer.NOTES
STARTUP = (("C4", 120), ("E4", 120), ("G4", 120), ("C5", 260))
UH_OH = (("G4", 160), ("E4", 160), ("C4", 320))
def play(melody, gap_ms=20):
"""Play (note_name, duration_ms) pairs. Use None for a rest."""
for name, ms in melody:
if name is None:
sleep_ms(ms)
continue
buzzer.tone(NOTES[name], ms, blocking=True)
sleep_ms(gap_ms)
buzzer.no_tone()
play(STARTUP)
sleep_ms(500)
play(UH_OH)
A melody is just a tuple of pairs, so a new tune is a new tuple, not new code. Each pair is a note name and how long to hold it.
Why this matters: a short rising tune says “ready” and a falling one says “uh oh”. Robots that communicate this way are far easier to live with.
Common mistakes:
no_tone(). Kev’s code always calls it after a tune, to be sure the buzzer is quiet.None rest between two notes. How does it change the tune?Problem: The buzzer stays on after your program ends.
Solution: Call buzzer.no_tone() at the end, and in a finally block if your program has a loop.
Why: Kev’s code always ends a tune with no_tone() so the buzzer is certain to be silent. Do the same.
Problem: The robot hesitates every time it beeps.
Solution: Use blocking=False inside the control loop.
Why: Blocking calls hold up the loop, so the robot isn’t sensing while the note plays.
Problem: An error about a missing note name when playing a tune.
Solution: Print NOTES and check the spelling of the note name.
Why: The table only holds the names the library defines.
Comments