Introduction: GSM Controlled Power Socket

This is my very first instructable here, so I hope it will be useful. But At first I want to apologize for my English. My native language is Slovak, so I hope that this instructable will be clear and easy to understand.

Step 1: Introduction

Reason why I did this project was, that I want to eliminate electromagnetic emission in my house. Everybody know that in the world we have lot of artificial sources of electromagnetic radiations which we can’t affect. All we can affect is our own sources, and one of this is wifi routers in our homes. There are a lot of studies which approves or disapproves theory, that wifi radiation is not healthy. And because of this I want to turn off wifi during sleeping time.

So my project is to make something, which will control my home wifi router (wireless functionality). Basically if you want to turn off wifi in router, you need to login into administrative section and disable it and this is annoying. And hardest thing is enable it again, you need to connect to it via cable. So this is much harder way. Also use wifi device like ESP8266 is not the way, because when you don’t have wifi signal, this device is not usable. So my decision was to use GSM module, SIM800L.

Step 2: Necessary Components

Finally I will make some box which will control external device. It will turn on/of device connected into that box. I can switch off my router because I use it only for wireless devices. For this project I will need or I will use: Power socket box, power adapter, arduino, relay, gsm module.

Plan is make box which can be inserted into your power socket on wall and it will also have own socket, where you can insert controlled device. So I will need power source for arduino and gsm module. I use 5V/2A because as GSM module I will use SIM800L which use in peaks 2 amps. As controller I will use one of smallest arduino, Arduino Nano and I will use one relay to control output of my box.

All components except of box I bought from china, where else :).
Here is the list with prices.

Arduino nano: £1.94 (2.28€)
Relay: £0.41 (0.48€)
SIM800L: £5.62 (6.6€)
Antena: £0.22 + shipping£0.66 (0.77€)
5V power adapter: £1.58 (1.86€)
Box (Strapubox SG 422): 9€ (shipping cca 4€)

Box which I used is Strapubox SG 422 which was bought here in slovakia.

So all components together cost less then 25€ and as you can see, box is probably expensive than all other components together :D

Step 3: Wiring Diagram and Connection

In this picture, you can see how I connect all components. Important is that SIM800L can’t be powered via ardiuno, it must be powered directly from adapter inside. For this project I use only 3 pins from arduino. One to connect relay and two for communicating with SIM800L.

Step 4: Flow Diagram

Before I started to write arduino program I have made preparation and flow diagram how it should works. All steps are showed in attached picture. Default state of relay after start is that plugged device will be turned off. Then arduino will control incoming calls. If there will be incoming call, it will check that number, if it is enabled. If no, arduino will hang up call. If yes, it will make action (turn on/off depends on actual state) and it will hang up call and again it will be checking incoming calls.

Step 5: Arduino Code

Based on my flow diagram I wrote my program for arduino. For communicating with SIM800L I use my own or better to said I use my own minimized libraries. In it, there is only function for receive call. To make it more secure, my box can be controlled only from enabled phone numbers. Basic libraries for SIM800L which I found in internet comparing numbers with numbers stored on SIM card. This was not very comfort for me and I made my function which compare numbers with numbers stored in array defined in arduino code. This solution will take more space from arduino, depends on how many numbers you have stored, but it is easier to change or add/delete numbers.

Call numbers
Regarding enabled numbers in array, I found that SIM800L show some numbers with country code and some without. Why I don’t know. So before you make final code and before closing box, check your numbers with making test call and then store your numbers.

Arduino connections
I don’t know why, but creating connection between arduino and SIM800L take too long time. I know that SIM800L is up and connected to network because I can call to it, but arduino still doesn’t have created connection to it because it doesn't react to my call. So you must be patient and wait while connection will not be established. So probably you must wait some minutes.

Step 6: Feedback

I do not have it inserted into my code, but if you will use this box to control something else than wifi, probably you will do not know in which state it is actually or what action you did. For this you can insert delay function. For example you can insert delay(2000) when you will turning off device. Then box will ring for 2 seconds and then it will hang up. Then you will know what you did with your box.

Step 7: Files for Download

Finally here are files what you will need, all packed in one zip file.

GSMSHIELD (directory) -> my minimized libraries for SIM800L

gsm_power_socket.pdf -> PDF file with both diagrams

gsm_power_socket.ino -> arduino code

Microcontroller Contest 2017

Participated in the
Microcontroller Contest 2017