Components Required
GSM shield
Arduino
Gas detection sensor module
_________________________________________________________________________________
Arduino Program:
int PIN = 7;// attach gas sensor to pin 7
int sensor = 0;
void setup()
{
pinMode (PIN,INPUT);
Serial.begin(9600); // gsm baud rate
delay(5000);
}
void loop()
{
sensor = digitalRead (PIN); // read whether gas is presented or not
if (sensor == HIGH){ // if gas is presented send a message
Serial.println("AT");
delay(1000);
Serial.println("AT+CMGF=1"); // send SMS in text mode
delay(1000);
Serial.println("AT+CMGS=\"+919962\""); //CHANGE TO Number , you'd like to receive message
delay(1000);
Serial.print("Gas Leakage at HOME (attention required)"); // content of the message
Serial.write(26); // ctrl+z ASCII code
delay(300000); // Wait for 5 minutes before next reading
}
}
_________________________________________________________________________________
please explain me why there is a 3rd connection given from the sensor to the audrino board which is connected to the 7th terminal of the board? if so then is it same for all the sensors to have 3 terminals .And most important of all where do i purchase these in india
ReplyDeletethanks in advance
Do you have code for SIM300
ReplyDeleteor will the same code works with SIM 300 GSM module?
thankssss its great
ReplyDeleteCan someone help me? This is my code.
ReplyDelete#include
#include "SIM900.h"
#include "sms.h"
#include
//#include
#include
SMSGSM sms;
boolean started = false;
char buffer[160];
char smsbuffer[160];
char n[20];
//LiquidCrystal lcd(4,2,3,7,8,9);
int buttonState;
int lastButtonState = LOW;
long lastDebounceTime = 0;
long debounceDelay = 50;
boolean st = false;
int buzzer = 12;
void setup() {
//lcd.begin(16, 2);
Serial.begin(9600);
if (gsm.begin(2400))
{
started = true;
}
if (started)
{
delsms();
}
sms.SendSMS("+60142646978" , "Gas Sensor and GSM module activated");
}
void loop() {
//lcd.setCursor(0, 0);
//lcd.print("Detektor Gas SMS");
int val = analogRead(A0);
val = map(val, 0, 1023, 0, 100);
//lcd.setCursor(0,1);
//lcd.print("Kadar: ");
//lcd.print(val);
//lcd.print("% ");
//code using sensor detection
if (val > 10) {
tone(buzzer,800,500);
delay(1000);
st = true;
}
else st = false;
if (st != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (st != buttonState) {
buttonState = st;
if (buttonState == HIGH) {
PString str(buffer, sizeof(buffer));
str.begin();
str.print("Gas Detected! Gas leakage at ");
str.print(val);
str.print("%");
//String a=str;
sms.SendSMS("+60142646978", buffer);
}
}
}
//code using sms lapor.
lastButtonState = st;
int pos = 0;
if (started)
{
pos = sms.IsSMSPresent(SMS_ALL);
if (pos)
{
sms.GetSMS(pos, n, smsbuffer, 100);
delay(2000);
if (!strcmp(smsbuffer, "lapor"))
{
PString str(buffer, sizeof(buffer));
str.begin();
str.print("Rate of gas leakage currently at ");
str.print(val);
str.print("%");
//String a=str;
sms.SendSMS("+60142646978", buffer);
}
delsms();
}
}
}
//delete sms yang dihantar
void delsms()
{
for (int i = 0; i < 10; i++)
{
int pos = sms.IsSMSPresent(SMS_ALL);
if (pos != 0)
{
if (sms.DeleteSMS(pos) == 1) {} else {}
}
}
}
I'm using arduino uno, sim900 module, mq2 gas sensor and buzzer to create a gas sensor detector based on sms.
I have to 2 option :
1. The mq2 gas sensor detects and send the result via sms to the number set in the code.
2. We can send a specific string to know the surrounding gas percentage and send the result to the specific number set in the code.
But I want to change the second option to be auto reply to any incoming number. What should I do?
please share the arduino model?
ReplyDelete