How to Code and Build a Magic Mirror

by yenj in Craft > Art

244 Views, 2 Favorites, 0 Comments

How to Code and Build a Magic Mirror

45B7B02E-A6C5-4B3F-97FF-AE20873E9D91.jpeg

This Magic Mirror build is your one-way ticket to fun-filled mornings and self-assured walks up the Million Dollar Stairs! This beautiful mirror - lit with LED lights - complements any room, be it a kitchen, bathroom, or, in this case, a dormitory. Additionally, the mirror contains three built in voice recordings, which can be chosen between using the mirror's potentiometer. These pre-recorded complements are designed to brighten your day - the Magic Mirror ensures that you look and feel good. Follow the instructions below to build your own Magic Mirror, set with your own custom voice commands!

Supplies

Electronic Components

  • Bluefruit Computing Device
  • LED Lights with Alligator Clip Endings
  • Potentiometer Component
  • Alligator Clip Plug-ins for Potentiometer
  • Battery Pack (for Bluefruit Device)

Decorative / Static Components

  • Store-bought mirror
  • Duct tape
  • Hot glue gun (or other adhesive of similar strength)
  • Piece of cardboard (dimensions depend on size of mirror, but cardboard piece should be bigger than mirror)
  • Twine
  • Scissors or Razor Blade
  • Two Alligator Clips (Optional)
  • 3.5mm Audio Jack (Optional)
  • External Speaker (Optional)

Set Up Bluefruit Code

Connect your Bluefruit to a computer with a serial monitor. In this specific Magic Mirror build, a sequence of lights go off when each button (A and B, in this case) is pressed. Button A is accompanied by a "magic" sound, to ensure that the mirror speaker is working properly. Button B's secondary effect is determined by a potentiometer. The value of the Mirror's potentiometer determines which - if any - of three pre-recorded .wav files will play. To code this, Button_A and Button_B must be defined as the Bluefruit device input buttons. The potentiometer must be hooked up to the device, and variable "potentiometer" must be defined as an input to one of the Bluefruit pads (A3, in this case). A function called "play_sound" is defined, which initializes the Bluefruit speaker, and plays a .wav file passed in as an argument. Under a "while true" loop, the desired lights and recordings are turned on/played when their respective buttons (A or B) are pressed, defined as "if Button_A.value" or "if Button_B.value." Ultimately, you can play around with different sequences and sounds, so the Magic Mirror best fills your wants and needs.

Downloads

Create Mirror Backing

Using a pencil, trace the shape of your mirror out on the cardboard. With a razor blade or scissors, cut out this shape, and use your adhesive to stick it to the back side of the mirror.

Attach Electronic Components

0E84FE12-5F78-40E1-A31C-66DA93D0EE33.jpeg

Using an adhesive (preferably tape, as to not damage any of the electronics), place the Bluefruit device on the cardboard backing of your mirror. From here, use the alligator clips on both the LEDs and the potentiometer plug to connect these components to the Bluefruit device. Once connected, the LEDs can be rolled up, tied in place, and sat at the base of the mirror, as a light source. The potentiometer can be attached to the cardboard backing of the mirror in a similar manner to that of the Bluefruit device. The battery pack that the Bluefruit device is plugged into can be clipped onto the side of the mirror.

Test Drive

Magic Mirror Test Drive

Turn on the battery pack, and ensure that your mirror works properly. Give it a couple of tries, with different potentiometer values, just to make sure that the voice recordings are playing properly. If desired, you can connect an external speaker to the mirror using alligator clips and an audio jack. To do this, simply clip the bottom of the audio jack to "GND" of the Bluefruit device, and clip the tip to "AUDIO."