Hi Guys,
I am currently working on a project which consists of sensing the server room temperature then trigger an alert message once the temperature value exceed the baseline.
I am using an arduino uno R3 + DHT11 temperature sensor and Seeed studio GPRS SHIELD v2.
I am currently able to get the temperature and print it on the serial monitor however, once merge both the GPRS and the temperature code. i receive a blank sms on my mobile.
/////////////////////////////////////////////////////////////////////////////////////
the code is the following:
#include <SoftwareSerial.h>
#include <String.h>
#include <dht11.h>
#define DHT11_PIN 2 //DHT11 sensor connected pin
dht11 dht;
SoftwareSerial gprsSerial(7, 8);
char incoming_char = 0;
float currentTemperature;
int baseline = 20;
void setup()
{
gprsSerial.begin(19200); // setting the GPRS shield baud rate to 19200
Serial.begin(19200);
delay(500);
gprsSerial.print("AT+CMGF=1\r"); // set SMS mode to text
delay(100);
Serial.begin(9600);
}
//DHT11 sensor query
int querySensor() {
int test;
Serial.print("DHT11, \t");
test = dht.read(DHT11_PIN);
switch (test) {
case DHTLIB_OK:
Serial.print("OK\t");
currentTemperature = dht.temperature;
Serial.print(currentTemperature);
Serial.print("C,\t");
return 0;
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println("Checksum error");
return 1;
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.println("Time out error");
return 1;
break;
default:
Serial.println("Unknown error");
return 1;
break;
}
}
void loop()
{
if (!querySensor()) {
Serial.println("connecting...");
for (int i = 0; i < 2; i++) {
int progress;
if (i == 0) {
progress = (currentTemperature );
Serial.print("Sending temprature: ");
}
}
}
delay(20000);
}
void check() {
if (currentTemperature > baseline); // if actuel temp is greater than 20
SendTextMessage(); // send the text message
}
// SendTextMessage
void SendTextMessage()
{
Serial.println("Sending Text...");
gprsSerial.print("AT+CMGF=1\r"); // Set the shield to SMS mode
delay(100);
gprsSerial.println("AT+CMGS = "+22376360908""); //receiver number
delay(100);
gprsSerial.println(currentTemperature); // send temperature / humidity values
delay(100);
gprsSerial.print((char)26);//the ASCII code of the ctrl+z is 26 (required according to the datasheet)
delay(100);
gprsSerial.println();
Serial.println("Text Sent.");
}