The idea behind this project is to contain a disco party within a cupboard... and listen to a lot of Kokomo. Music playback, along with a motorized disco ball lit by LEDs, is triggered by opening the cupboard door. Door detection is achieved using a reed switch kit. Everything stops when the cupboard door is closed again. Think music playing birthday card, but in a cupboard with sparkling lights.
I divided the project into 4 modules: motorized disco ball, LED spotlight(s), audio playback, and door detection. I then spent some time thinking about how to implement each module and how they would interface with a microcontroller. I focused on using parts I already had for each module without making them overcomplicated.
Motorized Disco Ball
I already had a 28BYJ-48 stepper motor with a ULN2003 driver so I figured that was the best option. After a quick google search I found that disco balls typically spin at 1-6 rpm; a simple stepper motor should easily run at these low speeds. I also intend to use a 4 inch disco ball which won't load the motor by much.
The ULN2003 requires 4 digital inputs to control the motor. An external 5V source is also required. I found that the motor should draw around 240 mA .
I have never used neopixels before and thought this project would be a fun opportunity to do so. The neopixel jewel has 7 addressable RGBW LEDs arranged on a circular PCB (kind of like a spotlight) . I intent to use 2 of these jewels to light the disco ball from opposite sides of the cupboard.
The neopixel jewels have a built-in decoupling capacitor and data line resistor. They can also be chained together so ideally you only need one 5V digital output from a microcontroller to control all the LEDs. They require a 5V external supply and draw 60 mA/pixel at maximum brightness . For 2 jewels that results in 2*7*60 mA = 840 mA current draw.
Audio playback is a bit tricky (for full song playback) as most low cost microcontrollers do not have enough flash storage for a 3-4 MB MP3 file. Also, to play higher quality audio it is best to use a dedicated audio codec (for high bit depth digital-to-analog conversion). The resulting analog audio signal also needs to be amplified and sent out to speakers.
I found a music maker featherwing from Adafruit that packs all the above things onto a single, feather-compatible board (which means we're going to use a feather MCU!) . This featherwing uses a microSD to store audio files and requires a SPI interface as well as 4 other digital inputs. All feathers (other than the 32u4 version) allow for background audio playback as well.
With an external 5V supply and using 8 Ohm speakers, the onboard amp draws ~700 mA for 2 channel audio.
My original plan for detecting whether the cupboard door was open/closed was to use an IR proximity sensor. However, these types of sensors can be affected by sunlight which could cause problems when the cupboard door is open.
A typical method for door detection is with a reed switch (i.e. a switch activated by a magnetic field). Adafruit has door sensor kits that include a mountable reed switch and separate permanent magnet to be used for door detection . The door sensor can be configured like any SPST switch: pulled up to 5V through a 10k resistor, providing an active low "door open" signal (assuming a normally open reed switch).
Considering all the modules above, 10 digital pins and a SPI interface (SCK, MOSI, MISO) are required. The MCU must be in the feather format as well. For a low cost option that provides background audio playback and supports Arduino development, the Feather M0 Express was selected (it was also in stock on Digikey).