Skip to content

Instantly share code, notes, and snippets.

@EDISON-SCIENCE-CORNER
Created October 4, 2024 14:49
Show Gist options
  • Select an option

  • Save EDISON-SCIENCE-CORNER/b430e726350acf6b41f98ba1096e35ce to your computer and use it in GitHub Desktop.

Select an option

Save EDISON-SCIENCE-CORNER/b430e726350acf6b41f98ba1096e35ce to your computer and use it in GitHub Desktop.
//EDISON SCIENCE CORNER
//www.esclabs.in
#include <SoftwareSerial.h>
SoftwareSerial GSM(11, 10); //SIM800 Tx & Rx is connected to Arduino
char phone_no[]="+919074213906"; //your number with country code
#define bt_C A1 // Button2 Pin A1 use for sos
#define bt_S A0
void setup(){
Serial.begin(9600);
GSM.begin(9600);
pinMode(bt_C, INPUT_PULLUP);
pinMode(bt_S, INPUT_PULLUP);
Serial.println("Initializing....");
initModule("AT","OK",1000); //Once the handshake test is successful, it will back to OK
initModule("ATE1","OK",1000); //this command is used for enabling echo
initModule("AT+CPIN?","READY",1000); //this command is used to check whether SIM card is inserted in GSM Module or not
initModule("AT+CMGF=1","OK",1000); //Configuring TEXT mode
initModule("AT+CNMI=2,2,0,0,0","OK",1000); //Decides how newly arrived SMS messages should be handled
Serial.println("Initialized Successfully");
}
void loop(){
if(digitalRead (bt_C) == 0)
{
callUp(phone_no);
delay(1000);
}
if(digitalRead (bt_S) == 0)
{
sendSMS(phone_no,"emergency alert");;
delay(500);
}
delay(5);
}
void sendSMS(char *number, char *msg){
GSM.print("AT+CMGS=\"");GSM.print(number);
GSM.println("\"\r\n");
delay(500);
GSM.println(msg);
delay(500);
GSM.write(byte(26));
delay(500);
}
void callUp(char *number)
{
GSM.print("ATD + ");
GSM.print(number);
GSM.println(";");
delay(20000);
GSM.println("ATH");
delay(100);
}
void initModule(String cmd, char *res, int t){
while(1){
Serial.println(cmd);
GSM.println(cmd);
delay(100);
while(GSM.available()>0){
if(GSM.find(res)){
Serial.println(res);
delay(t);
return;
}else{Serial.println("Error");}}
delay(t);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment