Introduction: 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.

1. A Raspberry pi board

2. A relay board

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

4. A lamp

5. A wireless router

6. A USB charger for powering up the Raspberry pi

7. A transistor 8050

8. Two resistor (1K ohm)

9. Lan cable and USB cable and

10. 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.

1. Auto login

2. Static IP

3. Auto-run script

4. GPIO control

5. Socket server

Details are list below:

1. 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"


2. Static IP

set the IP as ""

edit /etc/network/interfaces, change

"iface eth0 inet dhcp" into

"iface eth0 inet static







3. Auto-run script

edit .bashrc, add at the bottom:

"sudo python" is the script to serve the lamp control command


4. GPIO control

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


note: the version is changed to the latest one

5. Socket server

the Raspberry pi is acting as a socket server

the Python script is attached as


All the modified files are attached.

Step 5: Software-iPhone

Pythonista is installed in the iPhone to run the Python script, it also provides an UI design function.. The script is attahed as

Introduction of Pythonista can be found here:

Step 6: Connection and Testing

1. 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.

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

3. connect the iPhone and the Raspberry pi to the wifi router

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

5. 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.


heliophagus (author)2016-10-14

The article doesn't make it clear that the user has to write their own UI script to create the ON and OFF buttons in the Pythonista environment, and link the click actions to the script that the author provides. Running that script will producing a missing UI error, and the author provides no hint that the user will have to code this UI themselves. For beginners in Pythonista, this would detract substantially from the usefulness of this otherwise interesting article. That said, if the UI is written, the code and instructions provided work well (except for a missing "GPIO.setmode(GPIO.BCM)" statement in the Raspberry Pi code, and the fact that the static IP instructions provided will not work in the Pi2 onwards).

AhmetD (author)2014-08-02

nice work bedava firma kayıt ücretsiz web sitesi oluşturma ve firma rehberi

Samuel LIU (author)AhmetD2014-08-03


HualiC (author)2014-07-31

well done!

Samuel LIU (author)HualiC2014-07-31



Nice job! That light is super pretty too!