How to Build a 3D Printed Cellular Controlled 120V Power Outlet

Create a cellular controlled 120V outlet using an Arduino, 3D Printer and a 2G Sim card

Kelly Householder
The Startup

--

Introduction

Have you ever had a situation the required you to travel to a remote location to turn on some device? Ever wished you could just send the device a text message to turn it on? Sure, you could purchase a 3G remote switch on Amazon or just about anywhere on the internet, but where is the fun in that. In this DIY project, I will walk you through building your own cellular controlled 120V outlet.

The Idea

Buy and Cellular based Arduino, buck regulator, and some relays. Model and print a 3D box to place them in. Wire everything up, and build a program that would work with a text message from my phone.

WARNING: This project uses 120V AC.
Electricity can cause injury or death.
DO NOT proceed with wiring the 120V side of this project if you are not comfortable with using 120V AC. Or get help from someone who does.

Parts List:

Adafruit Feather 32u4 FONA = $44.95
GSM 2G SIM Card from Ting = $9.00
SainSmart 2-Channel Relay Module = $8.00
GSM/Cellular Quad-Band Antenna — 3dBi — 200mm = $2.95
NOYITO AC to DC 5v 3amp Buck Power supply = $11.99
RKURCK 125–250V AC Circuit Breaker 10Amp = $6.99
PG 13.5 Cable Gland = $7.99
15 Amp, 14 AWG 3' Extension Chord = $8.54
Lithium-Ion Polymer Battery — 3.7v 1200mAh =$9.95
Optional: Breadboard Female to Female Jumpers = $11.99
10 M4 X 12mm screws to hold the boards (local Hardware store)

Install SIM Card

Next, you will want to install the SIM card into the sim slot on the Feath.
Pro Tip — the card comes with 3 sizes and you want to be sure you use the middle size for this card. This got me for a few minutes when I first pulled out the sim chip from the holder.

adafruit

Arduino Wiring

If you are new to Arduino’s, don’t be concerned. They are simple devices and they are simple to wire. You can use a breadboard for testing if you desire. However, I won’t get into the details of prototyping on a breadboard in this article. For this project, you can simply use the push on wires in the parts list, a good soldering station, and solder.

Temporary Wire for Testing

We will use the Pin Outs from this Diagram to set up our test wiring harness.

Copyright Adafruit https://learn.adafruit.com/assets/46246

The Feather comes with posts that need to be soldered into the board. Complete this step prior to wiring up the unit.

  • note: push the short pin side in from the top of the board and solder the pins on the back of the board to allow us to use the push on wires.
  • If you feel comfortable you can also just solder wires directly to the board to make them more secure. I would, however, wait to do this after prototyping the setup.

We will use the following Pins.

GRN — This will be the ground wires to the relay module
A2 — Digital I/O pin for Relay 1
A3
— Digital I/O pin for Relay 2
USB — Voltage to the Relay Module from the USB Port.
ANT — Port that the antenna will mount on.

Below is a picture of how it should look for you at this point. The battery is not connected to the board in this picture. You will need the battery connected when testing text messages.

You will also want to attach the antenna snap on as you see it connected in the picture.

Activate the SIM Card for testing

Now that you have the parts connected with a temporary wiring harness and the SIM installed, go to ting.com/go to set up your sim card.
You will see the activate screen. This is for a cell phone, DO NOT set up the card as a phone. Click the link below the button that says “I have a Ting GSM Sim card. Skip this Step”

Enter the SIM card number (ICCID)off the back of your SIM Cardholder as shown above in Blue.

You will be prompted to set up a phone number, complete your profiles and set up your billing information to finalize the activation of your SIM card.

Don’t skip this step because we need the SIM activated with a phone number in order to test our code in the next steps.

Installing the Arduino IDE and Programming

Our next step will be installing the Arduino IDE so that we can program the unit and start testing our code.

Use one of the following links to walk through the installation of the IDE on your designated Operating System. Once you are done, come back here and we will start testing our code.

Installing Arduino IDE Windows
Installing Arduino IDE Mac
Installing Arduino IDE Linux

Before we can start working with our Feather board we need to add Additional Boards Manager URLs.

We will only be adding the following URL to your IDE for our project. https://adafruit.github.io/arduino-board-index/package_adafruit_index.json

To add the URL, open up the Arduino IDE Preferences pane and paste the URL in the location shown in this picture and then click OK.

With the URL added to the IDE, open the Boards Manager by navigating to the Tools->Board menu.

With the Board Manager open, click on the Type drop-down menu on the top left-hand side of the window and select Contributed. Install Adafruit AVR Boards.

Quit and then restart the IDE to initialize the added boards.

Select Tools -> Boards “Aurdino/Genuino Uno” -> Adafruit Feather 32u4

Windows Users: You may need to install the drivers when connecting the Feather. Click Here to find instructions.

With the IDE now successfully installed, we need to connect the battery plug to the battery connection on the Feather and connect the Feather to the computer with a USB cable. The type of cable is a USB-A Male to Micro-B. This type of cable is usually abundant in homes in the year 2020. However, if you do not have one you can run to a local best buy or staples and pick one up.

The battery connector on the Feather

Once connected, give the OS time to detect the Feather and you should see the device listed as a port in the IDE

Feather 32u4 as Port

The Arduino is now connected to the IDE and we can upload a test Sketch to the device. The easiest way is to just use the Blink Sketch. Paste that Sketch into your window and then click Sketch->Upload. It will take a few seconds and then you will see your Feather blinking as it initializes.

Below is the simple Blink Sketch

Blink Sketch File

Open up the Serial Monitor window [Tools-> Serial Monitor] so that you can watch what is happening with the code and the responses from the Feather.

Uploading the switching Sketch

Time for a quick inventory of where we are at to be sure we have not missed anything.

  1. The Arduino Feather Feather 32u4 is connected to the relay per the wiring diagram
  2. The Arduino IDE and Board Libraries have been installed
  3. The USB cable and the battery are connected to the Feather [ Very Important]
  4. The Blink Sketch has been uploaded to the Feather and the blink program has successfully run.
  5. The Serial Monitor window is open and you have seen output from the board into the window.

Next, copy my sketch file and load it into the IDE.

SwitchIt Sketch File

With the Sketch loaded into the IDE, we now need to turn on our debug lines to output information to our Serial Monitor window. To do this, change the following comments in the Sketch.

#define Sprintln(a) (Serial.println(a))
// #defined on#define Sprintln(a)
#define Sprint(a) (Serial.print(a))
//#define Sprint(a)

Next you will select the Sketch->Upload menu to upload the code to the Feather.

After the Sketch has been uploaded and the Feather has restarted, you should see something similar to this in your Serial Monitor window.

Once the unit stops displaying “Waiting for cell connection” and the blue like has gone from blinking fast to blinking slow. Send a text message to the phone number for the TING SIM.

Text Messages that are accepted by the code
Status
= will return the status of the relay. (on or off)
On = Turn on the relay and return status.
Off = Turns off the relay and returns status.

If everything is set up how it should be, you should hear the relay’s cycles when you send On or Off.

Prepare for installing in the box

We need to make one small change to the Sketch before we are ready to assemble the unit in the 3D printed Box. We need to set the code up to run without the debug output turned on. Make the following changes to the code and then uploading to the Feather.

// #define Sprintln(a) (Serial.println(a))
#defined on#define Sprintln(a)
// #define Sprint(a) (Serial.print(a))
#define Sprint(a)

Printing and Assembling

With all the parts gathered, the only other physical component we need is the 3D box that we will print to house the electronics.

I built the model using AutoDesk Fusion 360. I did have to iterate the model a few times to get the exact placement and stand off’s needed to mount the modules.

You can download the STL for this model here on Thingiverse.
For the filament, I used HatchBox PLA. I have had very good luck with this brand and the cost is reasonable when you buy from Amazon.

WARNING: PROCEED AT YOUR OWN RISK. 120V AC CAN LEAD TO INJURY OR DEATH. IF YOU NEED HELP GET IT!

The Buck has two sides. A 5v DC side +V (Red) GND- (Black) and a120V side marked AC/L (Line- Black) and AC/C (Common-White).

120V & 5V Wiring: Cut the extension cord in half and strip back the shielding with enough length to allow the wires to extend to the Buck inside the box.

Very Important: You need to have one extra white 14 AWG wires to connect the Buck, Socket, and Plug. You can get this wire by cutting the extension chord back far enough to cut about a 4" length off the white.

Using the extension cord you just cut in half. Connect your plug-in side white wire to the spare white wire you just cut. Then connect the socket side white wire with the other two white wires using a wire nut as shown below.

Next, connect the non-connected white wire to the Buck AC/C side.

You will now connect the plug-in side black wire to a spare black 14 AWG wire similar to how we did the white wires. One of the wires will connect to the Buck AC/L terminal and the other black wire will connect to the open side of the relay unit as shown below.

Wire the socket-side black wire to the terminal on the circuit breaker. On the other side of the circuit breaker use another black wire to connect to the second terminal of the relay next to the black wire you just connected.

If this feels complex, look at the actually finished picture to see the routing of the white and black wires.

Next, we will connect the + (-) of the 5V off the DC side of the Buck Power Unit to the relay and the Feather.

Connect the plug-in side and the socket-side ground wires of the extension cord together with another wire nut

When you are done with the wiring, it should look something like this.

Be sure to connect the battery to the Feather and then plug the unit into a wall socket with a lamp or other type of device on the socket side.

Give the unit time to boot up and get a cell connection: Blue flashing light will go from fast flashing to med flashing once a cell connection is established.

Send a text message to the unit and watch all of your hard work start to pay off.

Resources

Parts List:
Adafruit Feather 32u4 FONA = $44.95
GSM 2G SIM Card from Ting = $9.00
SainSmart 2-Channel Relay Module = $8.00
GSM/Cellular Quad-Band Antenna — 3dBi — 200mm = $2.95
NOYITO AC to DC 5v 3amp Buck Power supply = $11.99
RKURCK 125–250V AC Circuit Breaker 10Amp = $6.99
PG 13.5 Cable Gland = $7.99
15 Amp, 14 AWG 3' Extension Chord = $8.54
Lithium-Ion Polymer Battery — 3.7v 1200mAh =$9.95
Optional: Breadboard Female to Female Jumpers = $11.99
10 M4 X 12mm screws to hold the boards (local Hardware store)

Arduino IDE Install
Installing Arduino IDE Windows
Installing Arduino IDE Mac
Installing Arduino IDE Linux

Code Repo
Git Repo for code

Additional Learning Links
Adafruit Feather Fona 32u4 guide

--

--

Kelly Householder
The Startup

Disciple of learning all things. Love family, flying, music, tech and leadership.