Computer controlled tubelights!
A few months back, I implemented an interface using the Parallel Port to control my room’s tubelight and bulb. Such circuits that interface electrical devices to the computer through parallel port are extremely popular on the internet. My version uses one optocoupler (MCT2E), one transistor, a pair of resistors and a relay for every device I wish to control. So I’ve got some two implementations of this as of now.
A simple C program can help control the bits on the parallel port (and thereby the devices). Again, there are examples all over the internet like this one, that help you do that. I wanted something more flexible and easy to use, so I wrote a rather long program (maybe it is an overkill). Forgive me for the unclean and dirty code. Here it is. You can kick me for writing dirty C++ – I hardly learnt any C++. (I learnt that it is dumb to use stdio.h, fprintf etc in C++ code, and that all C++ code must be encapsulated, but who cares! I wrote this for my own use, and am graciously releasing it, so take it if you must, and if you do write better and cleaner versions, please link them in the comments to this post! :-D). What this code does is to implement something that can toggle the state of a specified device.
In this code, I read a configfile that defines the values of the bits that need to be switched on to control each of the devices. I implemented this so that it remains extensible – I’m planning to extend this to control my fan as well :-D. Once you’ve defined values in the configfile, you can then do things like:
sudo lpdevctl bulb
You can also specify a default device that’ll get toggled if you just say sudo lpdevctl (without an argument).
Once you have such a program, you can do lots of interesting things. The simplest of them would be to switch on your tubelight after 10 seconds delay, say:
sleep 10; sudo lpdevctl tubelight
Something slightly more interesting:
for i in `seq 1 5`; do sleep 0.5; sudo lpdevctl bulb; sleep 0.5; sudo lpdevctl bulb; done;
That flashes the lamp 5 times. Even more interesting – switching on your tubelight every day automatically at 1830 hours is like setting up a cronjob at 1830 hours to execute sudo lpdevctl tubelight.
I use a Jabber client called mcabber which has external action triggers, that can call an external action when something happens. So if somebody pings me on IM, I am notified of it through the flashing of my bulb (which I seldom use otherwise) instead of some ding sound that interrupts the beautiful music I’m playing. Besides, this alert is easy to switch off – because I can go and turn off the light bulb switch – and the relay is in series with that!
Once you get a command on your Linux system to do something, the ways in which you can extend it are infinite and are only (un)bounded by your creativity!
I like the idea of switching on my room light while sitting in my department computing facility using SSH 😀