I am trying to get this sketch working. It does everything i want except sending the SMS. I wont get anything. This is what i got through serial:
Waiting for GSM
Waiting for GSM
Simpel
SMS Deleted
Sending SMS
Waiting to send
Sent or timed out
Going to sleep
Wait
I used an example sketch from the IDE with success.
(Arduino Pro Mini 3.3V clone + SIM900A)
#include <GSM.h>
#include <HWSerial.h>
#include <SIM900.h>
#include <sms.h>
#include <WideTextFinder.h>
#include <SoftwareSerial.h>
#include <EEPROM.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#define power_pin 4 //Pin used to power GSM module on and off.
#define config_switch_pin 6 //Pin to read configuration
#define SMS_waiting_threshold 45000 //How long the module will stay on after notification in order to receive potential configured number
#define SMS_TIMEOUT_THRESHOLD 15000 //The time that the program waits for a send acknowledgement of an SMS
#define batt_pin A0 //Pin for battery level measurement
#define wake_pin 3 //Pin used for waking up
SoftwareSerial mySerial(7, 8); // RX, TX
String number = "+xxxxxxxxx"; //Set default number to call - in case none is programmed in the EEPROM yet
int start; //Variable used to start counting time for timeouts
String text; //Variable used for serial communication with the GSM module
float battery_level;
void setup()
{
battery_level = ((analogRead(batt_pin) / 1024.0) * 5.0); //Measure battery level before we start consuming more power and scale it to 5V
Serial.begin(9600);
mySerial.begin(9600);
pinMode(power_pin, OUTPUT);
pinMode(wake_pin, INPUT_PULLUP); //We'll use internal pull-up resistors to simplify the breadboard layout
pinMode(config_switch_pin, INPUT);
attachInterrupt(0, wakeUpNow, HIGH); //Use interrupt 0 (pin 2) and run function wakeUpNow when pin 2 gets LOW
MCUSR = 0; //Pre-configure WDT
number = get_number(); //Obtain number from EEPROM
power_GSM(); //Power up the GSM module
while (get_net_status()=="NC") { //Check every 1 second if the GSM module has registered in the network
Serial.println(F("Waiting for GSM"));
delay(1000);
}
I changed it but still no SMS. I am starting to think it takes a kind of demon worshipping to get this code working.
I tried this little sketch to send an sms. Worked flawless.
Uploaded the other sketch again. Serial monitor gave me this:
Waiting for GSM
Simpel
SMS Deleted
Sending SMS
Waiting to send
Sent or timed out
T+CMGDA="DEL ALL"
OK
AT+CMGF=1
OK
"
You've got mail!
Going to sleep
Waiting for serial and going to sleep
I have not looked at the code that checks the SMS response, just the send-SMS bit. Your code checking the responses from the SIM900 is not okay, as I told you in the last lines of my reply, but I have not debugged that code.
Somehow it got it to work after i used the a proper connection for the config switch and stored my mobile number in the EEPROM. Works very well but i can't stand not knowing what the real problem was since i entered my number in case there was no number stored in EEPROM.
After many hours of trying and searching it suddenly started working and received an sms.
I made a mistake with defining the pins the config pin was connected to the same pin as the rx pin to the SIM900. The program kept looping waiting for an sms with 'PROGRAM' in it. Merely by coincidence i sent one. After ungrounding the configswitch pin and resetting the Pro Mini i received my sms.
The sketch itself provides 2 ways of using a mobile nummer. Storing one in the EEPROM and enter one in the sketch. Only storing one in EEPROM seems to make the whole thing work.
I just can't find out why the number stored in the sketch doesn't work and i just can't stand that. I like to know how stuff works of why not.
Also i found out the Pro Mini with original bootloader does not support system restart by the watchdogtimer so i had to burn the Optiboot bootloader. That should rule out any problems with the millis funcion doesn't it?
By the way, the original .ino of this sketch comes from this Instructable
The sketch itself provides 2 ways of using a mobile nummer. Storing one in the EEPROM and enter one in the sketch. Only storing one in EEPROM seems to make the whole thing work.
I just can't find out why the number stored in the sketch doesn't work and i just can't stand that. I like to know how stuff works of why not.
I had a look, but did not see anything obvious at first sight, but I did not keep the whole sketch, nor did I use actual EEPROM. Bytes are usually not very different when they are read from EEPROM
You can do a few things:
Cut out everything you don't need. E.g. keep this: