Spooky Sensor

As Halloween approaches, one great project is to use a distance sensor to have a MakerBit play spooky sounds when someone reaches their hand into a container of treats!

 

This project uses either the MakerBit R since this is the easiest unit to accommodate the ultrasonic distance sensor (model HC-SR04) found in the Elgoo 37 Sensor Kit ― a most handy collection of sensors to expand the kinds of things you can make with your HyperDuino or MakerBit. You’ll also need an MP3 player board and a powered speaker for this project. This kit can be found here.

 

The sound effects for spooky sounds can be found online from a royalty-free collection like freesoundeffects.com. I downloaded 20 or so sounds and renamed them to start with 001―, 002―, etc. with all the sounds put into folder 01 in the microSD card plugged into the MP3 player.

 

Using my 3D printer, I made a pumpkin to hold the speaker, and put everything into a cardboard box with the ultrasonic sensors poking through the lid. It is important that these sensors are not blocked!

image

 

The rest of the project is placed inside the box.

 

image

MakerBit code

The MakerBit is programmed with MakeCode using the MakerBit extensions found here. The code is shown below

 

image

 

This sets up the MP3 player with the receiving pin connected to A0 and the tramsmitting pin set to A1. There is a white Grove connector on some boards with four pins that make these connections along with power and ground to the MP3 player, The powered speaker is connected to the phone jack on the MP3 player. Your MakerBit board may have a black connector wi@th four sockets on it into which you can simply plug the MP3 player directly. To finish the setup, we play track 1 from folder 1 ― the folder with all your sound effects.

 

The rest of the code is shown below:

image

With the ultrasonic connector connected to another white Grove connector with power and connections to pins P8 and P5, we can read the value sent by this sensor using the block in the MakerBit extensions for MakeCode. If this value is less than 30 cm, we display the number on the built-in LED display, play the next track in our collection of sound effects, and wait 2 seconds.  If the distance sensed is greater than 30 cm, we show the distance on the LED display, pause the MP3 player, and wait 2 seconds.

 

Have fun when the kiddies come by for candy!

 

  • Hi David,

     

    That's a great looking pumpkin and a cool project; how long does something like that take to print?

     

    Thanks for the links to your sound module, it is just what I need to get for next year. I tried to use some WTV020-SD modules recently and failed (might be down to the SD cards I was using).

    image

    Rod

Related
Engagement
Recommended