Introduction: World Wide Switch
This shows you how I made my remote switch that I use to switch on my PC at home while I'm not there, using an Android app.
My PC at home is off when I'm away but sometimes I need a file from it or I want to access it with RDP remotely. I use a home made Android app to switch on my PC remotely. The PC is connected to a solid state relay that is controlled by an Arduino and ethernet module. The Android app communicates via the internet with the ethernet module.
Step 1: Requirements
Hardware needed:
1x Arduino UNO
1x Solid state relay
1x Ethernet module
1x resistor 10K
1x resistor 330ohm
1x red LED
Some wires
The relay can switch 500W easily without being cooled. The LED will be used as a signal lamp to check whether the system is still functional.
Software needed:
You need the Arduino sketch and the Android app as discussed in the following steps. Both are open source.
Step 2: Hardware Assembly
The schematic diagram shows how to set up the hardware. This diagram shows the pin numbers of the Arduino as well as the pin numbers (between brackets) of the ethernet module and the pin numbers of the relay.
The pin numbers of the relay are also printed on the relay itself.
The anode of the LED (long pin) is connected to the 330 ohms resistor and the kathode (short pin) is connected to ground.
The 10K resisotor can be connected to the relay and is held by the screws on the relay (see photo).
Computer
The computer is to be connected to the mains and the relay (see schematic diagram). Instead of a computer you can connect lamps, tv sets, camera's, micro wave ovens, etc. Whatever device you want to switch on.
If you want to connect a micro wave or other high power device (more than 600 W) then you need to cool down the relay by connecting it firmly to a cooling plate.
Step 3: Arduino Firmware
I have written an Arduino sketch which listens on the internet for incoming connections (coming from the Android app). The sketch has a very simple function to check if the Android app is yours (to prevent others from using your switch).
Possible improvement is to write a better hash function or even embed more complicated security. If you do this you must also add the same functionality to your Android app.
The sketch has some constants that you may need to alter like the IP address of the Arduino web server (the sketch implements a webserver) and the port.
Attachments
Step 4: Android App
The Android app contains one main activity and a screen to set up the IP address of your Arduino server. When you start the app for the first time you have to wait until the internet connection times out, and after that set the IP address in the preferecne screen immediately.
The main acticvity of the app has a hash function that is used to create a password for communications. You may change this to some other calculation or embed a security algorithm. Use the same algorithm in the sketch.
Integer Hash() {
return (Token << 3) + 3; // Same hash function as in the arduino sketch
}
Attachments
Step 5: Router Setup
The IP address of the Arduino (set as a constant byte array in the Arduino sketch) is a local address on your LAN. To be able to connect to it from outside your home you need so set the Arduino as a virtual server. You do this on your router.
Use your browser to go to your routers embedded web server and look for a page called Virtual server list or Forwarding or something similar. Add a server by adding the IP address of the Arduino (192.168.0.88 in my sketch) and the port (8080 in my sketch). The port is sometimes referred to as Service port in your router's webpage.
Now you can test your system without connecting a computer or other device to the relay. Point your browser to the WAN address of your home (find the current WAN address in your router settings, make a note of it). And you should see the web page generated by the Arduino.
If this works you are ready to use the app. Set the WAN address as a preference in the app by selecting the Settings menu of the app and switch the relay on and off using the app. The LED on the relay shows the on/off status of the relay.
Step 6: Things to Do
Things you can do to improve this device:
- Create better security (in the sketch and in the app).
- Add a speaker to make some noise whenever someone tries to connect to the server. When someone tries to 'hack' you when you are at home you will be notified.
- Add an LCD to show a list of all IP address that have tried to connect to your Arduino server.
- Add a second relay to switch on an IP-webcam (connected to the internet) so you can watch your monitor (or whatever you want to see).