iPhone remote controlled lamp

This project uses the iPhone and a raspberry pi to remote control the lamp. Both the iPhone and the raspberry pi are connected to the wifi router. The lamp on/off commands are sent from iPhone and received by the raspberry pi embedded system. Then the raspberry pi triggers the IO to control the lamp through a relay. The lamp can be replaced by other home appliances. The software is written in Python and it can be easily port to other devices.

Step 1: System diagram

The system diagram is shown in this figure. The data flow is straightforward. The iPhone is connected to the wifi router wirelessly while the Raspberry pi is connected to the wifi router through a lan cable (this can change to wireless with a wifi adapter installed in the Raspberry pi). One of the Raspberry pi’s IO is connected to a relay board. Since the relay board control voltage is 5V and the Raspberry pi output voltage is 3.3V, a transistor is used to perform the voltage transition; the detail will be introduced in step 3. Then the lamp can be controlled through the relay board.

Both the iPhone and the Raspberry pi need to run a software for communication. In this project, Python is used as the programming language. In iPhone, Pythonista is installed and run the script, a UI is also designed. In Raspberry pi, a Python script is run automatically after booting the system. The communication is based on socket TCP mode.

Step 2: Electronics
Here are the electronics parts, almost all of them were got from http://www.kynix.com/.They are of great quality and are suitable for my project.

A Raspberry pi board

A relay board

A universal board for connecting the Raspberry pi and the relay board

A lamp

A wireless router

A USB charger for powering up the Raspberry pi

A transistor 8050

Two resistor (1K ohm)

Lan cable and USB cable and

Of course an iPhone as the remote control

Step 3: Circuit

Since the output voltage of the Raspberry pi is 3.3V and the control signal voltage of the relay board is 5V, we need to change the 3.3V signal to 5V signal. A voltage converter circuit is shown in this picture. A 8050 transistor is used to perform the transition. When the output GPIO of the Raspberry pi is low, the relay board input signal is high, and the relay is on, the lamp will turn on. When the output GPIO of the Raspberry pi is high, the relay board input signal is low, and the relay is off, the lamp will turn off.

Step 4: Software-Raspberry Pi

Some modification of the Raspberry pi is needed to perform this project’s task.

Auto login

Static IP

Auto-run script

GPIO control

Socket server

Details are list below:

Auto login
edit /etc/inittab, change

“1:2345:respawn:/sbin/getty --noclear 38400 tty1” into

“1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1”

Static IP
set the IP as “192.168.1.200”

edit /etc/network/interfaces, change

“iface eth0 inet dhcp” into

"iface eth0 inet static

address 192.168.1.200

netmask 255.255.255.0

network 192.168.1.0

broadcast 192.168.1.255

gateway 192.168.1.1"

Auto-run script
edit .bashrc, add at the bottom:

“sudo python server_5.py”

server_5.py is the script to serve the lamp control command

GPIO control
in order to contol the IO, RPi.GPIO is installed,

note: the version is changed to the latest one

Socket server
the Raspberry pi is acting as a socket server

the Python script is attached as server_5.py.
Step 5: Software-iPhone

Pythonista is installed in the iPhone to run the Python script, it also provides an UI design function.
Step 6: Connection and Testing

modify the lamp, break the live wire and connect into the relay board, one end connect to the com port, and another end connect to the normal open port.

use the GPIO 11 of the Raspberry pi to control the relay

connect the iPhone and the Raspberry pi to the wifi router

the screen of the iPhone is captured after running the script, there will be pop-up notifications after press On and Off buttons.

two demo videos are also embedded

It can be easily modified to control other home appliances. And it is quite convenient since you can control it everywhere when you can receive the wifi signal.