Things used in this project
(This is adapted from an older project share in the Particle community forums. Still very much relevant and in-use today!)
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 Photon!
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:
- Photon VIN --> Relay VCC
- Photon GND --> Relay GND
- Photon D1 --> Relay IN1
- Photon D2 --> Relay IN2
- Photon D3 --> Relay IN3
- Photon D4 --> Relay IN4
I am powering the Photon 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
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
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!