This is the sixth in a series of blog posts about researching and rewiring Christmas lights to work with Arduino devices.

I know this series of posts have been talking about Arduino devices. But I have been thinking about how to best remotely control the Home Collection RF lights and setting up an Arduino with both the RF transmitter and WiFi seems to be more work than I actually need to do.

Network Diagram for LAN, Arduino, Remote-controlled Lights

But what about a Raspberry Pi instead? I am already using one as a mini home server, and it has GPIO pins with both 5V and 3.3V. Can I connect the 433MHz transceiver to it and control the lights from Raspbian?

I connected the transmitter to the Pi as follows:

RF TransmitterPi
GNDPin 6
VCCPin 4
DATAPin 12

433MHz transmitter connected to Raspberry Pi GPIO

Next I booted up the Pi and set up a Ruby script to test the radio.

$ sudo apt-get install ruby ruby-dev
$ mkdir pi-lights-control
$ cd pi-lights-control
$ sudo gem install bundler --no-rdoc --no-ri
$ vim Gemfile
source 'https://rubygems.org'

gem 'rpi_gpio', '~> 0.3.2'
$ bundle install
$ vim control.rb
#!/usr/bin/env ruby -w

require 'rpi_gpio'

RPi::GPIO.set_numbering :board
RADIO_PIN = 12
RPi::GPIO.setup RADIO_PIN, as: :output
TIME_DELAY = 120
CODE_TABLE = [
  [4,4],
  [4,8],
  [4,71],
  [26,12]
]

powerOn = [3,0,1,0,1,1,0,0,1,1,1,0,1,0,0,0,0,2]
powerOff = [3,0,1,0,1,1,0,0,1,1,1,0,1,0,0,0,1,2]

def set_high
  RPi::GPIO.set_high RADIO_PIN
end

def set_low
  RPi::GPIO.set_low RADIO_PIN
end

def transmit_signal(pattern)
  6.times do
    pattern.each do |code|
      high_length = CODE_TABLE[code][0]
      low_length = CODE_TABLE[code][1]

      set_high
      sleep(high_length * TIME_DELAY / 1000000.0)

      set_low
      sleep(low_length * TIME_DELAY / 1000000.0)
    end
  end
end

puts "Turning Lights ON"
transmit_signal(powerOn)

puts "Waiting 5 seconds"
sleep(5)

puts "Turning Lights OFF"
transmit_signal(powerOff)

at_exit do
  RPi::GPIO.clean_up
end

This script is more or less a Ruby port of the C code I wrote in Part 4. Running it via the command line, I see the lights turn on, and after five seconds the lights turn off. Excellent!

Even with the lights outdoors, the range from the Raspberry Pi is about 10 – 15 metres and works fine. If I need better transmission or range the modules have a hole for an antenna.

Next I expanded the Ruby script into a gem/library where code tables and so on are in their own classes. By turning it into a gem, I can then control the lights either using a command line interface or integrate it with other Ruby frameworks such as Sinatra or Rails.

  1. Get 433.920 MHz radio boards for Arduino
  2. Test HC lights remote with Arduino and radio receiver to determine signals for controlling HC lights
  3. Use Arduino and radio transmitter to simulate the remote and control the lights
  4. Connect Arduino to WiFi or Bluetooth and setup remote control from iOS or from a Raspberry Pi
  5. Find a housing for the Arduino — it is wireless so it doesn’t need to go outdoors but it will need power
  6. Test range of the remote, then the range of the RF transmitter
  7. Get antenna if necessary
  8. Set up lights outdoors, then control them from indoors!

The next step I want to tackle is creating a tiny web server to remotely control the lights on my home network — a simple web page that can issue the commands. Afterwards I will try to integrate it with homebridge and control the lights via Siri.