Contact sales

How to build a smart advent calendar with Photon 2

Light up your holidays with a smart, 3D-printed advent calendar powered by Particle Photon 2

How to build a smart advent calendar with Photon 2

It’s Christmas time again, and one thing I remember fondly from my childhood is the countdown to Christmas day. We always had the cardboard Advent calendars with the little perforated doors when I was a kid, and this inspired me to come up with a modern, electronic version of this fun tradition—this time without the terrible, dried-out chocolates inside.

Thus, the Electrobaum was born—a tree-shaped, 3D-printed advent calendar with RGB LEDs and tactile buttons that light up the countdown, all powered by a Particle Photon 2 and a bit of creative coding. No stale chocolates here—just electronic holiday magic!


Solution

The Electrobaum is a 3D-printed Christmas tree advent calendar that lights up and interacts with you as you count down the days to Christmas. Each day is represented by an RGB LED, which lights up when its corresponding button is pressed. A Particle Photon 2 microcontroller tracks your progress, handles button presses, and sends updates to the Particle platform, where you can trigger additional actions like playing music or sending notifications.

Here’s what happens behind the scenes:

  • A 3D-printed tree frame houses the LEDs and buttons.
  • Tactile buttons act as the calendar’s “doors.”
  • RGB LEDs light up when a button is pressed.
  • The Particle Photon 2 keeps track of the days and communicates with the cloud for extra features.
  • The Particle Logic Ledger manages the state of the calendar, ensuring you can’t “open” the same day twice.

The result is a festive and interactive calendar that’s fun for all ages!


Bill of materials

Component Description
Particle Photon 2 Microcontroller for processing button presses and communicating with the Particle platform.
RGB LEDs Individually addressable LEDs (e.g., WS2812B or APA102) to represent the days of the calendar.
Mikroe IO Expander Expands GPIO pins on the Photon 2, making it easier to connect multiple buttons and LEDs.
Tactile buttons Act as the “doors” of the advent calendar.
Perf board For soldering and organizing connections between components.
Headers and jumpers For creating detachable connections between the components.
3D-printed tree frame A festive structure to house the LEDs and buttons, designed to resemble a Christmas tree.
Power supply A power source capable of powering the Photon 2 and LEDs (ensure sufficient capacity for the LED current draw).

Skills & tools required

  • Basic soldering to assemble the perf board.
  • Familiarity with 3D printing or access to a 3D printer for creating the tree frame.
  • A basic understanding of the Particle platform and how to set up devices, the Logic Ledger, and integrations.
  • Some experience with C++ or the ability to Google whatever you don’t understand (the most important skill when making things).

Step one: build the calendar

The first step in creating your Electrobaum is assembling the hardware. You’ll print a 3D tree frame, prepare LEDs and buttons, and wire everything up to the Photon 2. Let’s make this calendar come to life!

1. Print the tree frame

  • Download the files: Get the STL files from the GitHub repository. These include the tree structure, LED holders, and button mounts.
  • Start with a test print: Use the provided test file to ensure your components fit properly before printing the full model. This helps you avoid wasted time and filament.
  • Print the tree: Once the test looks good, print the full model. The tree consists of three separate parts that you’ll assemble. Use PLA or PETG for a sturdy build that will hold up to use.
  • Clean up the prints: Smooth out any rough edges or overhangs with sandpaper or a hobby knife. A clean fit will make the next steps easier.

2. Prepare the LEDs

  • Choose your LEDs: Use individually addressable RGB LEDs, like WS2812B or APA102. These allow you to control each light independently for maximum flexibility.
  • Layout: The project uses a grid of 8 rows by 6 columns (48 LEDs total) to match the ROW_COUNT and COLUMN_COUNT in the code.
  • Wire the LEDs:
    • Chain the LEDs in series, connecting the data out of one LED to the data in of the next.
    • Connect the power (VCC) and ground (GND) lines across the chain.
    • If your LEDs require 5V power, ensure the data signal from the Photon 2 is converted to 5V using a logic level shifter.
  • Test the LEDs: Before mounting them in the tree, test the LED chain by connecting it to a power source and microcontroller. Verify that all LEDs respond correctly.

3. Install tactile buttons

  • Layout: Place tactile buttons in a matching 8×6 grid, aligning each button with its corresponding LED. These buttons will act as the interactive “doors” of your advent calendar.
  • Wire the buttons:
    • Connect one terminal of each button to the IO Expander or directly to an available input pin on the Photon 2.
    • Connect the other terminal of each button to ground (GND).
  • Secure the buttons: Mount the buttons firmly in their designated slots, ensuring they are easy to press but not loose.

4. Mount the Photon 2 and IO Expander

  • Attach the Photon 2: Mount the Photon 2 on the back of the tree or on a separate base. Use screws, standoffs, or mounting tape to secure it in place.
  • Set up the IO Expander:
    • Connect the RESET_PIN (defined as D4) from the Photon 2 to the reset line on the IO Expander.
    • Connect the INT_PIN (defined as D2) from the Photon 2 to the interrupt line on the IO Expander. This allows the Photon 2 to detect button presses.
    • Use the SCL and SDA pins for I2C communication between the Photon 2 and the IO Expander.

5. Add power

  • Power the Photon 2: Use a 3.3V power supply for the Photon 2. This is the microcontroller’s operating voltage, so don’t connect it to 5V directly.
  • Power the LEDs: If your LEDs require 5V power, connect them to a separate 5V power supply.
    • Ensure the ground (GND) from the 5V power supply is connected to the ground of the Photon 2. This is critical for proper communication between the components.
  • Logic level shifter: If using 5V LEDs, insert a logic level shifter between the Photon 2 and the LED chain to convert the 3.3V data signal to 5V.

6. Test the assembly

  • Test the LEDs: Power up the system and confirm that all LEDs light up and respond correctly. Run a basic test program to verify that each LED in the grid is controllable.
  • Test the buttons: Press each button and confirm it sends the expected signal. Use a serial monitor to check that the input corresponds to the correct LED in the grid.
  • Inspect everything: Double-check all connections, paying special attention to the wiring of the RESET_PIN and INT_PIN. Look for loose wires, misaligned buttons, or any signs of shorts.

Step two: add some code

Now that your Electrobaum is physically assembled, it’s time to bring it to life with code! In this step, you’ll upload and test the provided code to ensure your hardware works as intended, and then you’ll configure the main project logic for the Advent calendar. Let’s get started!

1. Download the code

The full project code and test programs are available on the Electrobaum GitHub repository. The repository includes everything you need:

  • Test code: Verifies that your buttons, LEDs, and IO Expander are working correctly. This is a great first step to ensure your setup is ready.
  • Main project code: Implements the full functionality of the advent calendar, including button interactions, LED lighting, and cloud integrations.

2. Set up your environment

To program the Electrobaum, you’ll need:

  • Particle Workbench: An extension for Visual Studio Code and the easiest way to develop for the Photon 2. Download and set it up by following the Particle Workbench installation guide.
  • Particle account: If you haven’t already, create a Particle account and claim your Photon 2 device. This links the microcontroller to your account for easy programming and management.
  • Connect the Photon 2: Plug the Photon 2 into your computer via USB and ensure it’s recognized by Particle Workbench.

3. Upload the test code

Start by uploading the test program to ensure all components are wired and functioning correctly. Use the following code snippet from the repository:

#include <Wire.h>
#include "Particle.h"
#include "PI4IOE5V96248.h"

// Define pins and constants
#define RESET_PIN D4
#define INT_PIN D2
#define ROW_COUNT 8
#define COLUMN_COUNT 6

PI4IOE5V96248 io_expander(0x20); // Address of the IO Expander

void setup() {
    pinMode(RESET_PIN, OUTPUT);
    digitalWrite(RESET_PIN, HIGH);
    pinMode(INT_PIN, INPUT_PULLUP);

    Serial.begin(115200);
    while (!Serial) {
        // Wait for Serial Monitor
    }

    if (!io_expander.begin()) {
        Serial.println("Failed to initialize IO Expander!");
    } else {
        Serial.println("IO Expander initialized successfully.");
    }
}

void loop() {
    for (int row = 0; row < ROW_COUNT; row++) {
        for (int col = 0; col < COLUMN_COUNT; col++) {
            io_expander.writePin(row, col, HIGH);
            delay(200);
            io_expander.writePin(row, col, LOW);
        }
    }
}

Steps to upload and test:

  1. Open the test code: Copy the snippet above or open the test code file from the repository in Particle Workbench.
  2. Compile and flash: Use the “Flash” button in Particle Workbench to upload the code to your Photon 2.
  3. Monitor the serial output: Open the serial monitor (Ctrl+Shift+P and select “Particle: Serial Monitor”) to check logs. You should see messages confirming the IO Expander’s status.
  4. Check LED behavior: Verify that each LED lights up in sequence. If something doesn’t work, double-check your wiring.

4. Upload the main project code

Once the hardware passes the test, it’s time to upload the main project code. This code will:

  • Track the state of the calendar: Determine which days have been “opened.”
  • Light up LEDs: Activate the corresponding LED based on button presses.
  • Publish cloud events: Send an event ("advent_day_opened") to the Particle cloud, enabling notifications or other integrations.

Here’s an overview of how the main program works:

  1. Initialization: The Photon 2 initializes the IO Expander and sets up the LED and button grid.
  2. Button interaction: When a button is pressed, the corresponding LED lights up, and the state of that day is saved in memory.
  3. Cloud events: Each button press publishes an event to the Particle cloud, which can trigger notifications, music, or other festive actions.

5. Configure integrations

The Electrobaum supports cloud integrations for additional functionality. Here’s how to set up a simple notification:

  1. Log in to the Particle console: Go to console.particle.io.
  2. Set up a webhook:
    • Navigate to Integrations > New Integration > Webhook.
    • Create a webhook triggered by the "advent_day_opened" event.
    • Configure it to send notifications via services like Twilio, Pushover, or Slack.
  3. Test the integration: Press a button and check if the notification is sent. You can also add additional integrations for actions like playing music or controlling smart devices.

6. Fine-tune your calendar

Once the main code is running, you may want to customize a few features:

  • LED animations: Add festive effects when a button is pressed, like blinking lights or color fades.
  • Button debounce: Ensure accurate button presses by adding debounce logic to prevent multiple activations from a single press.
  • State persistence: Save the calendar’s state in non-volatile memory (e.g., EEPROM) so it remembers which days have been opened, even if the device is powered off.

Conclusion

At this point your Electrobaum will be running its main program and ready for action. The combination of LEDs, buttons, and cloud integrations makes this Advent calendar as exciting to use as it is to build. 

Feel free to share your Electrobaum build with the community—show off your creativity and inspire others! If you need help or want to see updates, head over to the GitHub repository or the Particle forums.

Happy holidays, and enjoy the countdown to Christmas with your very own Electrobaum! 🎄✨

 

Comments are not currently available for this post.