MakeCode extension for detecting claps and finger snaps with a modified HC-SR04 ultrasonic sensor.
The MakerBit connects to the BBC micro:bit to provide easy connections to a wide variety of sensors, actuators and other components.
![]() |
![]() |
---|---|
MakerBit | MakerBit+R with motor controller |
An HC-SR04 ultrasonic distance sensor can notify clap and finger snap sounds. Among audible frequencies, claps and snaps contain ultrasonic portions and thus the 40kHz receiver of the HC-SR04 detects them. In order to make this work, it requires a slight hardware modification of the sensor itself. We need to make sure that no other ultrasonic sounds are transmitted and therefore have to cover the transmitter (left cylinder). It turned out that masking tape works well.
Perform an action when a clap or finger snap is detected.
makerbit.onClap(DigitalPin.P5, DigitalPin.P8, () => {});
makerbit.onClap(DigitalPin.P5, DigitalPin.P8, function () {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
basic.showLeds(`
. . . . .
. # # # .
. # . # .
. # # # .
. . . . .
`)
})
Licensed under the MIT License (MIT). See LICENSE file for more details.
- for PXT/microbit
- for PXT/calliope