Pages: [1]   Go Down
Author Topic: How to send temperature from DS18B20 sensor via SMS ?  (Read 337 times)
0 Members and 1 Guest are viewing this topic.
France
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everybody,

In my project i want to display temperatures from 4 sensors DS18B20, (LCD 4x20) driving relay via SMS and my first goal, return temperatures via SMS  smiley-grin,

I use SIM900 shield with this libraries: https://code.google.com/p/gsm-shield-arduino/

Everything work fine, excepted i don't know how to return temperature in buffer1 and buffer2 from sensor 1 and 2 and print them via:

Code:
void tsitting_room(DeviceAddress sitting_room)
{
  float tempC = sensors.getTempC(sitting_room);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    lcd.setCursor(0, 0);
    lcd.print("T salon");
    lcd.print(tempC);
    lcd.print(" C");
  }
}

void troom(DeviceAddress room)
{
  float tempC = sensors.getTempC(room);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    lcd.setCursor(0, 1);
    lcd.print("T ch 1 ");
    lcd.print(tempC);
    lcd.print(" C");
  }
}

and i don't know if  using
Code:
strcat(message_str, buffer1);
sms.SendSMS(number,buffer1);
are a good way

Main Code
Code:
#include "SIM900.h"
#include "sms.h"
#include <OneWire.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#define ONE_WIRE_BUS 4

LiquidCrystal_I2C lcd(0x27,16,2); //LCD en I2C
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

DeviceAddress room = { 0x10, 0x5E, 0xE8, 0x33, 0x02, 0x08, 0x00, 0xDB };   //Sensor 1
DeviceAddress sitting_room = { 0x10, 0xBE, 0xCA, 0x33, 0x02, 0x08, 0x00, 0x89 };  //Sensor 2

SMSGSM sms;
 
char number[]="XXXXXXXXX";  // Destination number
char message[180];
char pos;
char *p;

char buffer2[6];
char buffer1[6];
char message_str[21]="Temperature room is:";

void setup()
{
  lcd.init();                      // initialize the lcd
  lcd.backlight();
  sensors.begin();
  sensors.setResolution(sitting_room, 10);
  sensors.setResolution(room, 10);
  Serial.begin(9600);
  if (gsm.begin(2400))
  Serial.println("\nstatus=READY");
  else
  Serial.println("\nstatus=IDLE");
  (sms.SendSMS(number, "Starting ok")); //envoie d'un SMS au demarrage
  pinMode(12, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop()
{
  returntemp();
  driverly();
  temp();
  runingled();
  void tsitting_room();
  void troom();
}

void driverly()
{
 pos=sms.IsSMSPresent(SMS_UNREAD);
  Serial.println((int)pos);
  if((int)pos>0&&(int)pos<=20){
    Serial.print("SMS incomming, POS=");
    Serial.println((int)pos);
    message[0]='\0';
    sms.GetSMS((int)pos,number,message,180);
    p=strstr(message,"password");
    if(p){
      Serial.println("PSWD OK");
      p=strstr(message,"led on");
      if(p){
        Serial.println("LED ON");
        digitalWrite(12,HIGH);
      }
      else{
        p=strstr(message,"led off");
        if(p){
          Serial.println("LED OFF");
          digitalWrite(12,LOW);
        }
       sms.DeleteSMS((int)pos);
      }
    }
 }
  delay(5000);
}


void returntemp()
{
  pos=sms.IsSMSPresent(SMS_UNREAD);
  Serial.println((int)pos);
  if((int)pos>0&&(int)pos<=20){
    Serial.print("SMS incomming, POS=");
    Serial.println((int)pos);
    message[0]='\0';
    sms.GetSMS((int)pos,number,message,180);
    p=strstr(message,"password");
    if(p){
     Serial.println("Passwd OK !");
        p=strstr(message,"temp sitting room");
        if(p){
        Serial.println("sitting room sms");
        strcat(message_str, buffer2);
        sms.SendSMS(number,buffer2);
        }
        else{
        p=strstr(message,"temp room");
        if(p){
        Serial.println("room sms");
        strcat(message_str, buffer1);
        sms.SendSMS(number,buffer1);
        }
      sms.DeleteSMS((int)pos);
        }
      }
    }
  delay(5000);
}

void tsitting_room(DeviceAddress sitting_room)
{
  float tempC = sensors.getTempC(sitting_room);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    lcd.setCursor(0, 0);
    lcd.print("T salon");
    lcd.print(tempC);
    lcd.print(" C");
  }
}

void troom(DeviceAddress room)
{
  float tempC = sensors.getTempC(room);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    lcd.setCursor(0, 1);
    lcd.print("T ch 1 ");
    lcd.print(tempC);
    lcd.print(" C");
  }
}

void temp()
{
  delay(500);
  Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();
  Serial.print("Temp room:");
  troom(room);
  Serial.print("\n\r");
  Serial.print("Temp sitting_room:");
  tsitting_room(sitting_room);
  Serial.print("\n\r");
}

void runingled()
{
  digitalWrite(7, HIGH);   // set the LED on
  delay(80);              // wait for a second
  digitalWrite(7, LOW);    // set the LED off
  delay(1000);              // wait for a second 
}


anybody can help me ?


king regards!
Logged

Pages: [1]   Go Up
Jump to: