The GSM sends many SMS text messages and does not stop. How to send only one SMS? This is my code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);
char msg;
int vibr_pin = 7;
void setup() {
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
pinMode(vibr_pin, INPUT);
delay(100);
}
void loop() {
int a;
a = digitalRead(vibr_pin);
if (a == 0) {
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+60125456758\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("test 1,2,3"); // The SMS text you want to send
delay(100);
mySerial.println((char) 26); // ASCII code of CTRL+Z
delay(1000);
}
}
EDIT:
After I change if (a==0)
to if(a!=0)
, it only sends message when the vibration sensor is moving. How to send sms when sensor is not moving?
flag
variable toremember
if you sent a message