I need some help, hastily. I'm trying to trigger the GSM to send a text message when an 'interrupt' happens. All is well except it did not send the text message. Have I got it wrong somewhere? I made this out of combining button, interrupt and gsm basic codes.
#include <SoftwareSerial.h>
#include <String.h>
SoftwareSerial gprsSerial(7, 8);
const int buttonPin = 3; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
volatile int buttonState = 0; // variable for reading the pushbutton status
void setup() {
gprsSerial.begin(19200);
Serial.begin(19200);
delay(500);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
// Attach an interrupt to the ISR vector
attachInterrupt(0, pin_ISR, CHANGE);
}
void loop() {
gprsSerial.println();
if(buttonState==1)
{
Serial.println("Supply ON");
delay(100);
}
else
{
Serial.println("Supply OFF");
delay(100);
}
delay(5000);
}
void pin_ISR() {
buttonState = digitalRead(buttonPin);
digitalWrite(ledPin, buttonState);
SendTextMessage();
}
void SendTextMessage()
{
Serial.println("Sending Text...");
gprsSerial.println("AT+CMGF=1\r");
delay(100);
gprsSerial.println("AT+CMGS = "+????????"");
delay(100);
if(buttonState==1)
{
gprsSerial.println("Supply ON");
delay(100);
gprsSerial.print((char)26);
delay(100);
}
else
{
gprsSerial.println("Supply OFF");
delay(100);
gprsSerial.print((char)26);
delay(100);
}
gprsSerial.println();
Serial.println("Text Sent");
}