The following project is about making a remote light switch which can be controlled from a (normal) local switch or from a phone. It will help you to turn on or off a light without touching the switch on wall - just using a phone! For example, when reading a book in bed, there will be no need to stand-up to turn off a light and then go back to bed. With this project, you can use your phone to turn off the light, then go sleep.
Here is the result (demo):
Here is the result (complete): PCB toggle switch + Phone application
This circuit is designed to detect a pulse from the normal switch or from the remote switch (by phone), allowing User to turn something on/off by either switch. So, in case they cannot use the remote switch, User can still turn a light on/off by the normal switch.
IC-555 is the center of the circuit for this toggle switch.
As in the schematic, there are two sections:
- Toggle circuit by IC-555
- Trigger signal: (1). Capacitor and opto are used to detect rising/falling edge from normal switch. (2). Remote switch (by phone).
The following is a completed PCB board:
Raspberry Pi will be used for the remote switch. Raspberry Pi will host a local webpage (which contains the remote switch) and also connect to WiFi. So, User may use a phone (connected to WiFi) to open the local webpage and turn on/off the light.
Raspberry GPIO map:
Pin 7 (GPIO7) will be used for the remote switch. So, Pin 7 and Pin 6 (GND) will connect to the toggle switch shown in the schematic (in Section 1).
2.2. Making local web interface:
2.2.1. Install WiringPI
WiringPI is used to control GPIO.
$ sudo apt-get install git-core $ sudo apt-get update $ sudo apt-get upgrade $ git clone git://git.drogon.net/wiringPi $ cd wiringPi $ git pull origin $ cd wiringPi $ ./build
Checking after the installation of WiringPI:
$ gpio mode 0 out
🠚If nothing special appears, everything's fine. Sample command, write and read pin 1:
$ gpio write 1 0 $ gpio read 1
2.2.2. Install web server
Install Apache HTTP server and PHP5 extension:
$ sudo apt-get install apache2 php5 libapache2-mod-php5
2.2.3. Web interface to GPIO of Raspberry
Local web uses PHP to control GPIO through WiringPI (installed in Section 2.2.1). To interface between local web and Raspberry, there is a tutorial available; this project is mainly base on that tutorial.
After modifying again, make the local web as follows:
- Local web is saved in
/var/www/(note that: The file "temp" should be changed to 777)
My local web can be download at this link here (Google share).
2.3. Control by Android app
Fortunately, we successfully made an Android app. This way it is easy for User to turn on/off a light. The app can be downloaded from the Google store with keyword "Data2server" or by following this link.
The screen of the app looks like this:
There are 2 settings for the local web address and a key setting:
First of all, User needs to check the connection status from the phone to Raspberry board. That's it! The light switch is in your phone!