How To Series: Make Your Own Raspberry Pi Christmas Lights Controller!

How To Series: Make Your Own Raspberry Pi Christmas Lights Controller!

Christmas is around the corner, are you ready to light up your home with some stunning Christmas lights? In SunFounder Christmas series, we are going to teach you how to DIY a Raspad controller for your Christmas lights.


 Are you tempted to create your Raspad controller? Let’s follow these steps:

Materials List

 

Basic Components

Quantity

Christmas String Lights

1

2-channel Relay module

1

GPIO Extension Board

1

RasPad (include Raspberry Pi)

1

Breadboard

1

Wires

Some

3PIN Anti-reverse connector

2


Others

Quantity

Heat-shrink tube

Some

Wire stripper

1

Slotted screwdriver

1

Label

1

Pen

1

Electric Soldering Iron

1

Hot Air Gun

1

Solder Wire

1

 

 

Firstly, let’s  take care of the Hardware

  1. Open the control box of the Christmas String Lights with the flat-blade screwdriver.
  2. Remove the circuit board, and stick labels on the wires and mark with (1, 2, 3, 4, 5). Note: Label number 1 covers three wires. These 3 wires are  COMMON GND, LED Strip 1, and LED Strip 2. 4, 5, they are AC input ports.
  3. Use the electric soldering iron to remove them from the circuit board.
  4. Use the wire stripper to strip the electrical insulation of the wire on both sides for 1cm.
  5. Place three long wires on the heat-shrink tube and then connect them to the wires labeled 1, 2, and 3 with an electric soldering iron.
  6. After the joint portion is covered with a heat shrinkable tube, stabilizer them with the heat gun.
  7. Connect the two short wires to step 5 and step 6 is connected to the power plug wire labeled 4.
  8. Connect the wire labeled 1 and the extended wire to the power plug label 5 according to step 5 and step 6.
  9. Connect the wires to the labeled 2  and 3, and extend the wires to the Normal Open of the two relay modules.
  10. Connect the wires with 4 labels to the common end of the two relay modules.
  11. Connect the Raspberry Pi, T-head and breadboard. Connect the relay module to the GPIO expansion board.
  12. Relay module

    GPIO Extension Board

    VCC

    5V

    GND

    GND

    SIG

    GPIO17

    SIG

    GPIO18

  13. -27d39262b614fd481.gif
  14. Hang the modified string on the Christmas tree

Secondly, let’s  take care of the software

  1. Open Raspberry Pi after installing Raspberry Pi to RasPad
  2. Open Python3(IDLE)
  3. Create a folder
  4. Write the following code to the newly created folder, save it after naming the folder (suffix is .py)

#!/usr/bin/python

import RPi.GPIO as GPIO

import time

 

GPIO.setmode(GPIO.BCM)

# LED1 connection GPIO17

LED1 = 17

# LED2 connection GPIO18

LED2 = 18

 

GPIO.setup(LED1, GPIO.OUT)

GPIO.setup(LED2, GPIO.OUT)

 

#Pin signal is initialized to zero

def cleanup():

   GPIO.output(LED1, 0)

   GPIO.output(LED2, 0)

 

def light(status):

   if status:

       # LED1 light up

       GPIO.output(LED1, 1)

       # LED2 Put out

       GPIO.output(LED2, 0)

   else:

       # LED1 Put out, LED2 light up

       GPIO.output(LED1, 0)

       GPIO.output(LED2, 1)



def light_1(led, status):

   if status:

       GPIO.output(led, 1)

   else:

       GPIO.output(led, 0)

 

# LED1 blink

def blink_1():

   for i in range(0, 24):

       light_1(LED1, 1)

       time.sleep(0.307)

       light_1(LED1, 0)

       time.sleep(0.307)

 

# LED2 blink

def blink_2():

   for j in range(0, 32):

       light_1(LED2, 1)

       time.sleep(0.307)

       light_1(LED2, 0)

       time.sleep(0.307)

 

if __name__ == "__main__":

   # Pin signal is initialized to zero

   cleanup()

   # LED1 blink

   blink_1()

   # LED2 blink

   blink_2()

   # LED1, LED2 light up

   light_1(LED1, 1)

   light_1(LED2, 1)

   # Hold for 0.357 seconds

   time.sleep(0.357)

   # LED1, LED2 light up

   light_1(LED1, 0)

   light_1(LED2, 0)

   # LED1, LED2 alternate flashing

   while True:

       light(1)

       time.sleep(0.307)

       light(0)

       time.sleep(0.307)

When the code is running, you can see lights of LED 1 interface flashes first, and then lights of LED 2 interface start to flash, the lights of LED 1 and LED 2 flash alternately every 0.307 seconds.

DONE!