t r o n i x s t u f f

fun and learning with electronics

Tutorial: Control AC outlets via SMS

This is the revised, 2012 edition of 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.

Welcome back fellow arduidans!

Assumed understanding for this article is found in part one. If you have not already done so, please read and understand it.

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 7805 regulator. 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.

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:

#axbx

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.

Have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

April 24, 2011 - Posted by | AC power, arduino, cellular, hardware hacking | , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

14 Comments

  1. Awesome stuff, although I dont understand half of this stuff, I still enjoy reading this. Also, where are the questions for the contest?

    Thanks!

    Erick

    Comment by Erick | April 25, 2011

    • Hello Erick
      Thanks for your comment. The questions are randomly spread throughout posts published in April. Four have been planted so far. If you use the search function of your web browser for the word “Question” you will find them. Or just read through all the posts :)
      Have fun
      john

      Comment by John Boxall | April 25, 2011

  2. Hi, im browsing the web for a dirt cheap GSM way to turn on my server at home, i thought i would use an ardweeny (10$) and some sort of GSM shield, those GSM shields are however quite pricey :( . do you have any idea of how i could cheaply trigger the button on my server via GSM or if cheaper and just as easy WAN? i figured i just need to attach a relay of sorts to the pwr button in my server and then trigger that somehow.

    Comment by Mikkel Jeppesen | May 21, 2011

    • Hello Mikkel
      You can certainly turn things on and off via GSM, we have explained this in chapters 27 and 33 of my Arduino tutorials. If all you need to do is activate a low-voltage button the GSM-controlled ardweeny and an optocoupler would be fine (see chapter 33). If you are looking for a cheap GSM module, the cheapest I have seen is this one – http://www.seeedstudio.com/depot/gprs-shield-p-779.html?cPath=132_134 however I haven’t tried it so can’t support it.
      have fun
      john

      Comment by John Boxall | May 21, 2011

  3. Hi, would this work without ripping apart the remote? As in, using a 433MHz RF link to send commands to the wireless power outlets? Thanks

    Comment by George | May 30, 2011

  4. Hi – I managed to track down the same wireless kit as you’ve got (thanks, Jaycar!) and have built the board without problems. However, I am not so much gifted with the old hand-eye coordination as you appear to be (and don’t have cement to set the wires in place!) so soldering the buttons has been a bit of a nightmare. I’ve only got one button working as a result.

    This has led me to think that a better solution might be to isolate the rf transmitter and decode/encode the rf stream and then send it directly through the transmitter. Have to had any experience with this? Presumably a modulator would be needed or something…

    Comment by steve | May 30, 2011

    • Hi Steve and George
      Yeah the button soldering is a bit of a mess. After reading your comment today I happened across another type in a sale brochure that could be easier, from Altronics (A0340).
      Analysing the transmission could be ok if you had receiver with outputs on a logic analyser matched to the transmitter. One could quite easily make their own custom system using wireless modules and 240VAC relays however I wouldn’t publish the details for safety’s sake.
      cheers
      john

      Comment by John Boxall | May 31, 2011

      • Hi – thanks for your reply, John. I’ll take a look at the Altronics transmitter.

        Cheers,

        S

        Comment by steve | May 31, 2011

      • Thanks for taking the time to post a reply. I’ll give it a go.

        Cheers

        Comment by George Watson | May 31, 2011

  5. Would love to see teardown pics of one of the receiver units to see what the internal hardware is.
    Is it a relay or a triac? Running the radio receiver and the relay from a transformerless power supply, I assume?

    Comment by Luke Weston | August 22, 2011

    • It was a relay. Afraid I binned it when cleaning up a few weeks ago.
      cheers
      john

      Comment by John Boxall | August 22, 2011

    • Found the photos you were looking for, I put them on flickr and not the website. Scroll around the photostream here -http://www.flickr.com/photos/tronixstuff/5648836523/

      Comment by John Boxall | August 26, 2011

  6. sir.please give me detail working of control AC via sms. I will give seminar on control AC via sms.so i need working of this system. Please reply soon.

    Comment by Raman kumar | September 14, 2011

    • The detail is in the article. If you’re going to give a seminar frankly you should work it out yourself so you can proficiently explain it to your audience.

      Comment by John Boxall | September 14, 2011


Sorry, the comment form is closed at this time.

Follow

Get every new post delivered to your Inbox.

Join 2,588 other followers