LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Linux box to control electrical devices? (https://www.linuxquestions.org/questions/linux-general-1/linux-box-to-control-electrical-devices-657064/)

vbsaltydog 07-20-2008 09:42 PM

Linux box to control electrical devices?
 
I would like to use a linux box and cron to control a series of electrical devices for a project. The only thing I can find is an old paper on how to wire the pins of the parallel port to a set of relays but the paper is not the greatest and it is old so I am looking for the newest techniques for turning a cheap pc running linux into a control box for a number of electrical devices.

Any help is appreciated.

johnson_steve 07-20-2008 10:03 PM

Well you need the relays they are the only way to electricly switch alternating current. traditionaly the parallel port because this makes the control circuit very simple. alternitivly you could make a circuit with a microcontroller that attaches to the serial or USB port to control the relays but USB -> parallel adapters are cheap enough that I would just hack one of those up.

vbsaltydog 07-20-2008 10:09 PM

How are you able to control multiple relays via the parallel port? Can you write the controlling program in Perl or PHP? Are there any tutorials on how to control the parallel port or do you need to have experience in writing device drivers?

pinniped 07-20-2008 10:30 PM

Quote:

Originally Posted by vbsaltydog (Post 3221081)
How are you able to control multiple relays via the parallel port? Can you write the controlling program in Perl or PHP? Are there any tutorials on how to control the parallel port or do you need to have experience in writing device drivers?

You simply send values directly to the /dev/lp0 device:

echo -e -n "\x48" > /dev/lp0

Well ... not quite like that - as soon as the device is 'closed' the driver resets it. So you need to open the device in your controller program; you can control the data lines by writing a byte and you can control the signal lines via IOCTL messages.

Since you will be using 'cron', you will need to:
a. save the state of all relays in a file somewhere
b. design your relay board to 'latch' the state of relays - easily done by toggling one of the signal lines; if you don't do this, all relays will switch off when your program exits.

You might have to have a peek at the kernel's parallel port driver to see what IOCTLs you can use.

Alternatively you can search the internet for commercial relay boards which can be controlled either by the serial port or the parallel port. If you look at the Advantech web site for example, you can get RS485 modules which have multiple contact closures - all you need in addition is an RS232-RS485 converter (which Advantech also sell) - about $400 all up. But unless you can do your own electronic design (or find a kit in an electronics hobby shop), $400 is about what it will cost.

pinniped 07-20-2008 10:37 PM

Oh, I forgot to say - if you're playing with the mains lines, and especially where inductive loads like motors are involved, you'd better know what you're doing or you can really hurt yourself (and even destroy your computer). For example, double-pole double-throw relays have a special class which guarantee "break-before-make" - a feature which is extremely important in some situations (otherwise the relay shorts through your power supply - a spectacular sight).

johnson_steve 07-20-2008 11:09 PM

$400! I did this years ago (in dos) for a couple of bucks with a chopped up printer cable and 8 relays from the local surplus shop. of course I am the cheapest bastard you will ever meet and have been doing circuit design for over 15 years so YMMV. you might want to use opto-isolators on your parallel port. flyback diodes on any inductive loads couldn't hurt either. if you use a USB -> parallel adapter worst case you fry that. I highly doubt anything would make it back to your computer. I never had any trouble with the one I built and it didn't have any protection not even a fuse. I only used it for simple stuff like lamps and fans.

Here is an example of a very simple one like what I had:

http://www.instructables.com/id/Peri...-screen-saver/

Edit:
110v probably wont kill you but just to be safe; take off your wedding ring, wear rubber soled shoes and always keep one hand in your pocket. or you could just not touch it while it's plugged in. ;)

pinniped 07-21-2008 05:16 AM

Well, I really wouldn't encourage people to mix low and high voltages in proximity unless they really know what they're doing. Otherwise I can see any number of violations of the National Electrical Code and that's just a start. I've seen some absolutely dopey wiring and wondered that more people don't fry themselves. 110V will still kill if you grabbed the live and neutral, so I never tell people "110V probably won't kill you" - that just seems to be encouraging them to do silly things.

johnson_steve 07-21-2008 07:07 AM

Quote:

Originally Posted by pinniped (Post 3221302)
110V will still kill if you grabbed the live and neutral, so I never tell people "110V probably won't kill you" - that just seems to be encouraging them to do silly things.

It ain't the voltage it's the current and the path it takes through your body. a stun gun will send 10,000 volts through your body but it only travels about 2.5"

110v (or less) can kill you if it goes through your heart, hence me telling him to keep 1 hand in his pocket and wear rubber soled shoes. I think you're a bit more cautious (wise) then I. Maybe I'm just silly because I've been zapped to many times. :eek: or spend to much time playing with tube amplifiers that run at 140v - 400v DC.

Quote:

Originally Posted by pinniped (Post 3221302)
Well, I really wouldn't encourage people to mix low and high voltages in proximity unless they really know what they're doing.

I don't understand this comment. isn't this what relays were designed for? how is that any more dangerous then futzing with a lamp, fan or vacuum cleaner? it's true that maybe he could fry the computer if something went wrong and the relay is wired right to the mother board, but he said; "I would like to use a linux box and cron to control a series of electrical devices for a project." to me 'old linux box' reads "some crap I have in the basement or can get of craigslist for $50" far less then the $400 you suggest spending. then again I drive a $900 ford taurus. Now I'm not encouraging any silly behavior. you should always disconnect the power before you work on anything (not that professional electricians do.) but I'm not going to try to scare someone either. I'm not an electrician by trade, but I did go to school for it. the advice I gave him about his ring, pocket and shoes is exactly what my teachers told me.


All times are GMT -5. The time now is 01:00 PM.