Raspberry Pi GPIO Home Automation




I had heard about GPIO pins on the raspberry pi and decided to do something with it. And with the holidays coming, wouldn't it be great to be able to turn on and off your light display from the web!  This is a pretty simple project that creates a web app for controlling lights.  It uses the Raspberry Pi for the internet connection and a wireless remote control to turn on and off the lights. The tricky thing is to connect the Raspberry Pi GPIOs to emulate pressing the buttons on the remote control.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Parts

Parts needed:
• Raspberry Pi
• Remote controlled outlets
• Ribbon cable
• Solder

(Not shown)
• PCB board
• Resisters

• Soldering gun
• Dremel/Hacksaw
• Screwdriver
• Wire cutters
• Wire striper
• Multimeter

Step 2: Web Server Setup

I choose the Web2Py framework for it’s ease of installation and use.  Installation is very simple.  Follow the instructions (repeated here) at http://web2py.com/books/default/chapter/29/13#One-step-production-deployment

Connect your R-PI to the internet. Logon to your R-PI and enter the following at the command line:

wget http://web2py.googlecode.com/hg/scripts/setup-web2py-ubuntu.sh
chmod +x setup-web2py-ubuntu.sh
sudo ./setup-web2py-ubuntu.sh

Follow the instructions on the screen.  This step will take several minutes and you may see some errors in the process, but it seems to work anyway.  The mail configuration is not really important, you can just set it as “no configuration”.  When asked about your location and such, the values aren't critical, do your best.  The most important thing is to remember the admin password that you select during the installation

Once the installation is complete you should be able to connect to web2py server from your computer.  In your computer's browser enter the address to your Raspberry Pi.  It is very important that you used https when connecting to the web2py server.  Your URL will look something like:  or  https://rasberrypi

You may see a security warning in your browser.  That's OK,  you can safely ignore this warning.  If everything worked correctly, you should now see the welcome page for Web2Py.

Step 3: Make the Board

Probably, the hardest part of this project is to figure out how your remote control works. 

As Dave Jones says, "don't turn it on, take it apart!".  Open up the case on your remote control.  I hope your's is as easy as mine,  it just had 3 screws.  Look carefully at the board on your controller and find where the buttons are, most likely they are traces on the PCB activated by rubber button.  Follow the traces connected to the button,  there should be 2 connections to each button.  One side of the button will be connected to a chip on the board (it will either be a black rectangle with legs, or a black plastic blob), the other end will be connected through a resistor  to either the battery + or the battery -.

In my case, the buttons were connected to the + of the battery.  This means that the button "pulls up" the micrcontroller line to the supply voltage when it is pressed.  To emulate the press of a button, we will connect the GPIO of the Raspberry pi through a resistor to the of the button that is connected to the chip on the board (rectangle or blob).  

The first schematic shows how the buttons were connected on my remote.  The second schematic show how to inject the signal from the Raspberry Pi.  

I created a board to make this as small as possible and be able to add the extra hardware into the case for the remote.  The layout for the board is included.  I used surface mount resistors because I had some, also the values aren't that important, 330 Ohm - 1K Ohms would be good choices.  If you have different values and through hole resistors, that's fine,  it will work fine. Also, creating a custom board for this is not required, you can certainly solder resistors directly to the remote's board. (good luck :))

Step 4: Connect to the Controller

So for connecting to the controller all you had to do is find the pads in the back of the controller that connect to the microcontroller. I had some wire hanging around so I soldered the pads to the board and the ribbon cable with the right pins corresponding to the GPIO pins on the Rasp Pi. I had to  use my multimeter find the right pins.

Use your dremel or file to make a slot in the back of the remote case so that the ribbon cable comes neatly out the back.

Step 5: Connect to the Pi

All I had to do to connect to the Pi was put in the ribbon cable and since I had to cut my ribbon cable because a pin was solid and blocked off. I just had to put the ribbon cable all the way to the top.

Step 6: Install App

Now that the hardware is setup, the app that controls the lights needs to be installed.  The attached file is source code for the application,  you need to install  into Web2Py.

1. Download the file, and unzip the file.
2. From your web browser (on your pc) connect to the Web2Py server using https.  https://raspberrypi/
3. Select Administrative Interface
4. Enter the password that you set when Web2Py was installed
5. Under "Upload and Install Packed Application" enter the application name of "Home_Lights" and select a the "web2py.app.Home_Lights.w2p"
6. Press install.
7. After the application installs you will see the application added to the list.

The application requires you to login to the application,  you don't want random people turning on and off you lights!  So we must create the users.

1. Under the Home_Lights application press edit.
2.Under Model, press "database administration"
3. Then press the "New Record" button next to db.auth_user
5.Enter First Name, Last Name, Email, and password.  All other entries can be ignored.  When done press "submit"

You can now navigate to the Home Lights application:  http://raspberrypi/Home_Lights and login with your email and password.

Step 7: Setup GPIO Server

At this point your application still won't work because access to the GPIOs on your pi needs to be set up.  Access to the GPIOs on the Raspberry Pi requires root access.  It isn't wise to run your web server under root, so a separate server was implemented to provide access to the GPIOs.  

Logon to your Raspberry Pi (ssh or at the command line, it doesn't matter) and install 1 python module:

wget http://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.4.2a.tar.gz
tar zxvf RPi.GPIO-0.4.2a.tar.gz
cd RPi.GPIO-0.4.2a
sudo python setup.py install

With that module installed, the server can be started (must be running for the web application to work)

sudo python /home/www-data/web2py/applications/Home_Lights/modules/GPIOServer.py

Step 8: Home Automation

You should now be able to control your lights from any web browser,  Your computer, a smart phone, or even the PI itself.  

1 Person Made This Project!


  • CNC Contest

    CNC Contest
  • Make it Move

    Make it Move
  • Teacher Contest

    Teacher Contest

113 Discussions


Question 3 months ago on Step 3

I get an error whenever I try to use "database administration" to add a user to login into Home_Lights.
I get the following response:
Internal error
Ticket issued: Home_Lights/

It appears as though the database "module" is not running?
I am following the instruction:
1. Under the Home_Lights application press edit.
2.Under Model, press "database administration"
3. Then press the "New Record" button next to db.auth_user
5.Enter First Name, Last Name, Email, and password. All other entries can be ignored. When done press "submit"

It fails at step #2

Does anyone know or has made this work?
I just started using web2py on raspberry pi 3
Thank you!

Abhay Jain

Question 12 months ago on Introduction

I am a very beginner. Can I use arduino instead of raspberry pi?


Question 1 year ago on Step 8

Nice project but if the Pi is only controllable from within the home network you can't control lights when you are on holiday! Maybe I misread "And with the holidays coming, wouldn't it be great to be able to turn on and off your light display from the web!" Does Web2Pi allow you to control Pi from outside th home network?


3 years ago

Hi, Thanks for the great manual. I have a little problem, hope you can help me.

I am getting the following error message: "RPi.GPIO.SetupException: This module can only be run on a Raspberry Pi!" when trying to run: sudo python /home/www-data/web2py/applications/Home_Lights/modules/GPIOServer.py

I have the latest raspberry pi, maybe it is not recognising it?

Thanks a lot!

1 reply

Reply 2 years ago

try this command

"sudo apt-get update && sudo apt-get upgrade" and try again

I have a remote controler where the button "pulls down" the micrcontroller line to the ground when it is pressed (opposite to your case of pulls up).

How can I do the wiring ?

2 replies

Reply 2 years ago

I have the same situation. I am not sure whether you can configure any of the GPIO's to sink the power rather than providing it. Any help would be greatly appreciated!!


2 years ago

The controller for the lights i am using is active low. It is at 12v at all times except when the button is pressed. Any ideas on how to wire this control into the RaspberryPi??


2 years ago

I put into the LXTerminal "wget http://web2py.googlecode.com/hg/scripts/setup-web2py-ubuntu.shchmod +x setup-web2py-ubuntu.shsudo ./setup-web2py-ubuntu.sh" and I just get a whole load of errors that all basically say that the name or service is not found. Is my syntax in the command wrong or is it something else? Also, I'm on Raspian.


2 years ago

I'm confused. So What OS do I have to install to my Raspberry Pi that this will work?

1 reply

Reply 2 years ago

You will need a debian based OS. So Rapsbian


3 years ago

I just do not see the wire connection for ALL on and off..?


3 years ago

Hi there, i also have a project which uses Raspberry for remote switch for light.

Please visit my blog for detail instruction



3 years ago

Is it possible to add button with 2 seconds delay for dimming? Should be easy.


3 years ago

Does anyone has error ticket problems when the button is pressed?i got <class socket.error>[Errno 111] connection refused.any idea where is the problem?

1 reply

Reply 3 years ago

In your hardware setup. You need to do diagnostics on your own :(


5 years ago on Step 7


wen i write this in pi terminal :

sudo python /home/www-data/web2py/applications/Home_Lights/modules/GPIOServer.py

it show me:

python: can't open file '/home/www-data/web2py/applications/Home_Lights/modules/GPIOServer.py':

[Errno 2] No such file or directory