This post shows my efforts to package up an 8 port relay module with a raspberry Pi. I did this for use with my home automation heating project. But it could be used to control any number of other things. I post it up here in the hope that someone else will find it useful.
The following is a list of things I get to build my system:
- 1x Raspberry Pi Model-B (Model A would suffice)
- 1x Edimax EW-7811Un wifi dongle
- 1x Generic 5V 8 Channel Relay Module – ebay
- 1x 5V 1A Power Supply
- 1x Plastic Box PX-4 Grey 114.5×184.5×62.5mm
- 1x Jumper Cables
- 2m Mains Cable – I had Flex Round 3 Core Lying around.
- 1x Terminal Wall Blocks
- 6x Zip Ties
- Epoxy Glue
- Lots of Lego – My Loft
Raspberry Pi Model-B + Wifi Dongle
I attach the wifi dongle into the pi. Easy.
Raspbery to 8 Module Relay
The first thing to get wired up and working is the 8 module relay block using the Jumper Cables in the wiring configuration seen below. There is a nice post describing how to wire up these relays with a wiring diagram. I do not bother with the transistor board, instead deciding to do the default state in software. I go with the following pin mapping:
The relays on the board are Songle SDRs. They have the following behaviour: (See wiring diagram above for letter pin mapping.)
No power to relay control
Power to relay
Power to relay and pi
C ----o / B---- A-----o
Power to relay WebIOPi started pin OUT LOW
C ----o B---- \ A-----o Indicator LED on relay board lights up.
Power to relay WebIOPi started pin OUT HIGH
C ----o / B---- A-----o
Below is a picture of the pi wired to the relay module.
5V 1A Power Supply
To power the pi and control board I will use a standard pi power block. I want to use the mains voltage that powers the timer units in the same way to power the pi. To save space I saw open the plug to get the circuit board out.
Here are some images of the circuit board, I have wired it up ready to go in the project box.
I have cut down the 5V wire as it was longer than I needed. I have chosen to use the micro USB connector rather than wire straight into the Pi as i means i get the fuse protection and makes future disassembly easier.
To package everything up I use a 114.5mm × 184.5mm × 62.5mm kit box. I start by drilling holes for the three wires (that I need it for in my current project) . I space the holes equidistant so that if later I want to re purpose the box for something else I can drill another 5 holes to maximise the 8 relay modules. I attach rubber grommets so the wires will sit snugly. To do this I have to chisel away part of the groves around the hole.
This Process can be repeated until there are 8 holes, one for each relay switch.
The box has groves down the side that fit the relay module block quite neatly. I now need to fit all the other components. To begin with i epoxy some lego bace blocks onto various areas of the box, when I do this I am careful to make sure that the various separate sections fit the lego block patten so that lego from one area can clip together with Lego from other sections. I lay a base for the area where the transformer circuit will go and another to raise the pi above the floor (where the wires will go).
Now that the base is in it’s time to build the transformer enclosure. I use blocks with holes in to allow access for the 230v and 5v wires.
When building the enclosure I include bracket bits to hold the right side of the relay board.
The relay board now fits snugly into a grove on the left side of the box and the bracket mounts on the transformer enclosure.
Close up on the bottom of the relay block. The heating control wires will connect here. You can also see the Lego arch mounts for the platform where the pi will be mounted. This gives good space to run the wires under.
The Pi mount. This will sit on top of the arches and the pi will fit inside this.
The Pi mount installed in the box.
All the components are now installed in the box and it all fits nicely. No the only thing left to do is to take it apart again and fit the wires.
The lid fits onto the box to finally seal everything away. I notice that it doesn’t sit totally flush and have to make a last min modification of cutting a little divot on the right hand side to fit the rip over the top edge of the relay control board.
And there you have it, a fairly simple boxed up raspberry pi with relay module and power source. As the wiring I use (Flex Round 3 Core) has three cables in each and I only need two for each relay on the current project I can re-puposed two of the spare wires to provide Live and Neutral for the power block. If this doesn’t float your board you could cut one further hole for these wire.
The box in situ. Three wires come in from each of the devices the box is controlling. As these cables carry three wires; Live, Neutral and Earth and I only need two from each to complete the circuit I decide to use one of them to bring the neutral line to power the pi (the live comes of one of the control circuits). I terminate the other redundant two in a bit of spare cabling sheath. To stop the wires from being ripped out I attach some zip ties to the wires at the point just before they leave the box, I tighten them with pliers to make sure they dig in. Safety first.
Everything is resembled again in situ.
Now we have all the hardware done it’s time to get the software up and running to control this thing. I choseWebIOPi as it gives you a pretty complete stack right up to a web server with pin layout. Instructions are all there on setting it up and getting it running. Enjoy.
Here is a collection of content i hold in high regard:
Great videos on all sorts of topics from Architecture to Religion.
Good tech news and general programming related topics.
Pretty much any Documentary he has made as well as his blog for interesting insights into geopolitics and general socio political behaviour.
An insightfull view of the world using statistics through the Gap Minder software. Often reporting on good things going on in the world with the odd amusing quip thrown in.
- TED Profile and videos (Watch “Hans Rosling shows the best stats you’ve ever seen” first.)
- Gap Minder
Doubling time and the rule of 70
Lecture on what exponential growth really means to you. The answer to this question is incredible important in a way you will not comprehend until you watch this video. It also teaches you what compound growth is, this is important for anyone who has a bank account.
- Video Part 1
- Video Part 2
- Video Part 3
- Video Part 4
- Video Part 5
- Video Part 6
- Video Part 7
- Video Part 8
Multivax and the The Last Question
A short story by Isaac Asimov on the future. Shows that entropy is kind of scary.
A documentary about typography and graphic design in the last century. It stars some very interesting and enjoyable characters, talking passionately about a subject you engage in everyday but probably think little about.
Photography – Cambridge in Colour
If you read all the tutorials and articles on this site you have pretty much undertaken a basic to mid level digital photography course without paying anything.
Photo Editing – dpBestflow
If you are into photography you should know all your tools, this extends to more than just your camera. You should know the content of these links and how they apply to making your pictures pretty.
Interesting books. No particular order.
- ISBN: 0141032405
- War is not fun.
- Zen and The Art of Motor Cycle Maintenance
- ISBN: 0061673730
- The Curious Incident of the Dog in the Night-Time
- ISBN: 0099450259
- The Hitch Hiker’s Guide to the Galaxy
- ISBN: 0434003484
- Brave New World
- ISBN: 0099518473
- Eats, Shoots and Leaves
- ISBN: 0007329067
If someone supposedly tells you what a drug is like and this website doesn’t have a similar story they are probably lying. This place has more interesting stories about drugs than the 60s rolled into one.
- cmd.fm Command Line tool for internet radio
I Have recently been trying to find a way of standardising the on-line catalogue we use at work. Something to do with the same data being entered into multiple databases, lots of manual data entry you get the picture.
I have been a bit disappointed to discover that there is very little in the way of a standard format for exchanging catalogue information. I can understand why Online Shopping Cart projects have been slow to implement this “we don’t want them running away from our system” but i would have thought there might have least been a push from some of the more confident open source movements.
Please correct me if I’m wrong here i haven’t looked at them all
After digging around a bit i did find that someone has created a format called the Open Catalogue Protocol or Format but unfortunately whoever implemented doesn’t seem to be around any more. (http://www.martsoft.com/ocp/)
If anyone knows where i could find a DTD for this please let me know.
This is the only example i could find of its implementation:
From: http://www.martsoft.com/docs/hierarchy.txt Date: 1999-05-05 <?xml version="1.0" standalone="yes"?> <!-- Catalog hierarchy file: this file only contains a hierarchy of categories, no products; the catalog engine caches it in memory --> <catalog> <category name="Computer Product"> <param name="NumberOfProduct" value="23"/> <attr name="Part ID" value=""/> <attr name="Vendor" value=""/> <attr name="Description" value=""/> <attr name="Cost" valuetype="float" value="" unit="dollar"/> <category name="Computer Hardware"> <link name="" valuetype="Alternative" value="OCP://www.martsoft.com/UPYP/Computer Related/Computer/HW/"/> </category> <category name="Computer Software"> <attr name="title" value="Software xxx"/> <attr name="Platform" value=""/> <attr name="Version" value=""/> <link name="" valuetype="CrossSell" value="OCP://www.xyz.com/sw/"/> <product name="11000078"> <link name="" valuetype="PartOf" value="Computer Product/Computer Software/11000079"> <attr name="Part ID" value="33444IET"> <attr name="Vendor" value="Microsoft"> <attr name="title" value="Microsoft Word"/> <attr name="Cost" valuetype="float" value="29.99" unit="dollar"/> <attr name="Platform" value="Microsoft Windows 98"/> <attr name="Version" value="7.0"/> <attr name="Description" value="Word Editor"/> <value> <val>Inline pictures</val> <val>HTML ready</val> </value> </attr> </product> <product name="11000079"> <link name="" valuetype="HasPart" value="Computer Product/Computer Software/11000078"> <attr name="Part ID" value="33444FFY"> <attr name="Vendor" value="Microsoft"> <attr name="title" value="Microsoft Office 98"/> <attr name="Cost" valuetype="float" value="399.99" unit="dollar"/> <attr name="Platform" value="Microsoft Windows 98"/> <attr name="Version" value="7.0"/> <attr name="Description" value="Office product suite"/> </product> </category> </category> <category name="Real Estate"> </category> </catalog>