Simulator

A sound sensor simulator: a KY-038 clap switch on an Arduino

Mokxi is a free online sound sensor simulator that runs in your browser, with nothing to install and no account needed. A KY-038 sound sensor on an Arduino Uno, with its digital output on pin 2 and its analog output on A0, and a lamp that toggles on each clap. It also shows, honestly, how little this module’s analog pin can tell you.

  • 505parts on the bench
  • 45boards running now
  • 1.00xreal time, on every board
Arduino Uno: a clap switchlive0.000 s 0.00x
Click to open it in the editor
Click the circuit to open it in the editor, then press clap on the sensor. The lamp toggles and the serial monitor prints how far A0 moved.

What you can do here

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

  • Clap, and toggle a lamp
  • Set how loud the room is, from quiet to very loud
  • Compare the digital output with the analog one
  • See how small the analog swing is: a few dozen counts for a clap
  • See why one clap must be debounced like a button
  • Change the sketch to need two claps

What the running circuit shows

One clap, one toggle, and a very quiet analog pin.

In a quiet room the sketch prints “A0 over the last second: 512 to 512”: the analog output sits at half the supply and does not move. Press clap. The monitor prints “clap: lamp on”, and the next report reads “A0 over the last second: 467 to 555”. Clap again: “clap: lamp off”.

Look at those numbers. A clap right at the microphone, about as loud as a sound gets, moved A0 by 45 counts out of 1023. The KY-038 has no amplifier, so ordinary talking barely moves the pin at all. That is why this module makes a fine clap detector and a poor sound level meter, and why projects that need the level use an amplified board such as a MAX4466 or MAX9814.

The switching is done by the digital output, which a comparator on the board flips when the sound passes the level its trimmer sets. One clap is not one pulse: the output trips on every peak of the sound, dozens of times in the 25 ms the clap lasts. The sketch acts on the first edge and then ignores the pin for 300 ms, the same idea as debouncing a button.

How the KY-038 is modeled

A microphone, a comparator and no gain.

The model has both outputs of the board: the analog pin, which is the microphone’s small signal riding on half the supply, and the digital pin, which is the comparator’s verdict on it. The sound is yours to set: a slider for the level of the room and a button for a clap, which is a sharp 120 dB burst that dies away in 25 ms.

It does not listen to your computer’s microphone, so there is no speech or music to analyze; the room is as loud as the slider says. The sensor’s tone, its frequency response, is not modeled either. On real hardware, set the trimmer so the board’s second LED is just off in a quiet room.

How it works

Three steps from a blank tab to a running circuit.

  1. Open the editor

    It runs in your browser tab. Nothing to install, and you need no account to start.

    Your first project
  2. Wire it and write the code

    Drag parts onto a breadboard, run each wire from pin to pin, and write the sketch beside it.

    Wiring
  3. Press Run

    Your sketch compiles in the tab and runs on a model of the chip, with the Serial Monitor beside it.

    Run and serial
Reviews

What makers say about Mokxi.

“The AI checker helps check and correct my circuits, and it has way more components than Tinkercad. As a student I really appreciate the tool.”

ChloeEngineering student

“I’d been looking for a real online electronic simulator that was intuitive and complete when I found Mokxi. I was able to quickly import a Fritzing file and my Arduino sketch and start testing. Mokxi has all of the makings for the best online Arduino simulator I have been able to find!”

JayModel builderFeatured in his DioramaOS post

“I’m using Mokxi to develop and simulate an STM32-based four-wheel-drive robot car before building the actual hardware. It allows me to experiment with DC motor control, PWM, RPM measurement using photointerrupters, and different acceleration, braking, and reversing strategies, helping me understand and refine the system before implementing it in real life.”

NusretRobot car builder, Hamburg

Share your story

FAQ

Questions, answered.

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.

Why does my sound sensor’s analog reading barely change?

The KY-038 has no amplifier, so its analog pin moves by only a few counts for normal sound. In this circuit a loud clap moves it from 512 to between 467 and 555. For sound levels, use a microphone board with an amplifier.

How do I make a clap switch with an Arduino?

Wire the sensor’s digital output to a pin, toggle a lamp on its rising edge, and then ignore the pin for about 300 ms, because one clap makes many pulses. That is the sketch on this page.

Does the simulator use my microphone?

No. You set the sound on the part: a level slider and a clap button. Nothing is recorded.

More simulators

Each one opens on a circuit that is already running.

Clap the lamp on

Open the circuit, press clap and watch the lamp toggle. Nothing to install, and no account needed.