Alarme Residencial via GSM

A aplicação a seguir faz uso de uma Gboard e mais alguns sensores, para servir de alarme residencial, capaz de enviar um SMS caso alguém passe diante de um dos sensores de presença. Para simplificar, o sketch usará apenas um sensor de presença, porém no final comentaremos como acrescentar outros.
Com um sensor de presença e algumas modificações em nosso sketch, podemos construir um verdadeiro alarme residencial que avisa enviando um sms caso alguém passe no raio de ação do sensor:

#include “SIM900.h”
#include <SoftwareSerial.h>
//We don’t need the http functions. So we can disable the next line.
//#include “inetGSM.h”
#include “sms.h”
#include “call.h”

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.

//Simple sketch to check if an incoming call is from an authorized
//number and in this case, send to this number an SMS with the value
//of a digital input.

//We have to create the classes for SMSs and calls.
CallGSM call;
SMSGSM sms;

char number[20];
byte stat=0;
int value=0;
int pin=1;
char value_str[5];

void setup()
{
pinMode(pin,INPUT);
//Serial connection.
Serial.begin(9600);
Serial.println(“GSM Shield testing.”);
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(2400))
Serial.println(“\nstatus=READY”);
else Serial.println(“\nstatus=IDLE”);
};

void loop()
{
//Chekcs status of call
stat=call.CallStatusWithAuth(number,0,0);
//If the incoming call is from an authorized number
//saved on SIM in the positions range from 1 to 3.
if(stat==CALL_INCOM_VOICE_AUTH){
//Hang up the call.
call.HangUp();
delay(2000);
do
{
delay(50);
//Check the value of the input.
value=analogRead(A0);
//Convert the int to a string.
itoa(value,value_str,10);
//if(value>0){
}
while (value==0);
//Send an SMS to the previous number with
//the value read previously.
sms.SendSMS(number,”Perimeter Warning System: alarm ativated”);//(number,value_str);
Serial.print(“SMS sent to  :”);
Serial.println(number);
}
delay(1000);
};

ESTAÇÃO METEOROLÓGICA

Com mais algumas modificações, transformamos nosso projeto em uma estação de monitoramento ambiental via sms!

double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
}
//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
return celsius + 273.15;
}
// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
double A0= 373.15/(273.15 + celsius);
double SUM =-7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM +=-1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * humidity;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}
// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
double Td = (b * temp) / (a-temp);
return Td;
}

#include <dht11.h>
dht11 DHT11;
#define DHT11PIN A2

#include “SIM900.h”
#include <SoftwareSerial.h>
//We don’t need the http functions. So we can disable the next line.
//#include “inetGSM.h”
#include “sms.h”
#include “call.h”

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.

//Simple sketch to check if an incoming call is from an authorized
//number and in this case, send to this number an SMS with the value
//of a digital input.

//We have to create the classes for SMSs and calls.
CallGSM call;
SMSGSM sms;

char number[20];
byte stat=0;
int value;
int pin=1;
char value_str[5];

void setup()
{
pinMode(pin,INPUT);
//Serial connection.
Serial.begin(9600);
Serial.println(“DHT11 TEST PROGRAM “);
Serial.print(“LIBRARY VERSION: “);
Serial.println(DHT11LIB_VERSION);
int chk = DHT11.read(DHT11PIN);
Serial.print(“Read sensor: “);

Serial.println(“GSM Shield testing.”);
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(2400))
Serial.println(“\nstatus=READY”);
else Serial.println(“\nstatus=IDLE”);
};

void loop()
{
//Chekcs status of call
stat=call.CallStatusWithAuth(number,0,0);
//If the incoming call is from an authorized number
//saved on SIM in the positions range from 1 to 3.
if(stat==CALL_INCOM_VOICE_AUTH){
//Hang up the call.
call.HangUp();
delay(2000);
//do
//{
//delay(50);
//Check the value of the input.
value=DHT11.temperature;
//Convert the int to a string.
itoa(value,value_str,10);
//if(value>0){
// }
//while (value==0);
//Send an SMS to the previous number with
//the value read previously.
sms.SendSMS(number,value_str);//”Perimeter Warning System: alarm ativated”);//(number,value_str);
Serial.print(“SMS sent to  :”);
Serial.println(number);
// }
delay(2000);
}
};

Anúncios

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair /  Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair /  Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair /  Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair /  Alterar )

Conectando a %s