Electronics · python · raspberry pi

Raspberry PI Controlling Power through GPIO (no wifi needed)


Digital Logger’s IOT Logic Outlets

In my previous two articles – we show two ways the Raspberry Pi can control power through Wifi:

Raspberry PI for controlling TP-Link POWER

Raspberry PI for Controlling Wemo Power

These assume wifi-enabled outlets, which are great, but there are some cases where you really want the Raspberry PI to control the power without requiring internet.  For me, that came when I decided my router occasionally needs a reboot. But… if I reboot my router, I wont have internet!  So I could power the outlet back up. 😉

Another case might be when you are having a Paper Airplane Bonanza and you don’t have Wifi as an option for controlling Fan-Based airplane traps!

So, here you want you’ll want either the one pictured above or this one:


The Power Switch Tail II

These both safely control 110V outlets used for all household appliances through Logic Level voltages.  “Logic level voltages” just means, it is something that can be controlled with a pin from a device like an Arduino or Raspberry PI.  Imagine the power you have!

A little code like this (Node code is a little further down.):

import RPi.GPIO as GPIO
import time
import signal
import sys

# Gracefully handle reseting the GPIO state.
def signal_handler(signal, frame):
  print('You pressed Ctrl+C!')
  GPIO.cleanup() # cleanup all GPIO

signal.signal(signal.SIGINT, signal_handler)

lampPin = 16 # The pin connected to the outlet controller.

GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme GPIO.setup(lampPin, GPIO.OUT) # Lamp pin set as output
GPIO.setup(lampPin, GPIO.OUT) # LED pin set as output
GPIO.output(lampPin, GPIO.LOW)

while True:
 GPIO.output(lampPin, GPIO.HIGH)
 GPIO.output(lampPin, GPIO.LOW)


Node Code… make sure you install rpi-gpio:

npm install --save rpi-gpio
var gpio = require('rpi-gpio');

var lampPin = 16;
function pinBlink() {
 gpio.write(lampPin, false, (err) => {
   if (err) {
     console.log("Error in setting gpio pin.",err);
   setTimeout(() => {
     gpio.write(lampPin, true, (err) => {
       if (err) {
         console.log("Error in setting gpio pin.",err);
   }, 1000);

gpio.setup(lampPin, gpio.DIR_OUT, () => {
 setInterval(pinBlink, 2000);

Can turn on fans… lamps… anything that normally plugs into a wall outlet!  In this code we make it blink!

An image of the setup is below, but its pretty simple.  These make it easy:


But any jumper wires you can strip on your own will work too.  You just need to get one routed from one of your pi’s ground pins, to the negative or ground on the tail or digital logger.

Then get pin 16 hooked to V+ or +IN on these devices.


Now, mix this code with an IR remote and you can reset your Wifi with a remote control!  For clues – check out this article:

Tying it all together! Wand > LIRC > Socket > Forever > Outlet

Another cool resource:

Another cool pin explorer resource: https://pinout.xyz/

Screen Shot 2017-11-12 at 2.06.11 PM

This site is an INTERACTIVE pinout chart.  Which is just fantastic.


5 thoughts on “Raspberry PI Controlling Power through GPIO (no wifi needed)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.