I have a SainSmart 4-Channel Relay Module that I’ve been using with 4 rocker switches and a 5v cell phone charger to turn the relays on and off. It controls some deck lights, patio lights, and umbrella lights, plus one extra outlet for whatever else (usually big box fans). While the setup with the rocker switches has been okay for the most part, I didn’t like the ethernet cable running from the weatherproof outdoor enclosure into the house where the rocker switches are “mounted”. So, naturally, I needed to get rid of the wires and control the outlets using a Spark Core!
I am not going to cover wiring of the A/C outlets as I am far from being electrically certified to do it. DO THIS AT YOUR OWN RISK. THERE IS A RISK OF FIRE, PROPERTY LOSS, PERSONAL HARM, OR EVEN DEATH.
The wiring is simple:
- Spark VIN → SainSmart VCC
- Spark GND → SainSmart GND
- Spark D1 → SainSmart IN1
- Spark D2 → SainSmart IN2
- Spark D3 → SainSmart IN3
- Spark D4 → SainSmart IN4
I am powering the Core using USB, so I am pulling the ~5v from the VIN pin to power the relay (it needs more than 3.3v). This particular SainSmart relay controller does things a little backward, so you have to digitalWrite the pin HIGH to turn it off, and digitalWrite LOW to turn it on. However, in the code, I use 0 to signify OFF and 1 to signify ON. I simply perform digitalWrite(pin, !state)
to invert the on/off logic for the relay board.
Also, since I have a bunch of 10K NTC thermistors on-hand, I also decided to use it to monitor the outdoor temperature near the enclosure. I have it connected to pin A0.
This project makes use of some additional functions and libraries made possible by the community:
- bitRead(), bitSet(), bitClear(), and bitWrite() provided by @bko
- elapsedMillis library provided by @peekay123
- Thermistor library provided by myself
- Keeping Binary States with Integers provided by myself
On the web side, I use my own Simple Spark PHP Proxy (the mod_rewrite version), jQuery, jQuery Mobile, and Google Hosted Libraries for the jQuery and jQuery Mobile JS/CSS hosting.
I have posted the web code as well as my firmware to my spark-deck-lights GitHub repository. The web code is in index.html
whereas all the firmware files are in the /firmware
directory.
Now, for a few pictures!
This is the original setup using a 5v cell phone charger and ethernet (you can see the ethernet and coupler in the bottom left).
The new setup using the Spark Core. The blue and white twisted pair is part of my thermistor temperature probe.
A screenshot of the web app on my iPhone 4s.