Hi, as you can see, I made the arduino gsm sheild to send a message every time the button is pressed. But I don’t know why when the button is pressed, it just keeps spamming messages.
/Note:This code is used for Arduino 1.0 or later/
#include <SoftwareSerial.h>
const int buttonPin = 2;
int buttonState = 0;
SoftwareSerial Sim900Serial(2, 3);
void setup()
{
pinMode(buttonPin, INPUT);
Sim900Serial.begin(115200); // the GPRS baud rate
delay(500);
Sim900Serial.println(“AT+IPR=19200”);
delay(500);
Sim900Serial.begin(19200); // the GPRS baud rate
delay(1000);
Serial.begin(9600); // the Hardware serial rate
Serial.println(“Please type ‘s’ to send SMS”);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
SendTextMessage();
}
if (Sim900Serial.available())
Serial.write(Sim900Serial.read());
else{
(buttonState == LOW);
}
}
void SendTextMessage()
{
Sim900Serial.print(“AT+CMGF=1\r”); //Sending the SMS in text mode
delay(100);
Sim900Serial.println(“AT + CMGS = “*********””);//The target phone number
delay(100);
Sim900Serial.println(“Hello I am testing at 9.25”);//the content of the message
delay(100);
Sim900Serial.println((char)26);//the ASCII code of the ctrl+z is 26
delay(100);
Sim900Serial.println();
}