:~
I need some help with my arduino uno code. I am trying to get a sms sent to my mobile whenever the door is opened.
the goodnews is, that i can get it to send an sms when the door FIRST opens. but if i shut the door and open it again say 30 Seconds later, I dont get a new SMS.
The only way to get a new SMS sent is to re-set the Arduino. Am i missing something in my code. The code I have has be cut and paste from a couple of web sites.
at the moment when the Arduino is powered ON, There is a delay of 35 secs to allow to gsm to register on the network. Then if the door is opened for more than 3 sec, the sms is sent
I'm using and Arduino uno R3, Sparkfun SM5100B GSM, and a reed swith as the door contact. Here is the CODE
#include <SoftwareSerial.h>
SoftwareSerial module(2,3); // We need to create a serial port on D2/D3 to talk to the GSM module
char mobilenumber[] = "078xxxxxxx4"; // Replace xxxxxxxx with the recipient's mobile number
int sensor = 12; // pin sensor is attached to
int time = 0;
int time_threshold = 3000; //time in ms => 10 sec.
int val = 0;
int led = 11;
void setup()
{
module.begin(9600); //Initialize serial ports for communication.
pinMode(sensor,INPUT);
pinMode(led,OUTPUT);
digitalWrite(sensor,HIGH);
delay(35000); // give the GSM module time to initialise, locate network etc.
}
void loop()
{
digitalWrite(led,HIGH);
val = digitalRead(sensor);
while(val == LOW){
val = digitalRead(sensor);
}
time = 0;
while((val == HIGH)&&(time < time_threshold)){
time = time + 100;
val = digitalRead(sensor);
delay(100);
digitalWrite(led,HIGH);
}
if (time >= time_threshold){
digitalWrite(led,LOW);
for (int i=100;i>5000;i++);
module.println("AT+CMGF=1"); // set SMS mode to text
module.print("AT+CMGS="); // now send message...
module.write(34); // ASCII equivalent of "
module.print(mobilenumber);
module.write(34); // ASCII equivalent of "
module.println();
delay(500); // give the module some thinking time
module.println("Door Open Alert"); // our message to send
module.write(26); // ASCII equivalent of Ctrl-Z
module.flush();
delay(10000); // the SMS module needs time to return to OK status
do // You don't want to send out multiple SMSs.... or do you?
{
delay(1);
}
while (1>0);
}
}