-1

I have a temperature sensor set up working with an LCD and a stick to adjust the brightness. I now want the temperature sensor to send a text whenever it reaches a certain temperature. Can somebody please help. The GSM unit i have is the SIM800L below is what I have so far :

#include<LiquidCrystal.h>

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

const int sensor=A1; // Assigning Analog Pin A1 to variable 'sensor'
float tempc; //variable to store temperature in degree Celsius
float tempf; //variable to store temperature in Fahrenheit
float vout; //temporary variable to hold sensor reading

void setup()
{
    pinMode(sensor,INPUT); // Configuring pin A1 as INPUT Pin
    Serial.begin(9600);
    lcd.begin(16,2);
    delay(500);
}

void loop()
{
    vout=analogRead(sensor);
    vout=(vout*500)/1023;

    tempc=vout; // Storing value in degrees Celsius
    tempf=(vout*1.8)+32; // Converting Temperature value from degrees Celsius to Fahrenheit

    lcd.setCursor(0,0);
    lcd.print("DegreeC= ");
    lcd.print(tempc);
    lcd.setCursor(0,1);
    lcd.print("Fahrenheit=");
    lcd.print(tempf);

    delay(1000); //Delay of 1 second for ease of viewing in serial monitor
}
Tom
  • 1,739
  • 15
  • 24

2 Answers2

1

you could use the library Fona to send SMS with a Sim800L

to send a message you use the command -> fona.sendSMS(sendto, message)

#include <SoftwareSerial.h>
#include "Adafruit_FONA.h"

//This part declares that the RX, TX and RST pins of the SIM800L must be connected
//to pin 2, 3 and 4 of the Arduino.
#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4

SoftwareSerial fonaSS = SoftwareSerial(FONA_RX, FONA_TX);
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

void setup() {
  while (!Serial);
  Serial.begin(115200);
  Serial.println(F("FONA basic test"));
  Serial.println(F("Initializing....(May take 3 seconds)"));
  fonaSS.begin(9600); 
  if (!fona.begin(fonaSS)) {            
    Serial.println(F("Couldn't find FONA"));
    while (1);
  }
  Serial.println(F("FONA is OK"));

   char sendto[21], message[141];
                :
                :
   //initialize sendto and message
                :
                :
   if (!fona.sendSMS(sendto, message)) {
      Serial.println(F("error"));
   } else {
      Serial.println(F("sent!"));
   }
}

to adapt the program to your case: i have put some lines of codes from setup to loop (easy to understant sendto and message definitions in loop now)

#include <SoftwareSerial.h>
#include "Adafruit_FONA.h"

//This part declares that the RX, TX and RST pins of the SIM800L must be connected
//to pin 2, 3 and 4 of the Arduino.
#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4

SoftwareSerial fonaSS = SoftwareSerial(FONA_RX, FONA_TX);
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

void setup() {
 fonaSS.begin(9600); 
 // you initialisation code
}

void loop()
{
    vout=analogRead(sensor);
    vout=(vout*500)/1023;

    tempc=vout; // Storing value in degrees Celsius
    tempf=(vout*1.8)+32; // Converting Temperature value from degrees Celsius to Fahrenheit

    lcd.setCursor(0,0);
    lcd.print("DegreeC= ");
    lcd.print(tempc);
    lcd.setCursor(0,1);
    lcd.print("Fahrenheit=");
    lcd.print(tempf);

    delay(1000); //Delay of 1 second for ease of viewing in serial monitor
    if (tempc > 30.0) {
        SendSms();
    }
}

void SendSms() {  
        char sendto[] = "+19999999999"; //put the desired destination phone number for sms here
        char message[141];
        sprintf(message, "Alert TEMP is %.2f", tempc);// limit to 140
         //sends the message via SMS
        if (!fona.sendSMS(sendto, message)) {
      Serial.println(F("error"));
    } else {
      Serial.println(F("sent!"));
    }
}

another way to send sms you could test the hayes command: for example

void sendsms(){
    Serial.println("Sending text message...");
    fonaSS.print("AT+CMGF=1\r");  // SMS MODE
    delay(100);
    // phone number    
    fonaSS.print("AT+CMGS=\"+33676171212\"\r"); //indicate your phone number 
   delay(100);
   // message here    
   fonaSS.print("Message test \r");  
   // CTR+Z in mode ASCII, to indicate the end of message
   fonaSS.print(char(26));            
   delay(100);
   fonaSS.println();
   Serial.println("Text send"); 
   }
Frenchy
  • 16,386
  • 3
  • 16
  • 39
-1
#include <SoftwareSerial.h>
#include "Adafruit_FONA.h"

//This part declares that the RX, TX and RST pins of the SIM800L must be connected
//to pin 2, 3 and 4 of the Arduino.
#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4

SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

void setup() {
 // you initialisation code
}

void loop()
{
    vout=analogRead(sensor);
    vout=(vout*500)/1023;

    tempc=vout; // Storing value in degrees Celsius
    tempf=(vout*1.8)+32; // Converting Temperature value from degrees Celsius to Fahrenheit

    lcd.setCursor(0,0);
    lcd.print("DegreeC= ");
    lcd.print(tempc);
    lcd.setCursor(0,1);
    lcd.print("Fahrenheit=");
    lcd.print(tempf);

    delay(1000); //Delay of 1 second for ease of viewing in serial monitor
    if (tempc > 30.0) {
        SendSms();
    }
}

void SendSms() {  
        char sendto[] = "+19999999999"; //put the desired destination phone number for sms here
        char message[141];
        sprintf(message, "Alert TEMP is %.2f", tempc);// limit to 140
         //sends the message via SMS
        if (!fona.sendSMS(sendto, message)) {
      Serial.println(F("error"));
    } else {
      Serial.println(F("sent!"));
    }
} 
  • i dunno if important but some initialization could be done like that:->SoftwareSerial fonaSS(FONA_RX,FONA_TX); but i think its th same thing but you could test too – Frenchy Jan 18 '19 at 13:28
  • Could you send me a link for the correct software serial file needed – Hashim Shakil Jan 18 '19 at 19:14
  • The issue is to do with the fona SS. You are not telling it to do anything – Hashim Shakil Jan 18 '19 at 20:03
  • i am using the library included in arduino IDE no need to install other library – Frenchy Jan 19 '19 at 09:29
  • id ont see why its not functional.. if you have the led blinking slow its and if the wire is right , i dont see why its not functional....maybe a stupid question ... you havent a code pin activated in your simcard? – Frenchy Jan 19 '19 at 09:46
  • i have exactly use the same logic aand wire than http://miliohm.com/sim800l-arduino-tutorial/ for me and its fucntional... – Frenchy Jan 19 '19 at 09:49
  • So yours is currently sending messages? I have tried testing the device against other code sending a text and it works. So it does seem like somtbing is wrong with the code. I currently have my RX TX and RST connected to pins 2 3 and 4. I will change it so they are connected to 10 and 11. Do you think this will make a difference – Hashim Shakil Jan 19 '19 at 10:56
  • yes i am sending and no i dont think the wire change will do a difference..maybe a bad wire??? – Frenchy Jan 19 '19 at 11:23
  • Dont think its bad wire as it sends using diffrent code. I will try changing the wire never the less. – Hashim Shakil Jan 19 '19 at 12:50