Holiday Wreath

Holiday Wreath

GrovePi controlled Holiday Wreath

Summary

Have you always wanted to control your Holidays displays? Many fantastic lights displays abound on the Internet, and some are very impressive. This project will let you take your first steps into this magical activity. Let’s build a GrovePi controlled wreath.

It will be light controlled. The lights will turn on when it’s dark, and run for five hours, then off for 6 hours till the next morning.

It will be motion controlled: the lights will blink whenever movement is detected, so that visitors to your home will be greeted by twinkling lights.

No soldering, it’s a promise!

 

  • This project requires modifying a 110V line and should be done with caution! Do not cut or touch bare wires with the lights plugged into the wall. Only plug the lights in when everything is done and you will no longer be manipulating the wires. A knowledgeable adult should supervise this project at all times. This project has not been tested on 220V.

What you'll need for this project:

You can get all the above (except the PIR sensor) by getting a GrovePi starter kit, or if you already have the first three items, a GrovePi+ Base Kit

  • a holiday wreath
  • a string of holiday lights (an old one is fine) strung around the wreath
  • a pair of strong scissors
  • a small screwdriver

Step 1: Cut the wire!

This project is going to handle “real” electricity.  That means it’s going to be slightly dangerous. The holiday lights handle regular, household electricity and you can get a shock. Do *NOT* plug in the holiday lights until everything is secure.

Bit of theory :

The relay  makes a link between two independent electrical circuits.  One circuit runs on low voltage electricity and that is the GrovePi+ circuit. When that low voltage is on, it closes a gap in the high voltage circuit (i.e. the holidays lights circuits) and allowing electricity to flow in the light circuits at a higher voltage. When the low voltage circuit is off, the gap is open, interrupting the high voltage circuit and turning the holiday lights off). If you want more details on how relays work, you could check “Explain That Stuff” about relays.

The first step is to cut one of the wires to create that gap and for that, you will need strong scissors. Cut just one of the wires, not both. Also, if you have a string of lights that runs in parallel – the type that still works even if a single light burns out, you will see that part of the string of lights actually has three wires. Don’t cut any of those. To be safe, cut near the power plug.

Again, be certain the wires are UNPLUGGED before you cut!

Once the wire is cut, the two ends will have to be stripped just a little bit. That means you have to remove the insulating cover for about 1/8″ to 1/4″ (or about half a centimeter). There are tools to help this wire-stripping, but if you don’t have one handy, you can use a knife and fingernails. Score around the insulation with the knife without nicking the wire itself, and pull the insulation off.

Step 2: Insert Wires into Relay

We promised no soldering, and we’ll keep that promise. At this step, most people would tell you to put a little bit of solder onto the now naked wire tips, and it would be good advice. However, you can get by with just twisting the wires so there are no stray bits.

Take the relay and unscrew the two screw terminals (their boxing is green). Take one wire end, visually ensure there are no stray bits of wire, and insert it into the now open terminal. Screw it down in place.  Do the same for the second wire end. Do a visual inspection that there is absolutely no contact (and no risk of contact either) between the two naked wires.

At this point, the string of lights is still not plugged into 110V. If you turn the relay over, you’ll notice pins underneath. Those pins will eventually conduct real electricity and you could get a shock. Handle the relay with caution.

Step 3: Assemble the Electronics

Take a deep breath. You’ve done the  most nerve-wracking part! Congratulate yourself for making it this far. Now you need to assemble your GrovePi+.

Please refer to this tutorial for your first use of GrovePi+.  You will find all the information for setting up your Pi and GrovePi, and getting it on your home network.

Insert the GrovePi+ over the Raspberry Pi GPIO headers.

  • Connect the relay to port D2,
  • Connect the light sensor to port A0
  • Connect the PIR sensor to port D8.

Done! It’s ready to boot!

Step 4: Run the code!

The easiest way to get the code is to update your SD card by running the DI Software Update utility.  You will need to have an internet connection on your Pi for this step.

Do not plug the lights in yet.

Once the SD card has been updated, open up a terminal window and enter the following:

cd ~/Desktop/GrovePi/Projects/Holidays_Wreath

followed by:

sudo python holidays.py

sudo_holidays

The code will start running. Depending on your current environment, the relay may or may not click right away. You can cover the light sensor with your hand to simulate night time, or put the motion sensor (the PIR sensor) under a mug so it won’t detect movement. To stop the code, use Ctrl-C to interrupt it.

Of course, since the lights are not plugged in, they won’t turn on, but you can hear the relay click on and off, and there’s a tiny red LED on the relay board to let you know when it’s on.

The code is written in such a way that the lights will turn on at dusk and run for five hours. Then the wreath will rest for six hours. You can adapt to your environment and desired usage by editing the code and changing two variables.

cd ~/Desktop/GrovePi/Projects/Holidays_Wreath
sudo nano holidays.py

Scroll down a bit until you find the following:

holiday_wreath_variables

light_threshold might need to be adjusted based on the wreath’s environment.

hours_after_sunset represents how many hours will the lights be on once they are turned on automatically due to darkness.

hours_of_sleep represents how many hours will the wreath be inactive at night.

To save your changes, press Ctrl-X, followed by Y, and the Enter key

Raspbian for Robots - Update Software

Step 5: Assemble the Wreath

Once you are satisfied with the behavior , you can start assembling the wreath. You will need to position the two sensors (light and PIR) on the surface of the wreath, as discreetly as possible, or not discreetly at all. It’s up to you!

The Pi and GrovePi will be somewhere in the middle, resting on the wreath innocuously, and the relay will be as hidden as possible behind the wreath. Remember that the underside of the relay will have electricity going through it. You might want to cover the underside with electrical tape, and place the relay in such a way that it won’t make contact with a conductive material.

Step 6: Starting the code at boot

Before you go out and install the smart wreath outside, it’s a good idea to set the Raspberry Pi to run the code at boot time. That way, you won’t need wifi connectivity to start it.

There are a couple of ways you can do this. You can read up on one way using crontab scheduling

Type

crontab -e

crontab

The line you need to enter at the bottom of the file is as follows:

@reboot sudo python /home/pi/Desktop/GrovePi/Projects/Holidays_Wreath/holidays.py

crontab_001

Then, Ctrl-X, Y and Enter to exit. Reboot your Pi. When it boots up, it should run the code automatically.

Step 7: Install your Smart Wreath at the Front Door!

At this point in the project, the lights are ready to be plugged in. Pay special attention to the back of the relay. Don’t touch it, and make sure it’s not touching metal. Use electrical tape if need be. Go ahead, plug the lights in and admire your lovely work!

All you have left to do now is hang it at the front door. As each household is different, you’ll have to find what works for you.  Make sure your Pi is protected from rain (or snow!) and that the relay is not making contact with anything flammable, or conductive. The relay also has to be protected from weather.

If you’re close to a streetlamp, you might need to adjust the light sensitivity threshold in the code on line 50.

light_threshold

The wreath will run all night with the lights on, and will blink anytime someone moves in front of it. May we suggest unplugging it when going to bed, just to be on the safe side.

Have fun! And may you have the best of times during the Holidays season!

How to get the code for this project:

The easiest way to get the code is to update your Dexter Industries software through the “DI Software Update”. Click the DI Software Update button on the desktop of Raspbian for Robots. When you do this, all of the code files for new projects like this will show up!

File Path

When you run the DI Software Update, this project can be run as:

sudo python /home/pi/Desktop/GrovePi/Projects/Holidays_Wreath/holidays.py

How to get the code for this project:

If you are not using the Dexter Industries custom software, Raspbian for Robots, and you still want to download this file, you can download it here: https://github.com/DexterInd/GrovePi/blob/master/Projects/Holidays_Wreath/holidays.py

Need help?

Have a question or a problem?  Post it on the forums and we’ll help you out.