Introduction: RaspberryPi Web Curtain Controller

The Somfy remote control system is a closed, proprietary system. This Instructable shows how to hardwire the remote to the RaspberryPi (RPi) and then write a simple PHP web page to control the drapes. Any application where you want to complete (close) a circuit from a web app can be used with this method. The circuits are closed with a transistor since the RPi GPIO does not directly support a basic switch function. Because we don't want to ping the motors constantly, I only close the switch a fraction of a second, which simulates pressing the button on the remote. The web app is designed to be used on your LAN. Once you have software control of your curtains the applications are only limited by your imagination.

Hardware needed:

  • RaspberryPi 2 w/power adapter
  • RapberryPi USB wireless adapter
  • Breadboard (for testing only)
  • 3 LEDs (for testing only)
  • 3 NPN transistors
  • 3 10K resistors (brown, black, orange, gold) - I didn't do the math, I just used large resistors to limit current
  • jumper wires (any kind)
  • Printed circuit board - one sided
  • Soldering iron and solder
  • Somfy Telus remote (this is a one way project, be sure you are willing to sacrifice the remote)

Software needed:

Final consideration:

I initially managed my RPi through a USB keyboard and mouse and an HDMI monitor. I've since realized it is much easier to SSH into the RPi from my MAC. The instructions to remotely access your RPi are here:

Step 1: Step 1 - Working With GPIO

There are many examples of how to use the GPIO (general purpose input output) pins on the RaspberryPi. If you are new to this, I recommend you start with simple wiringPi python scripts. This will get help you ensure your circuits are wired properly before you solder. There is much confusion on pin numbering. This Instructable uses the WiringPi pin mode. This is all made easier with the following website: REMEMBER, we are using WiringPi pins 2,3,7.

Be very careful as you can easily fry you Pi. Remember, always use a resistor and always do your wiring with the RPi unplugged.

Here is a simple guide:

FROM: GPIO pin --> resistor --> LED --> ground

ALSO: GPIO pin --> resistor --> transistor --> ground

Wiring instructions:

If you aren't familiar with breadboards, see this Instructable first:

Reference the picture above with the pins labeled 2,3,7 and ground. These numbers may seem illogical. Remember, we are using the WiringPi pin designation scheme. I avoided using pin 0 as "0" is often used in code as "False" or "Off."

Let's get started:

Wire from RPi pin 2 to the breadboard. Wire from the breadboard to a 10K resistor. These are very large resistors so your LEDs will be dim. This is the desired outcome. We do not need nor want to send a large current to our transistors. Wire from the resistor to the anode of the LED. This is the longer lead. Then wire from the cathode (shorter lead) of the LED to ground. For this project I use the blue ground rail on the edge of the breadboard and only connect to ground on the RPi once. I also follow the same principe with the remote and the circuit. Repeat the above step for pins 3 and 7.

Next step, turning the LEDs on with a Python script.

Step 2: Step 2: Testing Your Circuit

This is an optional step that uses Python to quickly test your circuit. The reason I recommend this step is that you don't want to spend hours debugging code when you have a wiring problem and vice versa. By validating your wiring in advance you will know that any issues in the web app are limited to code, permissions, directories and all those other troublesome software quirks.

From the RaspberryPi GUI: Menu --> Programming --> Python2(IDLE)

Create a new file and paste this code:

##this only works with python2 
import wiringpi2 as wiringpi 
#using wiringPi pin designation 
#set up three GPIO pins for output
wiringpi.pinMode(2, 1)
wiringpi.pinMode(3, 1)  
wiringpi.pinMode(7, 1) 
#turn on pins on/off in succession
wiringpi.digitalWrite(2, 1)  
wiringpi.digitalWrite(2, 0) 
wiringpi.digitalWrite(3, 1)  
wiringpi.digitalWrite(3, 0) 
wiringpi.digitalWrite(7, 1)  
wiringpi.digitalWrite(7, 0) 

Click Run, save your file and watch your LEDs light up in succession.

Next step --> Install a web server on your RaspberryPi

Step 3: Step 3: Software

Install Apache and PHP:

Follow these instructions to install Apache and PHP on your RaspberryPi.

The reason I chose PHP is that it is a one file implementation. If you have any examples on how to control this circuit using Node.js and Javascript by all means, please let me know. For now PHP on Apache is a clean and simple solution.

My program is named index.php and it is in the directory /var/www/html. Placing this file in this directory will allow it to execute when your RaspberryPi's ip address in entered into a browser. Alternatively, you can qualify the file name in the browser. e.g: Be especially careful with file permissions during the Apache setup. You need enough to save and execute your file, but don't risk your RPi's security.

Get you RPi's local ip address:

From the terminal type hostname -I (that's a capital i)

My RPi is located at This is on a local network. This project is not accessible from the internet. I personally don't want strangers opening and closing my curtains.

The PHP program: index.php

1) This program begins with CSS to style the buttons.

2) The second part is three form statements. Since PHP is a server-side language, the code executes on the server. By using a form and the post command, we can invoke our code on the RaspberryPi with a simple click of a button.

3) The PHP section uses the ISSET command to detect a button press. When the button is pressed the GPIO pin is set to output, turned on for 0.8 seconds and then turned off. That's all there is to it.

<h1>RaspberryPi Blind Control</h1>

.openButton {
  display: inline-block;
  font-size: 72px;
  width: 400px;
  text-align: center;	
  border-radius: 12px;
  color: #fff;
  background-color: green;

.closeButton {
  display: inline-block;
  font-size: 72px;
  width: 400px;
  text-align: center;   
  border-radius: 12px;
  color: #fff;
  background-color: yellow;

.stopButton {
  display: inline-block;
  font-size: 72px;
  width: 400px;
  text-align: center;   
  border-radius: 12px;
  color: #fff;
  background-color: red;

<form method="POST" action="">
   <input class="openButton" type="submit" name="open" value=Open><br><br><br><br>

<form method="POST" action="">
   <input class="closeButton" type="submit" name=“close” value=Close><br><br><br><br>

<form method="POST" action="">
   <input class="stopButton" type="submit" name=“stop” value=Stop><br><br><br><br>

### open     
exec("sudo gpio mode 7 out");
if ( isset( $_POST["open"] ) ) {
    exec("sudo gpio write 7 1" );
    exec("sudo gpio write 7 0" );

### close
exec("sudo gpio mode 3 out");
if ( isset( $_POST[“close”] ) ) {
    exec("sudo gpio write 3 1" );
    exec("sudo gpio write 3 0" );

### stop
exec("sudo gpio mode 2 out");
if ( isset( $_POST[“stop”] ) ) {
    exec("sudo gpio write 2 1" );
    exec("sudo gpio write 2 0" );


Next step --> Transitors

Step 4: Step 4: Working With Transistors

Why a transistor?

In our final circuit the LEDs will be replaced by NPN transistors that will operate as on/off switches for the remote. The transistor is used to close the circuit without introducing any RPi power to the Somfy remote. Remember, the remote has a battery and it operates under its own power. If we try to connect the GPIO pin directly to the remote we risk destroying the device. The picture above inspired this design. Many thanks to RaspberryPi Geek for the article found here:

Wiring the Remote:

The brown wire soldered to the Somfy remote operates as a ground for all of the buttons. I tested this using a multi-meter. The resistance between all of the leads on the bottom of the buttons is zero meaning they're all connected inside the remote. I connected the remote ground to my circuit ground reducing the number of wires in the project. Note the brown jumper wires on the circuit board; if I designed my board better, I could have connected all of the ground underneath with solder. This would be similar to the blue ground bar on a breadboard. The green wire on the remote is the Open wire. If you touch the green wire and the brown wire together the remote will be activated. We are simply closing a circuit on the remote. That circuit brings its own power.


I mistakenly used the wrong color wires for the other two buttons. From left to right the buttons are: Open, Stop, Close. I didn't think it was worthwhile to re-solder just for color coding; please don't get confused by this.

How does this work?

For more on how transistors work, check out this Sparkfun article:

Next step --> Putting it all together

Step 5: Step 5: Putting It All Together

Printed circuit board:

Once the hardware and the software were working successfully, I moved my project to a printed circuit board (PCB) to make it permanent. This involves moving the circuit from the breadboard and soldering the connections. The key is to take your time an be sure there are no mistakes. The PCB I used was one-sided with no connections on the bottom. This differs from a breadboard where the rows are connected underneath. The connections are instead made with solder.

While my circuit works splendidly, it's not the neatest looking project. A bit of planning will help improve the look of your final circuit.

Here are some suggestions:

  • Use Fritizing to virtually design your circuit before you solder
  • Measure and shorten your leads to the exact size needed
  • Use a bride to connect the RaspberryPi to the PCB
  • Find a nice enclosure to house the Pi, the remote and the board.

That's it. Connect the leads to the RaspberryPi and navigate to the url from your favorite device.

Hack Your Day Contest

Participated in the
Hack Your Day Contest

Raspberry Pi Contest 2016

Participated in the
Raspberry Pi Contest 2016