Simple Home Automation

This was originally posted on another blog that I posted on occasionally, but has unfortunately become spam ridden.. thus I will not be linking to it.(Matt sort your blog out :P)  I will however take this opportunity to copy it verbatim as my first post on RobThePyro Hacks It 😉

Right time for my first real blog post… And its going to be about a little project I made to control the lights in my room from my PC over the parallel port! I’ve been thinking about this for awhile now and today I finally got round to doing it, quite simple in theory really: connect a suitable relay in series with your lights, connect it you the parallel port and write a simple application to flip a bit on the port thus turning the lights on and off! 🙂

OK so for starters I scratched around in my box of components and found a 12V DPST, 240V AC 5A relay! perfect for turning the lights on and off. Now firstly the parallel port is only capable of about 2mA @ 5v SOOO usually to switch the relay I’d have used a small transistor but I decided to go for a 4n33 optocoupler (http://pdf1.alldatasheet.com/datasheet-pdf/view/250132/VISAY/4N33.html) instead as this would allow us to not only switch the 12V needed by the relay but also optically separate the port from the rest of the circuit, should anything go wrong! Here is a pic of the relay all wired up with the optocoupler hot glued on the side. there is also a small 470ohm resistor inside the heat-shrink near my thumb to prevent the 4n33 from drawing to much current from the port and damaging it!

Relay

I tried to keep everything well insulated since we are going to be working with mains here!

Next the port: I didn’t have a spare lpt cable lying around so I’m just using my LED test cable atm (It has 8 leds connected to the first 8 bits of the port, I just disconnected the first bit and connected it to the relay for the mean time before I come up with a more permanent solution 🙂 I’m not going to go into more detail about this here, If you want to read up about it I suggest you check out this GREAT article by Levent Saltuklaroglu @ CodeProject.com

LTP port connecter

-don’t ask about the purple paint on my thumb :P-

Now for Power: the relay needs 12v to activate its coil, hmm where to get that? AH what luck! your PC’s outputs 12v on the molex’s amongst other places SO I re-purposed a molex pass-through to 12V fan adaptor to power my relay, I also made it easily detachable should I want to disconnect it. 🙂

LTP Wiring

Now for the switch wiring: I connected two decent pieces of wire onto the relays normally closed pole and centre pole (this means the lights will be on by ‘default’ unless the parallel port pin goes high (or 1) and activates the relay turning the lights off)

Dissasembled light switch

-Disassembled the switch-

Obviously for the next step your going to want to get a decent torch ready and turn the power off at the distribution board. I made a point of connecting the LOAD to the centre pin of the relay and not the LIVE wire so that the unused exposed pole of the relay doesn’t get ‘hot’ when the relay switches the lights off and risk a short inside the switch!! Its small things like this that keep these simple mods reasonably safe! 🙂

Wired light switch

-Attached for testing, sorry for shitty pic.-

AH! and she works! B) Note I left the light dimmer attach as well so I can still manually adjust brightness and turn them off if needed! Now to put the switch back together nicely!

Finished?

I haven’t thought of a nice cable management solution just yet but I am quite happy to have a couple wires lying around for the advantages I get!

The Software: I wrote a super simple C# application for testing that uses the freely available inpout32.dll to control the port, again I’m not going to go into detail here since there is tonnes of info available on Google and if you want the basic info on controlling the port I’m going to send you here again 😛 So this is what the app looks like atm:

App

And now for a vid of the action! 🙂

If anyone is interested in the app or the sauce (YUM! :P) post a comment here and I’ll upload it! Once I get some more time I’m going to write a much better app that can turn on/off at certain times, be controlled over my network from another PC or the internet!! and even have a small app on my phone so I can turn the lights on/off from my bed!!! And anything else I can think of!

Some other considerations: for those of you that know a thing or two about electronics, yes I should have put a diode across the relay to prevent feedback spikes from damaging the PSU, but I’m fairly confident that such a small relay wont be a problem -time will tell!- also I have kept this REALLY simple, I am planning alot of future upgrades like controlling other devices, RS-232 or USB control, and possibly even implementing a Triac to dim the lights from the computer!!! add a couple of sensors and you could be looking at ‘SMART’ lighting that would dim to the right level depending on ambient light, whether your in the room or not, etc.

Right well that’s it for now!

Rob~

Discalmer: This project deals with mains that can injure or KILL, so we cannot be responsible to you or your property if you attempt this bla bla etc. so be careful out there kids! 🙂


Posted

in

by

Comments

2 responses to “Simple Home Automation”

  1. Igor Toledo Avatar

    Hello, could you send me the program shown in the tutorial? I intend to make my home automation too.

    From already thank you.

    1. Rambo Avatar

      Hi Igor

      This code is quite outdated now and there are better ways to do these things.. what are you trying to automate?

      Rob.

Leave a Reply

Your email address will not be published. Required fields are marked *