I am sure somewhere a tutorial for this exists and I am just fool enough not being able to find it.

So what I have done is:

  • I have a 4 channel relay module

  • I have connected the relay module with my RPi and it works fine using my python program.

What I am after now is:

  • Connect this 4 channel relay module to a "Power Strip Outlet". I am looking at a product like this.

  • So that I control (turn on and off) each outlet on the board using RPi. For eaxmple: I will have a table lamp plugged in to outlet 1, a room heater puggled in to outlet 2. The outlet's power chord/cable will be plugged in to the wall outlet for the ultimate 220V power supply (as any Power Strip Outlet is normally used). The "power strip outlet"'s Outlet 1 is connected to relay module's channel 1 and outlet 2 is connected to relay module's channel 2 which I will switch on/off from my RPi.

I am using RPi2 Model B.

Any help/step by step guide will be awesome. I am a software engineer so my electrical skill in pretty bare minimum but I do understand the very basic.

  • 2
    I am of the school which thinks that if you have to ask you really shouldn't be touching mains electricity.
    – joan
    May 13, 2015 at 8:46
  • @joan of course safety comes first and I am aware of that. However, stack exchange is all about asking question. I apologise if I can't see how your comment is helpful in any way in this context.
    – Ali Nahid
    May 13, 2015 at 8:56
  • 1
    If safety comes first do you really think the Raspberry Pi Stack Exchange is a suitable place for novices to ask questions regarding mains electricity?
    – joan
    May 13, 2015 at 9:29
  • @joan when I joined stacked exchange there wasn't a level of knowledge to be qualified for mentioned anywhere on SE. And clearly you misunderstood my original question as the main quest wasn't about main electricity being safe or not. So unless you have anything valuable to add to the original question I really don't think these comments will get me anywhere. Thanks for trying though.
    – Ali Nahid
    May 13, 2015 at 9:36

2 Answers 2


If you want to control each individual outlet by itself you probably need to open up the power strip and connect the relays into the wiring between the sockets. This can be a bit tedious to do. You probably would like to keep all wiring (except the control wires) into the power strip so that you don't get electrocuted.

Here is a nice guide on what you would like to achieve, Web Controlled 8-Channel Powerstrip.

  • 1
    And make sure you do not connect the relay directly to the Pi, but via a transistor. Your relay module might already have this built in, but for good measure, check and double check. The GPIO pins are not designed to deal with switching a relay directly.
    – Phil B.
    May 13, 2015 at 12:50
  • @PhilB. I'll second that. May 13, 2015 at 13:08
  • BTW, the relay used in the Instructable @MattiasJohansson linked as an opto-coupler on it, which is fine too instead of a transistor.
    – Phil B.
    May 13, 2015 at 13:31
  • 1
    @PhilB. somehow I get the feeling that an optocoupler is safer than using a transistor. I looked in the datasheet for the specific optocoupler on that relay board. It is a PC817C and it has an isolation voltage between input and output of 5000 Vrms. Pretty good and it will keep the PI safe. I mean I would definitely use a transistor for prototyping and the optocoupler if I would make a design that I would produce in larger volumes. May 13, 2015 at 13:38
  • 1
    I agree wholeheartedly. My advice was to the OP - make sure you either add a transistor yourself, or ensure the relay board you use has a transistor or opto-coupler. The board you reference has an opto-coupler, so it can be used directly. The OP did not specify which board they have, so I would recommend they check & double-check.
    – Phil B.
    May 13, 2015 at 13:40

I would strongly discourage you from do hobby work inside such a plug.

It is not clear, what exactly you have - if you already have 4 relays that can switch 230V at a desired power. If you have just some 12V relay, dont try to use them on 230V. In this case - a safe solution would be much more expensive - DIN rail, DIN power source, DIN relays, DIN plugs, box. Everything mounted on DIN rail and housed in a closed box. These 230V relays you can operate from your relays that already work. Especially I remind, that for the heater, you need a relay that can operate 10A 230V.

Examples (sorry I cannot fetch photo of my device now) http://www.rapidonline.com/electronic-components/24v-dc-relay-module-with-positively-driven-contacts-din-rail-mounting-520505#techSpecs



I understand that this is not the answer you would like to hear, but doing it improperly, you risk. Even if it works in the beginning with a duck tape solution, after few weeks or months a fire can break out in the middle of the night.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.