Hello, i'm trying to make a project which need to be on power save mode as possible.I use an arduino pro mini that is in sleep mode and an RTC DS3231 send an interrupt at the alarm that i set to then wake up do some work and then go to sleep.Everything works fine with the alarms and the code except the SIM900 parts which i need to send an sms with some sensor values.It seems that it skips completely the sms part.If someone could help would be nice.Here is a sample code :
#include <avr/sleep.h>
#include <Wire.h>
#include <RTClibExtended.h>
#include <SoftwareSerial.h>
#include <DHT.h>;
#define interruptPin 2 //Pin we are going to use to wake up the Arduino
#define relay 4
#define ledPin 13
#define DHTPIN 12 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
RTC_DS3231 RTC; //we are using the DS3231 RTC
SoftwareSerial mySerial(6, 5); //SIM800L Tx & Rx is connected to Arduino #6 & #5
float hum; //Stores humidity value
float therm_mesa; //Stores temperature value
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
dht.begin();
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
delay(2000);
digitalWrite(ledPin, LOW);
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
//Initialize communication with the clock
Wire.begin();
RTC.begin();
RTC.adjust(DateTime(__DATE__, __TIME__)); //set RTC date and time to COMPILE time
//clear any pending alarms
RTC.armAlarm(1, false);
RTC.clearAlarm(1);
RTC.alarmInterrupt(1, false);
RTC.armAlarm(2, false);
RTC.clearAlarm(2);
RTC.alarmInterrupt(2, false);
RTC.writeSqwPinMode(DS3231_OFF);
//Set alarm1 every day at 18:33
RTC.setAlarm(ALM1_MATCH_HOURS, 41, 1, 0); //set your wake-up time here// SETUP: minutes/hours/seconds
// RTC.setAlarm(ALM2_MATCH_HOURS, 27, 17, 0); //set your wake-up time here// SETUP: minutes/hours/seconds
RTC.alarmInterrupt(1, true);
}
void loop() {
Serial.print("Entering sleep mode");
delay(5000);
Going_To_Sleep();
}
void Going_To_Sleep(){
sleep_enable();//Enabling sleep mode
attachInterrupt(0, wakeUp, LOW);//attaching a interrupt to pin d2
set_sleep_mode(SLEEP_MODE_PWR_DOWN);//Setting the sleep mode, in our case full sleep
digitalWrite(ledPin,LOW);//turning LED off
sleep_cpu();//activating sleep mode
Serial.println("just woke up!");
//next line of code executed after the interrupt
digitalWrite(ledPin,HIGH);//turning LED on
digitalWrite(relay, HIGH);
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
therm_mesa= dht.readTemperature();
delay(1000);
Serial.print("Humidity:");
Serial.print(hum);
Serial.print("Temperature:");
Serial.print(therm_mesa);
sendSMS();
digitalWrite(relay, LOW);
digitalWrite(ledPin, LOW);//turning LED on
Serial.print("Clearing alarms");
//When exiting the sleep mode we clear the alarm
RTC.armAlarm(1, false);
RTC.clearAlarm(1);
RTC.alarmInterrupt(1, false);
}
void wakeUp(){
Serial.println("Interrrupt Fired");//Print message to serial monitor
sleep_disable();//Disable sleep mode
detachInterrupt(0); //Removes the interrupt from pin 2;
}
void sendSMS(){
mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
mySerial.println("AT+CMGS=\"+mobile\"");//change ZZ with country code and xxxxxxxxxxx with phone number to sms
mySerial.println("Thermokrasia mesa:");
mySerial.println(therm_mesa);
mySerial.println("Ygrasia:");
mySerial.println(hum);
// End AT command with a ^Z, ASCII code 26
mySerial.println((char)26);
delay(100);
mySerial.println();
// Give module time to send SMS
delay(5000);
}