Embedtronix Build Your Embedded System


This example shows how to use a low-cost SIM800l GSM/GPS Module to send an SMS message in response to a security switch opening or closing.

Your need the following :
1 x SIM800l Module
1 x 3A Power Supply
1 x High Power Buck-to-Buck Converter
1 x Window/Door Switch
1 x Arduino Uno
1 x SIM card that supports a 2G network. 
Optional: USB Breakout

1. Power Supply
Remove the USB plug from the power supply (or optionally use the USB breakout to avoid removing the USB connector) and connect to the input of the buck-tobuck converter being mindful of polarity. Adjust the buck-to-buck converter for an output of approximately 4V. Actual value can be anywhere from 3.7V to 4.2V for the Sim800l module.
Connect the power from the buck-to-buck converter to the SIM800l VCC and GND connections.

2. SIM800l and Arduino
Connect Arduino GND and GND on the SIM800l module. It is important that this GND is common with the GND of the back-to-buck converter as the reference voltage must be the same.
Connect RXD and TXD to pins 10 and 11 on the Arduino Uno.

3. Window/Door switch
Connect one end of the door switch to Arduino digital pin 3. Connect the other end to GND. We are not going to short 5V to GND as we are going to use the internal pullup resistor on pin 3 to hold it high by default.

4. SIM Card
Setup your Ting account and insert the SIM (mini size - the Ting comes in macro size and can be broken into Mini or micro).

5. Arduino Libraries
Download this SIM800l Arduino library. There are many other libraries you can try but this will work fine for this example. Install it as a Zip library in the Arduino IDE.
Install Debounce2 library in the Arduino IDE. This is a known library, no need to download it, the system will do that automatically.

6. Arduino Sketch
Use this sketch, changing the phone number to the one you want to send an SMS message to.



/* this library is written by Cristian Steib.
* steibkhriz@gmail.com
* Designed to work with the GSM Sim800l, may work with SIM900L
*
* This library uses SoftwareSerial, you can define de RX and TX pin
* in the header "Sim800l.h" ,by default the pin is RX=10 TX=11..
* be sure that GND is attached to arduino too.
*
* RESET_PIN is optional for most usage
*
* Esta libreria usa SoftwareSerial, se pueden cambiar los pines de RX y TX
* en el archivo header, "Sim800l.h", por defecto los pines vienen configurado en
* RX=10 TX=11.
* Tambien se puede cambiar el RESET_PIN por otro que prefiera
*
* PINOUT:
* _____________________________
* | ARDUINO UNO >>> SIM800L |
* -----------------------------
* GND >>> GND
* RX 10 >>> TX
* TX 11 >>> RX
* RESET 2 >>> RST (optional)
* 
* POWER SOURCE 4.2V >>> VCC
*
* Created on: April 20, 2016
* Author: Cristian Steib
*
*/
#include <Sim800l.h>
#include <Bounce2.h>
#include <SoftwareSerial.h> //is necesary for the library!!

Sim800l Sim800l; //to declare the library
char* closedText;
char * openText;
char* number;
bool error; //to catch the response of sendSms

#define SWITCH_PIN 3 // Connect switch pin here
Bounce debouncer = Bounce();
int currentState = -1;
int lastState = -1;

void setup(){
 Serial.begin(9600);
 Sim800l.begin(); // initializate the library.
 closedText="Door has been closed"; //text for the message.
 openText="Door has been opened"; //text for the message.
 number="xxxxxxxxxx"; //sms phone number
 pinMode(SWITCH_PIN, INPUT_PULLUP);
 debouncer.attach(SWITCH_PIN);
 debouncer.interval(100);
 //digitalWrite(BUTTON_PIN, HIGH);
}

void loop(){
 debouncer.update();
 currentState = debouncer.read();
 if (currentState != lastState){
  if(currentState == HIGH){
   Serial.println("open");
   error=Sim800l.sendSms(number,openText);
  }
  else {
   error=Sim800l.sendSms(number,closedText);
   Serial.println("closed");
  }
  lastState = currentState;
 }
} 
author
Embedtronix
Build Your Embedded System. Belajar bareng ngoprek Microcontroller, Arduino, TPLink, GLiNet dan ilmu Microelectronic lainnya.