You are on page 1of 16

Code 1

int timesTosend=2;

int count=0;

char phone_no[]=”9443657545”;

void setup{}

Serial.begin(9600);

delay(500);

Serial.printin(“AT+CMGF=1”);

delay(500);

void loop{}

while(count<timesTosend){

delay(1000);

Serial.print(“AT+CMGS=\””);

Serial.print(phone_no);

Serial.println("\"");

while(Serial.read()!=’>’);

Serial.print(“the car has faced an sevier accident plse emerge soon,car no:1234”);

delay(500);

Serial.write(0x1A);

Serial.write(0x0D);

Serial.write(0x0A);

delay(2000)

count++
}

Code2 correct

#include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 10);

void setup()

mySerial.begin(9600); // Setting the baud rate of GSM


Module

Serial.begin(9600); // Setting the baud rate of Seri


al Monitor (Arduino)

delay(100);

}
void loop()

if (Serial.available()>0)

switch(Serial.read())

case 's':

SendMessage();

break;

case 'r':

RecieveMessage();

break;

if (mySerial.available()>0)

Serial.write(mySerial.read());

}
void SendMessage()

mySerial.println("AT+CMGF=1"); //Sets the GSM Module


in Text Mode

delay(1000); // Delay of 1000 milli seconds or 1 secon


d

mySerial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Rep
lace x with mobile number

delay(1000);

mySerial.println("I am SMS from GSM Module");// The SMS


text you want to send

delay(100);

mySerial.println((char)26);// ASCII code of CTRL+Z

delay(1000);

}
void RecieveMessage()

mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to
receive a live SMS

delay(1000);

}
Code 3
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

Serial.println("SMS Messages Sender");

// connection state
boolean notConnected = true;

// Start GSM shield


// If your SIM has PIN, pass it as a parameter of begin() in quotes
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
} else {
Serial.println("Not connected");
delay(1000);
}
}

Serial.println("GSM initialized");
}

void loop() {

Serial.print("Enter a mobile number: ");


char remoteNum[20]; // telephone number to send sms
readSerial(remoteNum);
Serial.println(remoteNum);

// sms text
Serial.print("Now, enter SMS content: ");
char txtMsg[200];
readSerial(txtMsg);
Serial.println("SENDING");
Serial.println();
Serial.println("Message:");
Serial.println(txtMsg);

// send the message


sms.beginSMS(remoteNum);
sms.print(txtMsg);
sms.endSMS();
Serial.println("\nCOMPLETE!\n");
}

/*
Read input serial
*/
int readSerial(char result[]) {
int i = 0;
while (1) {
while (Serial.available() > 0) {
char inChar = Serial.read();
if (inChar == '\n') {
result[i] = '\0';
Serial.flush();
return 0;
}
if (inChar != '\r') {
result[i] = inChar;
i++;
}
}
}
}

Code 4

void setup()
{

Serial.begin(9600);

void loop()

delay(1200);

Serial.print("AT");

delay(1200);

bool bOK = false;

while (Serial.available() > 0)

char inChar = (char)Serial.read();

bOK = true;

if(bOK)

Serial.println();

Serial.println("AT+CMGF=1"); // sets the SMS mode to text

delay(100);

delay(1200);

bool bOK = false;

while (Serial.available() > 0) {

//Serial.write(Serial.read());

char inChar = (char)Serial.read();

bOK = true;

if(bOK)
{

Serial.println();

Serial.print("AT+CMGS="); // send the SMS number

Serial.print("+923004772379");

Serial.println("\"");

delay(1000);

Serial.print("A new post is created by Zain."); // SMS body

delay(500);

Serial.write(0x1A);

Serial.write(0x0D);

Serial.write(0x0A);

}
Code with analysis

#include <SoftwareSerial.h>

#include<LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

SoftwareSerial mySerial(9, 10);

int sensor=A1;

float temp_read,Temp_alert_val,Temp_shut_val;

int sms_count=0,Fire_Set;

void setup()

pinMode(sensor,INPUT);

mySerial.begin(9600);

Serial.begin(9600);
lcd.begin(16,2);

delay(500);

void loop()

CheckFire();

CheckShutDown();

void CheckFire()

lcd.setCursor(0,0);

lcd.print("Fire Scan - ON");

Temp_alert_val=CheckTemp();

if(Temp_alert_val>45)
{

SetAlert(); // Function to send SMS Alerts

float CheckTemp()

temp_read=analogRead(sensor); // reads the sensor output


(Vout of LM35)

temp_read=temp_read*5; // converts the sensor reading


to temperature

temp_read=temp_read/10; // adds the decimal point

return temp_read; // returns temperature value in degree


celsius

void SetAlert()

{
while(sms_count<3) //Number of SMS Alerts to be sent

SendTextMessage(); // Function to send AT Commands to GSM


module

Fire_Set=1;

lcd.setCursor(0,1);

lcd.print("Fire Alert! SMS Sent!");

void CheckShutDown()

if(Fire_Set==1)

Temp_shut_val=CheckTemp();

if(Temp_shut_val<28)
{

lcd.setCursor(0,1);

lcd.print("Fire Shut! SAFE NOW");

sms_count=0;

Fire_Set=0;

}}}

void SendTextMessage()

mySerial.println("AT+CMGF=1"); //To send SMS in Text


Mode

delay(2000);

mySerial.println("AT+CMGS=\"+919544xxxxxx\"\r"); // cha
nge to the phone number you using

delay(2000);

mySerial.println("Fire in NEW ROOM!");//the content of


the message

delay(200);
mySerial.println((char)26);//the stopping character

delay(5000);

mySerial.println("AT+CMGS=\"+919847xxxxxx\"\r"); // ch
ange to the phone number you using

delay(2000);

mySerial.println("Fire in NEW ROOM!");//the content of


the message

delay(200);

mySerial.println((char)26);//the message stopping chara


cter

delay(5000);

sms_count++;

Port

You might also like