Controlling Lights with .NET
- Posted: Oct 31, 2006 at 3:39 PM
- 8,822 Views
- 11 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
|This article demonstrates how to control lights from your computer using custom applications written in Visual Basic and Visual C#.
Time Required: 1-3 hours
Video Tutorial: Controlling Lights with .NET
In the first DIY Tech video, I discussed the basics of the X10 home automation technology, and showed you how to add and replace switches to intelligently control lights in your home. In this video, I take it a step further and show you how to control lights from your computer using custom applications written with Microsoft Visual Basic 2005 Express Edition and Microsoft Visual C# 2005 Express Edition.
To do this project, you'll need to buy a CM11a serial controller to connect your computer to your X10 power line network. Plug it into your computer's serial port, and then plug it into an available electrical outlet. That's all you need to do to control your lights from your computer by using the software that's included with the controller, but that software's not very flexible, and it certainly can't match the power of the .NET Framework.
To enable you to communicate with the CM11a controller from .NET applications, you need a library. The most reliable library I have found is at CraigsCreations.com When you create your project, you'll need to add a reference to the X10 library and to the included serial port library. If you're not sure how to do this, don't worry, because I walk you through the process step-by-step in my videos.
Now that you can control your lights and other appliances from a .NET Framework application, the creative possibilities are limitless. I've always been fascinated with devices that physically show real-life information, like the BT Ambient Orb. However, I'm frustrated with their limitations:
So, for my project (available in both C# and Visual Basic), I decided to build my own lamp to visually show how well a stock is performing. I took a very binary approach, as shown in Figure 1. Naturally, any colored lights will do-you can even build your own glowing orb by placing red and green strings of Christmas lights in an opaque plastic sphere.
If the stock is going up, my application turns the green light on. If the stock is going down, it turns the red light on. To retrieve the stock information, my application queries the Delayed Stock Quote Web service at XMethods.net.
This is a very simple demonstration that you can either build yourself or customize to your own needs. By adding just a few lines of code, you can use the red and green lights to indicate the weather forecast, traffic patterns, the number of visitors to your blog, or whether Slashdot has been updated. You can also turn lights on or off in varying degrees by using X10 dimming capabilities. That's the amazing thing about writing your own code-the power to control the exact behavior of your software.