Send SMS using SIM900 and ArduinoMega


#1

Hello everyone,

I am working on a project, in which I have to send an SMS with a predefined text and the correct time, when some event happens (eg. when a motor stops/runs - but for now, any high signal works).
For this, I am using sim900, and ArduinoMega and I succeeded in sending the SMS (“Event happened at:” “15:45:05”) to my cellphone number.
But I need to upgrade this project and after some research, I found Thinger.io, and connected to it (with the simplest connection code).
I understood more or less how things work here. My goal is to create a dashboard, with some editable text boxes, so I can change the cell numbers and the text at any time (because when the project be ready, i will not be able to change the code), and also get the time from here, without using RTC (I used DS1307 before).
I don’t know if thats possible.
So, in synthesis, i need to:

  • send sms to 5 phone numbers with a text and the current time (updated from network)
  • be able to change the phone numbers from thinger.io

That’s it. Thanks for everything


#2

Hi @Rafael_Freitas,

this is possible. Not over a dashboard yet, but over the device API explorer is something quite easy to do. Take a look to the following post in the community that wanted to do something similar (instead of card numbers you can store phone numbers):

The same will apply to the text to send. Just define a text resource for controlling it.

Hope it helps! :wink:


#3

Hi @alvaro, this is my code so far, but not seem to be working. Do you have any ideas about what could I have done wrong?

‘’’
#define TINY_GSM_MODEM_SIM900
#define DEBUG
#include <TinyGsmClient.h>
#include <ThingerGPRS.h>
#include <SPI.h>
#include “sms.h”
#include <Wire.h>

char mob_num[]="+5565996357512"; //numero do chip

#define USERNAME “Freitas”
#define DEVICE_ID “LED”
#define DEVICE_CREDENTIAL “credenciais”

ThingerGPRS thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL, Serial1);

SMSGSM sms;
String smsText = "Rafael: Teste do projeto em ";
boolean started=false;
char sms_text[160];
#define LED 5
int sensor = 9;

#define MAX_CARDS 5
#define CARD_ID_LENGTH 20
char auth_cards[MAX_CARDS][CARD_ID_LENGTH] = {“a12345678910”, //my cell phone number here
"b12345678910",
“c12345678910”};

void setup(){
Serial.begin(9600);
Serial.println(“INICIALIZANDO SIM900”);
pinMode(48,OUTPUT);
digitalWrite(48,HIGH);
delay(500);
digitalWrite(48,LOW);
delay(500);

Wire.begin();

// rtc.begin();
pinMode (sensor, INPUT);
pinMode (LED,OUTPUT);

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

// Serial GPRS
 Serial1.begin(9600);
// Definir APN
thing.setAPN("zap.vivo.com.br", "vivo", "vivo");


thing["auth_cards"] << [](pson& in){
    // provide current auth devices
    if(in.is_empty()){
        pson_array& array = in;
        for(int i=0; i<MAX_CARDS; i++){
            array.add((const char*)auth_cards[i]);   }
    // update current cards
    }else if(in.is_array()){
        pson_array& array = in;
        for(int i=0; i<array.size() && i<MAX_CARDS; i++) {
            const char *card_id = (const char *) *array[i];
            if(strlen(card_id)>CARD_ID_LENGTH) continue;
            strcpy(auth_cards[i], card_id);
        }
    }
};

}

void mostraResposta(){
while(Serial1.available()!=0){
Serial.write(Serial1.read()); }
}

void loop(){
thing.handle();

if (sensor == HIGH){
digitalWrite(LED, HIGH);
//timestamp = getDateTime();
//Serial.println(timestamp);
//smsText = smsText+timestamp;
smsText.toCharArray(sms_text,160);
sms.SendSMS(“auth_cards[0]”,sms_text); //is this way right??
sms.SendSMS(“auth_cards[1]”,sms_text); //is this way right??

String smsText = "Rafael: Teste do projeto em ";

}
}
’’’