Holiday Light Hack

Introduction

The holidays are coming up and what better way to spend it than diving in to a hardware hacking project!

In this tutorial you will learn how to hack holiday lights, and control it through an iOS device. Make the lights blink to the beat of your favorite holiday music or work as a warning system if someone fiddles with the presents?

Holiday Lights Hack!

IMPORTANT! In this project we will use a string of lights that runs off of 120V. The voltage can seriously harm you, so if you're unsure of what you're doing, don't follow this tutorial. Always make sure that the lights are unplugged when you're modifying the electronics, and be sure to follow our instructions carefully!

Before You Begin

This tutorial assumes you have completed the Getting Started guide and that you understand how to upload a sketch to Bean using Bean Loader.

Software

Hardware

You need either a Bean OR a Bean+ for this project.

  • iOS devicex 1
  • Resistor 10k ohmx 1
  • Controllable RGB lightsx 1

Tools

  • Soldering iron
  • Wire cutter/stripper

Make It

Cut fet pins

Make sure that the string of lights are unplugged. Open the little white box. In there you have a simple microcontroller that controls the lights through three fets. One fet controls the yellow LEDs, one the red and one controls both blue and green.

fets

The middle pins of the fets are the ones controlling the current to the LEDs. Use a pair of pliers to cut of these pins as close to the circuit board as you can to make it easier to solder resistors to them.

clip the fets

Solder resistors

Cut one side of the 10k Ohm resistors to about half its length. Solder the resistors to the middle pins of the fets, the ones we just cut off. Insulate all the uncovered parts with heat shrink tubing.

exposed resistors
shrink-wrapped

These resistors will later be connect to pins 0-2 on the Bean, and by setting them to HIGH/LOW we can turn the LEDs of that specific color ON/OFF.

Solder to ground

Solder one wire to the far right leg of one of the fets. This is ground that we will connect the Bean to.

close-up

Pull wires through button hole

This string of lights have a button that changes the mode of the lights. Remove the white cap of the button from the case and pull the three resistors and the ground wire through the hole. Close the case.

exposed wires

Solder wires to Bean

Solder one of the resistors to pin 0 on the Bean, one to pin 1 and the last one to pin 2. Then solder the black wire to GND on the Bean.

final product

This is what the final wiring should look like:

wiring diagram

Program Your Bean

Upload the following code below to your Bean.:

/*  
  This sketch controls a string of holiday lights using
  the LigthBlue Bean and the iOS app LightBlue.

  This code is in the public domain.
 */

// The control inputs we will use from LightBlue
#define button1  13
#define button2  14
#define button3  15

void setup() 
{
  Serial.begin();
  Serial.setTimeout(5);

  // Set the pins connected to the holiday lights to OUTPUT
  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
 }

void loop() {
  // Check for serial messages from LightBlue
  char buffer[64];
  size_t length = 64; 
  length = Serial.readBytes(buffer, length);    

  if ( length > 0 )
  {
    for (int i = 0; i < length - 1; i += 2 )
    {
      // Check if button1 has been pressed or released...
      if ( buffer[i] == button1 )
      {
        // If the button is held down, buffer[i+1] will be 0
        // If it's released, buffer[i+1] is 1
        // Set pin 0 to 1 when the button is held down
        // and to 0 when released
        digitalWrite(0,1-buffer[i+1]);
      }
      else if ( buffer[i] == button2 )
      {
        digitalWrite(1,1-buffer[i+1]);
      }
      else if ( buffer[i] == button3 )
      {
        digitalWrite(2,1-buffer[i+1]);
      }
    }
  }
}

Test It Out!

Open the app LightBlue and connect to your Bean. Click options and choose Sandbox. If everything has been set up correctly, you can turn the lights on and off by pressing the buttons in the third view.

Bean iOS sandbox

Learn More

If you have any questions about this project, the best place to ask is the Beantalk community forum.