Tutorial: Control AC outlets via SMS

This is chapter thirty-three of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe.

The first chapter is here, the complete series is detailed here. Any files from tutorials will be found here.

Welcome back fellow arduidans!

In this chapter we will continue with the use of the SM5100 cellular shield to turn digital outputs on and off via SMS. However please read chapters twenty-six and twenty-seven first if you are unfamiliar with using the GSM shield with Arduino. As an extension of chapter twenty-seven, we will use our Arduino to turn on or off AC outlets via a common remote-control AC outlet pack. Please note this is more of a commentary of my own experience, and not an exact tutorial. In other words, by reading this I hope you will gain some ideas into doing the necessary modifications yourself and in your own way.

Firstly, we need some remote-control AC outlets. Most electrical stores or giant retail warehouses may have something like this:

Nothing too original, just a wireless remote control that can switch on or off receiver outlets on a choice of four radio frequencies. Before moving forward I would like to acknowledge that this article was inspired by the wonderful book Practical Arduino – Cool Projects for Open Source Hardware by Jon Oxer and Hugh Blemings. In chapter two an appliance remote-control system is devised using a similar system.

At first glance the theory behind this project is quite simple – using the hardware in example 27.2, instead of controlling LEDs, activate the buttons on the wireless remote control for the AC outlets – leaving us with AC outlets controlled via SMS. However there are a few things to keep in mind and as discovered during the process, various pitfalls as well.

Before voiding the warranty on your remote control, it would be wise to test the range of the remote control to ensure it will actually work in your situation. I found this was made a lot easier by connecting a radio to the remote outlet – then you can hear when the outlet is on or off. If this is successful, make a note of the amount of time required to press the on and off buttons – as we need to control the delay in our Arduino sketch.

The next step is to crack open the remote control:

… and see what we have to work with:

Straight away there are two very annoying things – the first being the required power supply – 12 volts; and the second being the type of button contacts on the PCB. As you can see above we only have some minute PCB tracks to solder our wires to. It would be infinitely preferable to have a remote control that uses actual buttons soldered into a PCB, as you can easily desolder and replace them with wires to our Arduino system. However unless you can casually tear open the remote control packaging in the store before purchase, it can be difficult to determine the type of buttons in the remote.

As you can see in the photo above, there is an off and on pad/button each for four channels of receiver. In my example we will only use two of them to save time and space. The next question to solve is how to interface the Arduino digital outputs with the remote control. In Practical Arduino, the authors have used relays, but I don’t have any of those in stock. However I do have a quantity of common 4N25 optocouplers, so will use those instead. An optocoupler can be thought of as an electronic switch that is isolated from what is it controlling – see my article on optocouplers for more information.

Four optocouplers will be required, two for each radio channel. To mount them and the associated circuitry, we will use a blank protoshield and build the Arduino-remote control interface onto the shield. The circuitry for the optocoupler for each switch is very simple, we just need four of the following:

As the LED inside the optocoupler has a forward voltage of 1.2 volts at 10mA, the 390 ohm resistor is required as our Arduino digital out is 5 volts. Dout is connected to the particular digital out pin from the Arduino board. Pins 4 and 5 on the optocoupler are connected to each side of the button contact on our remote control.

The next consideration is the power supply. The remote control theoretically needs 12 volts, however the included battery only measured just over nine. However for the optimum range, the full 12 should be supplied. To save worrying about the battery, our example will provide 12V to the remote control. Furthermore, we also need to supply 5 volts at a higher current rating that can be supplied by our Arduino. In the previous GSM chapters, I have emphasised that the GSM shield can possibly draw up to two amps in current. So once again, please ensure your power supply can deliver the required amount of current. From experience in my location, I know that the GSM shield draws around 400~600 milliamps of current – which makes things smaller and less complex.

The project will be supplied 12 volts via a small TO-92 style 78L12 regulator, and 5 volts via a standard TO-220 style 7805regulator. You could always use a 7812, the 78L12 was used as the current demand is lower and the casing is smaller. The power for the whole project will come from a 15V DC 1.5A power supply. So our project’s power supply schematic will be as follows:

Now to mount the optocouplers and the power circuitry on the blank protoshield. Like most things in life it helps to make a plan before moving forward. I like to use graph paper, each square representing a hole on the protoshield, to plan the component layout. For example:

It isn’t much, but it can really help. After checking the plan over, it is a simple task to get the shield together. Here is my prototype example:

It isn’t neat, but it works. The header pins are used to make connecting the wires a little easier, and the pins on the right hand side are used to import the 15V and export 12V for the remote.

Question – What frequency is mains power in Australia?

While the soldering iron is hot, the wires need to be soldered to the remote control. Due to the unfortunate size of the PCB tracks, there wasn’t much space to work with:

But with time and patience, the wiring was attached:

Again, as this is a prototype the aesthetics of the modification are not that relevant. Be careful when handling the remote, as any force on the wiring can force the soldered wire up and break the PCB track. After soldering each pair of wires to the button pads, use the continuity function of a multimeter to check for shorts and adjust your work if necessary.

At this stage the AC remote control shield prototype is complete. It can be tested with a simple sketch to turn on and off the related digital outputs. For example, the following sketch will turn on and off each outlet in sequence:

Example 33.1

/* Example 33.1 - test our AC remote prototype http://tronixstuff.com/tutorials > chapter 33 | CC by-sa-nc */  void setup() { pinMode(9, OUTPUT); // 1 off pinMode(8, OUTPUT); // 1 on pinMode(5, OUTPUT); // 2 off pinMode(4, OUTPUT); // 2 on }  void loop() { // outlets on channel 1 on digitalWrite(8, HIGH); delay(1000); digitalWrite(8, LOW); delay(5000); // outlets on channel 1 off digitalWrite(9, HIGH); delay(1000); digitalWrite(9, LOW); delay(5000); // outlets on channel 2 on digitalWrite(4, HIGH); delay(1000); digitalWrite(4, LOW); delay(5000); // outlets on channel 2 off digitalWrite(5, HIGH); delay(1000); digitalWrite(5, LOW); delay(5000); }

Now to get connected with our GSM shield. It is a simple task to insert the remote shield over the GSM shield, and to connect the appropriate power supply and (for example) GSM aerial. The control sketch is a slight modification of example 27.2, and is shown below:

Example 33.2 (Mega version)

/* Example 33.2  Control two AC remote outlets via SMS tronixstuff.com/tutorials > chapter 33 |  CC by-sa-nc NOT for Arduino Mega */  #include   //Include the NewSoftSerial library to send serial commands to the cellular module. char inchar;                //Will hold the incoming character from the Serial Port. NewSoftSerial cell(2,3);    //Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.  int aon = 8; int aoff = 9; int bon = 4; int boff = 5; int pressdelay = 1000; // duration to activate a button on remote  void setup() { // prepare the digital output pins pinMode(aon, OUTPUT); pinMode(aoff, OUTPUT); pinMode(bon, OUTPUT); pinMode(boff, OUTPUT); //Initialize GSM module serial port for communication. cell.begin(9600); delay(30000); // give time for GSM module to register on network etc. cell.println("AT+CMGF=1"); // set SMS mode to text delay(200); cell.println("AT+CNMI=3,3,0,0"); // set module to send SMS data to serial out upon receipt delay(200); }  void loop() { //If a character comes in from the cellular module... if(cell.available() >0) { inchar=cell.read(); if (inchar=='#') { delay(10); inchar=cell.read(); if (inchar=='a') { delay(10); inchar=cell.read(); if (inchar=='0') { digitalWrite(aoff, HIGH); delay(pressdelay); digitalWrite(aoff, LOW); } else if (inchar=='1') { digitalWrite(aon, HIGH); delay(pressdelay); digitalWrite(aon, LOW);  } delay(10); inchar=cell.read(); if (inchar=='b') { inchar=cell.read(); if (inchar=='0') { digitalWrite(boff, HIGH); delay(pressdelay); digitalWrite(boff, LOW);  } else if (inchar=='1') { digitalWrite(bon, HIGH); delay(pressdelay); digitalWrite(bon, LOW);  } delay(10); inchar=cell.read(); cell.println("AT+CMGD=1,4"); // delete all SMS } } } } }

The variable pressdelay stores the amount of time in milliseconds to ‘press’ a remote control button. To control our outlets, we send a text message using the following syntax:


Where a/b are remote channels one and two, and x is replaced with 0 for off and 1 for on.

So there you have it – controlling almost any AC powered device via text message from a cellular phone. Imagine trying to do that ten, or even five years ago. As always, now it is up to you and your imagination to find something to control or get up to other shenanigans.Thank you for your patience in awaiting this series of articles. Although getting it together was a little tricky, it was a lot of fun. I hope you enjoyed reading it as much as I did writing it for you.

If you have any questions about the processes or details in this article, please ask in our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, there is the odd competition or give-away –  and we can all learn something. Or follow tronixstuff on twitter and facebook. High resolution images available from flickr.

Otherwise, have fun, stay safe, be good to each other – and make something!

By John Boxall

Leave a Reply

Please log in using one of these methods to post your comment:

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 )

Google+ photo

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

Connecting to %s