Raspberry Pi Wifi enabled 4-way power box

Greetings OG!

An old friend (@lefthandseeds) developed the idea of using a raspberry pi, a relay, and some software to power 4 outlets based on timing schedules set within an amazing piece of software called Node-Red (https://nodered.org).

I will detail in this post how we set it up, and how to do it yourself if interested.

This thread comes with a strong disclaimer - this project “suggestion” deals with high voltage applications. If you don’t have an understanding of how to work with 120V power in an application such as this, I highly recommend you bring in a friend that does. Follow strict safety procedures if you decide to follow the “suggestions” here about how we did it. Never work on the box while it’s plugged in to 120V (obviously).

Firstly, why?

We were both using cheap timers in our grows that only allowed for very limited timing intervals (on/off only on hourly basis) and had switched to feeding on an hourly schedule such as 15s on per hour. This device allows for microsecond control of any type of timing. I wanted 4 relays so that I could control both a water pump and lights on a veg and flower tent on completely separate timing schedules.

The Rasperry Pi and Node Red also allow this box to be fully wifi controlled, but we use it as a “set and forget” utility.

On to the fun.

The components, and a cost breakdown:

4 Gang work outlet box - $7 - https://amzn.com/B000BQWVD2
4 power outlets - $4 x 4 = $16 - https://amzn.com/B002DQT5UK
4-gang wallplate - $6 - https://amzn.com/B003AU36OY
Raspberry Pi-Zero W (wifi enabled) - $10 - https://www.sparkfun.com/products/14277
Raspberry Pi Power Supply - $8 - https://www.sparkfun.com/products/13831
Raspberry Pi Header (this is a solder-less option) - $7 - https://www.adafruit.com/product/3413
Raspberry Pi Jumper Wires (female/female to go to header and relay) - $4 - https://www.sparkfun.com/products/8430
16G Micro SD for Pi - $8 - https://amzn.com/B073K14CVB
4-Channel Relay Module - $8 - https://amzn.com/B00E0NSORY
Wire push connectors (you can use anything you want to combine wires) - $7 - https://amzn.com/B07CNNQDMZ
18 gauge wire (I usually just buy an 18AWG power cord and strip it for its component wiring) - $7 - https://amzn.co/B006VKCFAQ

Please note: verify your gauge of wiring based on the amps of your lights, pumps, fans or whatever else you’re going to be hooking up! Use the right gauge based on your application. If you don’t know, once again, please stop and ask someone who is knowledgable in electricity applications!! Here’s a guide based on AWG (american wire gauge): https://www.powerstream.com/Wire_Size.htm

Total cost: $88.00 USD

First step is to get the Raspberry Pi configured, I’m not going to go into this here, but here are the steps for the Pi, and for Node-Red installation.

Node Red install: https://nodered.org/docs/getting-started/installation

Make sure you set Node Red up to start at boot on the Raspberry Pi so that you can simply turn the Pi on and it will be active at your Pi’s address!

Here’s a build schematic I made to display exactly how it’s wired:

As you can see, the Pi is wired from 5v and ground to the relay, and then 4 GPIO pins of your choice go to the IN1 - IN4 pins on the 4-Channel Relay.

Notice power (black) from the push-in connector goes to the center channel of each relay, which is power in, then the bottom, or right most connector on each relay goes out to the power outlet. This is very important! The relay I linked “floats high” so you actually send a False or Off signal to turn ON the relay. I know, super confusing - but this allows for the best case failure state - if your Pi fails for whatever reason, or you lose power - your pumps, lights, and otherwise will default to an OFF condition!

Imagine you lose power and then your pumps default to on, thus dumping your entire reservoir into your grow!

The rest just shows basic wiring to get the power source’s grounds and neutrals to the outlets.

After wiring, you can stuff the relay and the Pi into the bottom of the gang box, and then screw in the outlets to the gang box itself. It will be a mess, be patient and make sure your wires are tight and in alignment to push everything in. Please note also, you are going to need a power source for the box itself and the raspberry pi power adapter, run the raspberry pi’s power adapter out of the gang box.

Plug in just the Raspberry Pi, do NOT plug in the main box power yet as you might need to make adjustments.

Ok, on to Node Red - I’ll post a couple screenshots of the interface and how to setup a simple timer switch, but leave the rest up to you - Node Red is an incredibly powerful IoT application but we use it at its most basic.

When you visit your Pi’s Node-Red address (e.g. you will be presented with a blank flow, which is where your timing arrangements live.

If you want a timer switch to do interval timing:

  1. Visit the Menu at top right
  2. Visit “Settings”
  3. Click the “Palette” tab
  4. Under the “Nodes” tab - search for “node-red-contrib-timerswitch”
  5. Click Install

This will make available the timerswitch input under “input” on the left menu.

Drag a timerswitch input onto the flow area, and then scroll all the way down on the left menu to “Raspberry PI” and drag the “rpi gpio” with the dot on the left side of the object onto your flow.

You then attach timerswitches to Rpi GPIO objects like so!

You must individually configure the Rpi Nodes to your GPIO pins running from your Pi to the Relay board, as so:

Here are examples of my timing schemes I set up in the timer switch nodes, please note the On/Off payload is a “0” for ON and a “1” for OFF, this ties to how the relay works, as I described way up above:

Finally, hit the “Deploy” button after you save these settings, plug in your main power to the box. Try plugging a light or other item that will show power is active on an outlet, and try setting a timer switch to turn on now. Once you verify all the outlets work, you are ready to grow with precision!

That’s pretty much the whole setup. I know this project is not for your average stoner to pursue, so please feel free to post any comments or questions. @Mr.Sparkle will probably come in here with a much simpler solution for most people involving smart plugs!

I will post a finished picture of the power box when I’m available later.

Thanks for everything you do, OG!

cc: @WMoon518 (promised this write up a long time ago in Sparkle’s thread)


Thanls @8k_feet. This sounds great and not too difficult (or expensive, which is most important). I take it that each plug (2-outet pair) is run from a separate relay? I just like the fact that you can connect locally and do not have to go through a site, like the home automation route. And getting more familiar with Linux, I prefer this over Arduino.


That’s correct - so each socket on an outlet will receive a single power source from the relay it is attached to. You could technically do some nice things with that - for example if you had two tents on the same schedule of lights/pumps/etc.

The other cool thing is that this setup scales - you could technically run a single relay for every GPIO pin on your Rapsberry Pi making for 20+ relays to be controlled individually.


I am guessing you could run 5v stuff (fans, pumps, etc) right off the relay, directly and cut down on the # of outlets?

Does anyone know if the 3B+ has 12V output or just 3.3/5v like the Zero?

1 Like

Great write up! Interesting look into the raspberry pi world. I’ve been doing the similar projects with the Arduino.


I don’t think the pi 3 B+ has 12V rails, just 3v3 and 5, same as the zero.

I wouldn’t recommend running 5V fans off the pi. It’ll draw too much power for the regulators on the pi. You could just plug a 5V adapter into the outlet and switch it with the relay – or you could hard wire the adapter to the line 120V inside the box and run a cord out.

1 Like

I don’t think the draw more than 200 - 300 mA. That is too much for the 3B+? I would think many of the things you would plug into the USB port would draw the same or more.

I am guessing you could probably use a shield like this that would pop right onto the Pi?


Also, they sell “Stacking Headers” (long pins on one side and header on the other) and “solder-less Headers” that you tap into the holes (used to use something like this in the 80’s) but do not allow for stacking. Does anyone sell a “Solder-less Stacking Header”?


I like this project a lot. Ive been using Sonoff’s but I hate having the “cloud” in China and having the program have access to my system, wifi, having to re-login periodically, etc. I just dont trust them as far as my privacy.

Looking forward to trying this out when budget allows.



Goin’ down today to pick up a $5 Pi Zero W. Woo Hoo!!!


I like this option for compactness. but how do you know which relay connects to which port on the pie? Would the code need to be altered?

1 Like

I don’t know. I know that each relay is numbered (I am guessing J2 is relay #1 and so on) and I have not done anything with these kind of things. I just figured the same as you, it would be more compact and straight forward.

Actually going to P?U Zero tomorrow (have until Tues so no rush. Am going to have to start looking around at all the nice little (and hopefully cheap) new toys I can get.

--------- Added -----------

I looked at the listing and in the comments section the following is listed by a few people:

gpio 4 is relay 1
gpio 22 is relay 2
gpio 6 is relay 3
gpio 26 is relay 4


Make sure you get the W version (the $10 one). The non-W doesn’t have wifi on board!


It is the “W” just getting it for $5 cheaper! WOO HOO!!!

Yeah i dont even use arduino anymore well as of recent just cause of the available options out there, and considering what one typically would use them for.

and mosfet cycle timers like the recent one i picked up all fit the bill


:open_mouth: where’s the sale? I want to pick up another.


I don’t know whether I should say… hehehehehehe

Okay, it’s Micro Center. If you buy one, it is $5. if you buy two, they are $15 each. I guess they don’t want everyone buying more than one. You can reserve one online, but you MUST pick it up in store.


FANTASTIC contribution! Thanks for taking the time to share this :thumbsup:


If you look at the bottom left corner of the relay picture, you’ll notice IN1…IN4 - remember which GPIO pins went to which IN1…4 terminals on the relay.

IN1…IN4 then corresponds to K1…K4 on the relay’s power terminals on the right side of the relay counting from top to bottom.

The best way to test is you can use Node Red, and map your GPIO as I displayed to your timer node, and if your power gang box is still open you can actually see LEDs on the relay board light up as you turn them “on” in node red. You could also just hook up a desk lamp to power if the box is closed up and it’ll of course flick on when you activate the node in Node Red.


You can totally use that shield - also pretty sweet but technically limits you to 4-way of course if you ever want to expand.

Ideally, and @lefthandseeds the hardware purist would say this also - you should solder in your header from the bottom of the Pi.

I actually linked “hammer in headers” in the post - you have to buy a plastic jig and that “hammer header” I linked - you put the Pi in the jig, and then lightly tap with a hammer on the top of the jig to push the hammer header into place. It will work without soldering, which is why I thought it might be a better option for the “general crowd” :smiley:

I don’t actually have a soldering station, because I just don’t do enough of it to justify, I make @lefthandseeds god mode soldering skills handle it! :laughing:


Awesome thread! Will be giving this a run soon

1 Like