I'm working on a Raspberry Pi based heating control system but I'm hoping my approach could be used for a variety of sense / control scenarios (e.g. light, water moisture, heating etc).
I've attached my design so far and put notes below to share the idea in case anyone else would like to do the sam.
I'd welcome comments! I have not built anything like this before so it's new territory for me and I'd love to get some advice. Will it work, any draw backs of flaws?
Credit to Mike for his very well explained explanation on "http://www.raspberrypi.org/forums/viewtopic.php?t=36225
How to wire a Raspberry Pi to a Sainsmart 5v Relay Board" in this http://www.raspberrypi.org/forums/viewtopic.php?t=36225
(right click and open theses images in new tab to see them enlarged)
- 1x Raspberry Pi - Micro Controller, offers range of choice for programming control logic and building a user interface to the system
- 2x Sainsmart 8x Relay (operates at 5V throughout, could also consider the 16x relay but this requires 12V for the relay circuit)
- 1x MCP23017-E/SP - I2C 16 bit port expander (1.8V-5.5V Supply. DIP Package.)
- 3x ULN2003AN - 7x Darlington Transistor Array (PDIP Package)
- 2x AD7997 - I2C 8 channel, 10 bit ADC (2.7V-5.5V Supply. TSSOP Package)
- 2x 5v 1A power supplies - 1x for the RPi, 1x for the sainsmart boards.
- Various capacitors and resistors - as required for noise filtering and pull up / pull downs.
- Pi Cobler, Project board, jumper wires, solder etc.
>>> THE GOAL
Control an environment (in this example temperature in many "zones") using a programming language (e.g. python) and Web User Interface (e.g. a web framework like python's django). Keep the electronics easy to construct (solder etc) with relatively cheap to buy the components.
>>> THE RELAYS
Sainsmart 8x relays as a cost effective way for switching mains voltage. The advantage of two 8x relays rather than one 16x is the 8x version can use a 5v supply, the same as the Raspberry Pi. The 16x requires a 12v supply.
>>> THE TRANSISTORS
The ULN2003AN Darlington Transistor Array was selected because it is amiable in an easy to solder, relatively cheap, DIP package. Further advantages of using these transistors include inverting the logic so a high bit turns the relays on, and interfacing between the 3.3V port expanders and the 5V really boards. Darlington pairs are not strictly required for this circuit (see “How to wire a Raspberry Pi to a Sainsmart 5v Relay Board” in the references) however the ULN2003AN is a nice alternative to purchasing individual transistors and resistors. Unfortunately it only providers 7 transistor pairs per chip so three ULN2003AN’s are required to cover 16 channels.
>>> THE I/O
For input and output the MPC23017 port expander and the AD7997 ADC were selected for their 3.3V I2C compatibility. More of these chips can be added to the I2C bus to expand the number of relays and sensors beyond 16x.
>>> POWER SUPPLY & ISOLATION
The circuit works using 5v power supplies and 3.3v from the RPi GPIO. It is assumed all have a common ground. The Raspberry Pi requires one supply, capable of 700mA to 1A, which will power the Pi itself and the 3.3V MPC23017 and AD7997 chips. The Sainsmart 8X relay requires two 5v supplies, VCC and JD-VCC, which can be made common using a jumper across pins 2 and 3 on the board. There is an advantage to supplying these separately because, since the board uses opto-isolators, the really circuits will then be physically isolated from the control circuits. VCC will draw around 24mA total (1.5mA x 16) so could be supplied from the GIO 5V out pin. JD-VCC will draw significantly more, around 960mA (60ma x16) with all relays activated so could be powered from a dedicated 1A 5V supply.
>>> START UP STATE
At start up the Raspberry Pi may move the GPIO pins though various states (low, floating, high?). If/where this is the case the I2C port expander and transistors offer a simple way to avoid any unintended switching that may occur if the relay board was attached directly to the GPIO. All bits of on the port expander should remain low or floating during start up and the transistor array includes a pull down resistor which will keep the logic low (relays off) until the port expander is intently set to output a logic high.