1

I have the below code working from https://www.youtube.com/watch?v=Y30iEOxl1To - to receive temperature & humidity as an sms when i give a missed call to a specific number (sim on the gsm shield)

The above code is like on demand sms. I also want to alter this code so it can automatically send me another sms if the temperature exceeds a threshold.

Please help.

Below is the code...

#include "SIM900.h"
#include <SoftwareSerial.h>
#include "call.h"
#include <DHT.h>
#include "sms.h"

SMSGSM sms;
#define DHTPIN 7  
#define DHTTYPE DHT22   

CallGSM call;
boolean started=false;
char sms_text[160];

DHT dht(DHTPIN, DHTTYPE);

void setup()
{
    dht.begin();
    Serial.begin(9600);

    if (gsm.begin(9600)) 
    {
        Serial.println("\nstatus=READY");
        started=true;
    } 
    else 
        Serial.println("\nstatus=IDLE");
}

void loop()
{
    float humidity, temperature;
    String smsText ="";
    if(temperature>29)
    {
        switch (call.CallStatus())
        {
            case CALL_NONE: // Nothing is happening
                break;

            case CALL_INCOM_VOICE : // Yes! Someone is calling us
                Serial.println("RECEIVING CALL");
                call.HangUp();
                delay(1000);
                humidity = dht.readHumidity();
                temperature = dht.readTemperature();
                delay(1000);
                smsText = "Temperature: "+String(temperature,1)+"C Humidity: "+String(humidity,1)+"%";
                smsText.toCharArray(sms_text,160);
                //Serial.println(smsText);
                sms.SendSMS("+91**********",sms_text);
                break;

            case CALL_COMM_LINE_BUSY:  // In this case the call would be established
                Serial.println("TALKING. Line busy.");
                break;
        }
        delay(1000);
    }
}
2

The code below will check if the temperature goes above 29 degrees. It also check whether the temperature was below 29 previously, to prevent it from sending an SMS every second, for as long as it's above 29 degrees C.

#include "SIM900.h"
#include <SoftwareSerial.h>
#include "call.h"
#include <DHT.h>
#include "sms.h"

SMSGSM sms;
#define DHTPIN 7  
#define DHTTYPE DHT22   

CallGSM call;
boolean started=false;
char sms_text[160];

DHT dht(DHTPIN, DHTTYPE);

void setup()
{
    dht.begin();
    Serial.begin(9600);

    if (gsm.begin(9600)) 
    {
        Serial.println("\nstatus=READY");
        started=true;
    } 
    else 
        Serial.println("\nstatus=IDLE");
}

float previousTemperature = 0;
void loop()
{
    float humidity, temperature;
    humidity = dht.readHumidity();
    temperature = dht.readTemperature();
    delay(1000);

    // check if temperature has raised to above 29 degrees
    if(temperature>29 && previousTemperature<=29)
    {
        sendSMS(temperature, humidity);
    }
    previousTemperature = temperature;

    // check for incomming call
    switch (call.CallStatus())
    {
        case CALL_NONE: // Nothing is happening
            break;

        case CALL_INCOM_VOICE : // Yes! Someone is calling us
            Serial.println("RECEIVING CALL");
            call.HangUp();
            delay(1000);
            sendSMS(temperature, humidity);
            break;

        case CALL_COMM_LINE_BUSY:  // In this case the call would be established
            Serial.println("TALKING. Line busy.");
            break;
    }

    delay(1000);
}

void sendSMS(float temperature, float humidity)
{
    String smsText ="";
    smsText = "Temperature: "+String(temperature,1)+"C Humidity: "+String(humidity,1)+"%";
    smsText.toCharArray(sms_text,160);
    //Serial.println(smsText);
    sms.SendSMS("+91**********",sms_text);  
}
12
  • You are awesome :-) – Susindran Srinivasan Jul 4 '16 at 16:34
  • Thank you. Just make sure to mark this answer as accepted, in return. – Gerben Jul 9 '16 at 10:05
  • I get this error now when compiling the same code in ARDUINO IDE /Users/administrator/Documents/GSM_Call_Receive/GSM_Call_Receive.ino: In function 'void loop()': GSM_Call_Receive:42: error: 'sendSMS' was not declared in this scope sendSMS(temperature, humidity); ^ GSM_Call_Receive:56: error: 'sendSMS' was not declared in this scope sendSMS(temperature, humidity); ^ exit status 1 'sendSMS' was not declared in this scope – Susindran Srinivasan Mar 13 '18 at 12:07
  • That’s not how it works! – Gerben Mar 13 '18 at 12:30
  • well i had the void sms part before the loop function and it started working – Susindran Srinivasan Mar 23 '18 at 3:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.