My Arduino fun projects: Part4: SMS controlled devices (e.g. lights)

in #arduino8 years ago

Ever wanted to control your lights or appliances via SMS from anywhere in the world...here we go. I designed this little project to switch ON/OFF my lights when I am not home just to make people believe I am still around.

Features and operation:

  • Prototype is built around a stand-alone 8 Bit AVR microcontroller – ATMEGA328P.
  • Two solid state relays 1 and 2.
  • SIM900 GSM module receives an SMS for example R11 (meaning Relay 1 – 1 = ON / 0 = OFF) which will switch ON an 220
  • AC devices connected to Relay 1 or 2.

Full table of SMS to be sent:

Well by changing the code you can always create your own table for example "Lights ON" and "Lights OFF".


I will breakdown the project into fewer parts and conclude by combining all the parts as a final design.

Parts to be discussed:

Please note: I used two regulators because GSM alone draws close to 1 ampere when connecting the network and during transmission which gives the ATMega a shock...it then goes into a save mode by shutting down. Rather separate them.


SIM900 GSM module

Connect the GSM to the ATmega328 or Arduino as show above.


ATMega328 to Arduino pinout


Here is a little recap on the pins of the Arduino in relation to ATMega


Solid state relay


Well the are different methods to use like the normal relay with that clicking sound...then optocouplers...I mean you can use any method. I prefer solid state relays as they are more reliable and can handle more current...even the life span is longer...but they do not come cheap.

Image credit and more info
I used the above Arduino compatible breakout module and connected Relay 1 to Arduino pin A4 and Relay 2 to Arduino pin A3.


Final design:

The full Arduino sketch is uploaded on Github
You going to need SIM900 GSM library which I include on Github

#include "SIM900.h"
#include <SoftwareSerial.h> //GSM RX = 3; TX = 2
#include "sms.h"
SMSGSM sms;

Relays:

const int Relay1 = A4;
const int Relay2 = A3;

Check if SMS has been received into a variable "Str":

sms_position=sms.IsSMSPresent(SMS_UNREAD);
        if (sms_position) 
        {    
            sms.GetSMS(sms_position, phone_number, sms_text, 10);
             for (y=0;y<10;y++)
             {
              str+= sms_text[y];
            }

Note i used str.toUpperCase(); to convert the SMS received to all CAPS just to ensure it is not case sensitive for example "ALLON" or "Allon" or "allON" still the same...it should still work.

Remember that table I discussed earlier about the relays SMS:

if(str =="R11")
            {
              digitalWrite(Relay1, HIGH);     
            }
            
            if(str =="R10")
            {
              digitalWrite(Relay1, LOW);  
            }
            
            if(str =="R21")
            {
              digitalWrite(Relay2, HIGH);  
            }

            if(str =="R20")
            {
              digitalWrite(Relay2, LOW);   
            }

            if(str =="ALLON")
            {
              digitalWrite(Relay1, HIGH); 
              digitalWrite(Relay2, HIGH);  
            }

            if(str =="ALLOFF")
            {
              digitalWrite(Relay1, LOW); 
              digitalWrite(Relay2, LOW);  
            }
        }

Feel free to use it and have fun with it

Kindly upvote and follow me: @mokluc….I will upload another project soon: My Arduino fun projects

Sort:  

Thanks for sharing. I bought a raspberry Pi and haven't set it up as yet.

Good learn Python you will do great things

Hi @mokluc
Great post, I love the idea, it just look a bit to complicated to me, I suppose you can buy it off the shelf? (Probably at a price)

Yes Communica in Midrand they have off the shelf products but im going to post about a data version not using SMS more cloud based much better

hi.i try it first time every thing work 100% first time..then i uploaded other code for other project .the i uploaded again ur code ,in this second time its not work .plz help me what can i do.
my facebook is Banderuos Banderuos‎

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63039.96
ETH 2549.01
USDT 1.00
SBD 2.78