Introduction: Control AC Devices Wirelessly Using USB

Hi everybody!

In this instructable I will show you how to control Your home appliance switches using 2 computers a nxt with usb.

The basic idea is simple:

And here is the preview (Sorry low quality cam):

You need to know a bit Visual Basic .NET and have to have a Mindstorms LEGO Kit or any other microcontroller kit.

Please feel free to modify this idea.

And do vote me for the USB Contest if you like it!

Here are the references: -Gear - Bulb$File/Computer-Laptop-Black.png - computer - text document

Step 1: Material Required

Gather all your materials:

1) A Computer with Visual Basic 2008 Express Edition Installed. (Click the link to download)
2) Another computer. No Prerequisites.
3) A Lego NXT Mindstorms KIT.

Please feel free to modify this idea to suit to your requirement. For example, if you are fimiliar with C# rather than VB then use C# only...

No (Good) Images, Sorry.

Step 2: Make the NXT Robot

Please see the video to understand more.

Nxt Materials Needed:

1) 4 black connectors
2) 1 White shaft
3) 1 Motor
4) Yellow L-Bracket
5) Plus Shaped Shaft

See the video to understand...

Basically you need the robot to press the switch.

Step 3: Setting Up the Control Computer

Now we have to set up the computer that will switch on the light.

Get the NXT-G Software.

Open up visualbasic express and insert a timer control. The doubleclick on the form and Press Ctrl+A.

Then copy this code:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
        Timer1.Interval = 100
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Me.Text = Cursor.Position.ToString()
        Me.TopMost = True
    End Sub
End Class

Now run the program. Run the NXT-G program. And connect your robot to the Computer. Open up the remote control and click on the action button. It should move the arm of the bot. Hover the mouse over the action button and see the coordinates on the title bar of the VB application we just wrote. Write these values in notepad and save it.

Now create a weebly account. Make a new site and then on any page of the site, insert the a file to upload. Click on it and click upload a file. After that on your desktop right click and create a new text file named ins.txt. Open it in notepad and type the word 'off' in it. Upload it. In the website editor, right click on the download file button and copy the link address and save it in notepad.

Now you should have a url and coordinates.

In the same program which we wrote remove all the code and enter this code:

Public Class Form1
    Dim instance As MouseEventArgs
    Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
    Private Const MOUSEEVENTF_MOVE As Integer = &H1 ' mouse move
    Private Const MOUSEEVENTF_LEFTDOWN As Integer = &H2 ' left button down
    Private Const MOUSEEVENTF_LEFTUP As Integer = &H4 ' left button up
    Private Const MOUSEEVENTF_RIGHTDOWN As Integer = &H8 ' right button down
    Private Const MOUSEEVENTF_RIGHTUP As Integer = &H10 ' right button up
    Private Const MOUSEEVENTF_MIDDLEDOWN As Integer = &H20 ' middle button down
    Private Const MOUSEEVENTF_MIDDLEUP As Integer = &H40 ' middle button up
    Private Const MOUSEEVENTF_WHEEL As Integer = &H800 ' wheel button rolled
    Private Const MOUSEEVENTF_ABSOLUTE As Integer = &H8000 ' absolute move
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
    Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Integer, ByRef lpPoint As POINTAPI) As Integer
    Public Declare Function SetCursorPos Lib "user32.dll" (ByVal X As Integer, ByVal Y As Integer) As Integer
    Public Structure POINTAPI
        Dim X As Integer
        Dim Y As Integer
    End Structure
    Private Sub clickdown()
        Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    End Sub
    Private Sub ClickUp()
        Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
        Timer1.Interval = 2000
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
My.Computer.Network.DownloadFile("Your Weebly File Adress Here", "sample.txt")
        Dim txt As String = My.Computer.FileSystem.ReadAllText("sample.txt")
        If Me.Text <> txt Then
            If txt.ToUpper = "ON" Then
                Cursor.Position = New Point(Your Coordinate X here, Your coordinate Y here)
            End If
        End If
        Me.Text = txt
End Try
    End Sub

End Class

Where it is written' Your Coordinate X Here' and 'Your Coordinate Y Here' enter your X and Y values which you saved.
Where it is written, 'Your Weebly File Address Here' enter your weebly address.

Run the program and you should see 'OFF' in the titlebar.

You are done!

Step 4: Setting Up the Remote Computer

Now we need to prepare the remote of our system.

Just open up the web browser and login to your weebly account. Edit the site where you uploaded the 'ins.txt' file. Click on the ins.Txt file and click upload a new file. Make another file ins.txt on the desktop, this time with the word 'on'. Do not upload it yet...

You are done!

Step 5: Set Up Everything, and Give It a Test!

Now we are ready for the grand finale!

Make sure your program is running on the computer connected to the nxt bot. Place the pot near a switch as shown in the video. You can use books etc... to level it up.

Make sure, that the clicking the action button flips the switch and your porgram is running.

On the remote computer you just need to upload the file and watch the light turn on!

Feel free to ask question, modifications and comments!

USB Contest

Participated in the
USB Contest