Halloween with MicroPython

This is a quick Halloween project (if you have the parts, they are easy to find).  With a little imagination, you can adapt it to different components or behaviors. The software is written in MicroPython for a RP2040 (or RP2350), you can port it to other boards by replacing the PIO code for the HC-SR04 sensor with normal GPIO operations.

A resin skull (bought in a trinket store) is transformed into a spooked object that lights up and makes strange noises, especially when someone nears it.

What you need

Here is a list of the parts needed for this project

  • An RP2040 (or RP2350) board. We will use one UART and four GPIOs pins. The Pico or Pico2 works fine. A XIAO RP2040 or RP2040 Zero is a very compact option. In the pictures, I am using a Feather RP2040 that has battery support
  • Three WS2812B RGB LEDs (or more)
  • An HC-SR04 ultrasound distance sensor
  • A DFPlayer Mini MP3 Player, a micro SD card, and a small speaker

Schematic

The picture below shows the interconnection of the parts:

Nothing special here, just notice that the HC-SR04 is powered by 5V (I could not get it to work reliably at 3.3V), so a voltage divisor is used in the Echo signal.

Mechanical Assembly

The details for the mechanical assembly will depend on the particular skull you got and your skills (or lack of them, as is my case).

For easy access to the skull's interior, I use a hole saw to make a big opening at the bottom. Small holes were made at the eyes, and two RGB LEDs were fixed with hot glue, the third LED was fixed at the back with tape.

The main circuit was housed in a cardboard box used as a base for the skull. Holes were made for the sensor, speaker, and USB cable. If you power the board with a battery or USB power bank, you may do without the hole for the USB cable.


I used a small breadboard, but you can solder wires for a more definitive and rugged assembly.

Software

You can get the code (and the MP3 files I used) from github: https://github.com/dquadros/HalloweenSkull

Here is a concise explanation of its working:

  • The MP3 class controls the MP3 player. The command used plays files named nnnn.mp3 in a mp3 directory on the SD card.  The end of the sound is detected by the Busy signal from the player.
  • The HCSR04 class uses the HCSR04 sensor to measure the distance of an object in front of the sensor. It uses a PIO program to trigger the sensor and measure the time to receive an echo.
  • The standard neopixel module is used to control the RGB LEDs. It is assumed that the first LED is at the back of the skull and the next two are at the eyes.
  • The main loop action depends on the distance to the object in front of the sensor:
    • If there is something near the sensor (less than 40 cm), the eyes will light up and a sinister laugh will be played
    • If there is nothing near the sensor, the eyes will randomly blink and a strange voice will sound.

Changing the Project

It should not be hard to make changes to the project. Some ideas:

  • Change the code to increase or decrease the occurrence of the actions 
  • Change the sounds, by replacing the MP3 files
  • Increase the number of random sounds, by loading more MP3 files and changing the software
  • Use another kind of sensor to trigger the lighting of the eyes
  • Add a servo motor to make something move when someone comes near the skull


Comments

Popular posts from this blog