I recently upgraded my kitchen lighting from high power halogen lights to nice low power 12V DC LED lighting and I want to control those gracefully, not with a stack of plug-in mains relay modules as I had previously (and sadly is often the only choice).
I also wanted some built-in intelligence and sensors, lots of sensors! I have 3 separate areas (sink, cooker and microwave area) that want to be controlled as one or separately, as well individual control of four possible light sets per area (over cabinet, under cabinet, white LED strip and UV strips for added silliness. Sorry, to kill the germs).
Only one thing for it! A custom PCB with a Particle Photon on-board, some big FETs and lots of other goodies!
Presented here is my 3rd version of that board. I've found the PCB really useful, not just for my kitchen lighting but for controlling UV exposure boxes (more on that in another Hackster project), prototype and a few other things. I'm sharing this project as you may find the design useful as well.
Features:- 4 Channel low side high current (5-10ish Amps, untested but may run more) PWM FET control, ideal for LED strips, motors, fans etc. (NB: PWM control only - not suitable where current limiting is required for LED strips or high power LEDs).
- NeoPixel drive from internal 5V or external for higher current (>500mA).
- On-board 5V regulator for Photon, USB power connector and NeoPixel LEDs.
- On-board status LEDs for diagnostics.
- Switch input with software controllable power (e.g. push button with LED or hall effect sensor).
- DC current monitoring.
- 5V voltage monitor (to allow for possible battery operation of the photon)
- High side switched 5V USB A connector (power output only).
- 5V PIR sensor connector.
- External light sensor (3.3v).
- On-board temperature sensor and connector for external DS18B20 sensors.
- I2C external connector.
- WiFi connected through Particle Photon.
- Links up with SmartThings (e.g. lights on with motion sensor).
- Prototype area, connections available for 12V, 5V, 3v3, GND and all Photon pins.
All that goodness and on a 9cm x 10cm PCB!
Construction:Construction is fairly simple. PCB's are available at DirtyPCBs. All the components are reasonably easy to solder by hand with a little experience (and a solder wick), but if you plan on making more than one get a stencil made from DirtyPCBs or OSH Stencils.
For hand and reflow soldering, fit the smallest components first (resistors, SMD capacitors, LEDs - watch the polarity, temperature sensor, USB switch IC). For reflow soldering, put the PCB in the reflow oven or heat with a hot air gun to get a good flow.
Moving on to the through hole components. I found it easiest to fit the 2 and 3 pin connectors first, get a sponge bigger than the PCB, put the connectors in, place the sponge on top, invert the board keeping pressure between the PCB and sponge, then gently tack 1 pin of each connector.
Flip the board back. Now you can go through each of those joints, melt the solder on the one pin, the let the connector come loose and then press it squarely into place, so that you have a nice professional looking PCB.
And repeat:
Use a Photon to hold the sockets in-place whilst you tack a couple of pins either side, flip the board and make sure it's square, solder a couple more pins then remove the Photon to save overheating it and solder the rest of the photon socket.
Fit the remaining components as desired (if you don't want the 5V USB, don't fit that, etc).
The design uses a 7805 regulator, I prefer the DC-DC buck converters (7805 drop-in replacements readily available on eBay). Make sure they are set to 5V before you fit it. A regular 7805 gets warm dropping 12V to 5V for the Photon, so fit a heat sink if you use one.
Watch out for the polarity of the NeoPixel connector. On PCB Version 2.03 (5 Feb 2016), I rotated the connector but not the silk screen, so +Ve is actually -Ve. I've popped a couple of NeoPixels because of that!
Also watch out for the polarity of the power connector. This board has no protection against reverse polarity, so it's possible to do a lot of damage if you put the power in the wrong way around.
Size the current sense resistor (R14) appropriately. 0.02 Ohms for low current loads, for 5+ Amps I'm using 0.01 Ohms and update the firmware (showCurrent() -> *10 factor for 0.01
). Don't forget to fit an appropriately sized fuse.
The firmware uses Particle.function()'s to expose 4 internet callable methods:
- on - with arguments of "Under", "Over", "Sink" or "UV" for channels 1, 2, 3 or 4 respectively. Any other argument value switches on channels 1-3 and NeoPixels
- dim - arguments of "OVER" to dim channel 2 lights. Otherwise channel 1 and 2 are dimmed and the NeoPixels switched on.
- off - switches ALL lights off.
- neoPixelsOn - creates a rainbow effect as per the NeoPixel library.
I have the channels wired as:
- Channel 1 wired to under cabinet lights ("Under").
- Channel 2 for over cabinet lights, white LED strip facing up ("Over").
- Channel 3 for sink specific under lights. ("Sink").
- Channel 4 for a UV strip ("UV").
The main application loop just checks for a button press or the PIR being triggered. For either, a desired state is set based on the current state (Off -> Dim -> On -> Off), as well as gradual dimming of the lights if triggered by the button press.
The button LED (D7 on the photon, pin 3 on JP34) can give 3.3V @25mA from the photon. This is used to light a LED on the button, it is switched off during processing of the loop and on again at the end to help catch bugs in the loop code. It can also be used as in the video at the end to power a hall effect device rather than a button.
Connecting to SmartThings:Whilst it's possible to link a PIR sensor and other goodness to the PCB, it is much better nicer to use it as part of a bigger automation system, and this is where SmartThings comes in. You can add the controller as a SmartThings device (or device type) and control the lights from your phone.
You will need to load the device handler definition into SmartThings. Head over to the device handler guide and follow the instructions.
- Add a device type from "My Device Types".
- Create a new Device Handler.
- Paste in the code from the DeviceHandlerDefinition.txt file (attached or in GitHub)
- Add a virtual device for each of the PCBs you've made - I never actually did this; mine still run as debug versions.
- Ensure each device has a different Device Network ID. The value doesn't matter.
- Search Hackster for more details on SmartThings devices as there are lots of good articles to help you.
In addition to controlling your lights through SmartThings, you might also like to track light usage, temperature, power consumption as well as potential sensor data through Tinamous.
- If you don't already have a Tinamous account, you can register here.
- Add a Particle Bot to your Tinamous account. This will bring in your Particle devices as devices in Tinamous.
- As each device gets added, measurements published as senml measurements are tracked and fields automatically added for them.
- Devices can publish "status" messages which you can see on the Tinamous timeline.
- Variables are read on a defined time-frame (every
n
minutes) and stored as sensor measurements.
You can also control your lighting via Tinamous, either manually from the device page or as part of a notification that is set to call a Particle method.
For example, with a notification you could have it trigger on a status message of, "It's dark" or "I'm home" from one of your other devices or members and have the kitchen lights come on automatically.
In use:Here's a non-kitchen version using a hall effect sensor to toggle states for running UV lights, a fan and some NeoPixels (more on this in another project).
Alternatives:You might like to look at some of the earlier PCB versions, if you want more channels and a bigger prototype area. Version 1 supported 6 channels and had a large prototype area. Here's a purple PCB (no prizes for guessing where that was made).
And version 2.00 (an intermediate version) with more prototype area:
Comments