Simulator

A buzzer simulator that shows every tone your code plays

Mokxi is a free online buzzer simulator for Arduino that runs in your browser, with nothing to install and no account needed. An Arduino Uno plays the opening of “Ode to Joy” on a passive piezo buzzer with tone(), one note at a time, and lights an LED on each beat. The buzzer shows the frequency it is being driven at, and the serial monitor names each note.

  • 455parts on the bench
  • 43boards running now
  • 1.00xreal time, on every board
Arduino Uno: piezo melodylive0.000 s 0.00x
Click to open it in the editor
The tune plays, then rests for two seconds. Click the circuit to open it in the editor and write your own.

What you can do here

In the circuit above, or in the editor it opens.

  • Play notes with tone() and stop them with noTone()
  • Read the frequency each note really comes out at
  • Change the tune, the tempo or the gap between notes
  • Swap in an active buzzer that beeps from a plain digitalWrite
  • Make a parking sensor that beeps faster as something gets closer
  • Save the tune and share it with one link

What the running circuit shows

A square wave at the pitch you ask for.

tone(pin, frequency) starts timer 2 toggling pin 8 at that frequency and returns at once, so the sketch decides how long each note lasts with its own delay() and stops it with noTone(). The 30 ms gap after each note is what makes two notes of the same pitch into two notes rather than one long one.

In the engine the piezo reads each note’s frequency as it plays: the E the sketch asks for at 330 Hz comes out at 330.7 Hz, and the C at 262 Hz at 262.6 Hz, because the timer can only divide the 16 MHz clock by whole numbers. The fifteen notes take about 6.4 seconds, then the serial monitor says “again in two seconds”.

Active and passive buzzers

One beeps by itself, the other needs a tone.

The piezo here is a passive buzzer: it makes whatever frequency the pin drives it at, which is why it can play a tune. An active buzzer has its own oscillator inside, so a plain HIGH makes it beep at its one pitch and tone() is not needed. Both are in the parts bin, and the active buzzer project beeps one from digitalWrite.

What it leaves out: the sound. Mokxi does not play the tone through your speakers; the buzzer shows the frequency on its face, which is quieter in a classroom and exact. A real piezo is also loud at its resonant frequency and quiet away from it, which this one does not model.

Questions

Is it free?

Yes. The circuit on this page, every part in it and the editor it opens in are on the free plan, with no card.

Do I need an account?

No. The circuit runs the moment the page does, and the editor opens without one. A free account is only for saving a project to the cloud and sharing it by link.

What is the difference between an active and a passive buzzer?

An active buzzer has an oscillator inside and beeps at one pitch when it gets power. A passive buzzer, or piezo, makes whatever frequency it is driven at, so it can play notes with tone().

Can I play a song?

Yes. The sketch keeps the tune as two lists, the notes in hertz and the lengths in beats; replace them with your own and press Run.

Can I make it play faster?

TEMPO_MS is the length of half a beat, 200 ms in this sketch. Make it smaller and the tune plays faster; set GAP_MS to 0 and repeated notes run together.

Play a tune

Open the circuit, change a note and press Run. Nothing to install, and no account needed.