Hi, I'm new to Arduino and I'm having troubles with my code, it reads the gas values fine and the buzzer turns on when the gas value is over 400, my problem is that it doesn't send the SMS like it is supposed to do, I need to solve this issue asap. Thanks in advance.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
int buzzer = 12;
int GASA0 = A5;
int gasvalue;
void setup() {
mySerial.begin(9600);
Serial.begin(9600);
pinMode(buzzer, OUTPUT);
delay(500);
}
void loop() {
int analogSensor = analogRead(GASA0);
int gasvalue=(analogSensor);
Serial.print("Gas: ");
Serial.println(gasvalue);
delay (500);
if (gasvalue > 400)
{
SendTextMessage();
tone(buzzer, 1000);
}
else
{
noTone(buzzer);
}
delay(500);
}
void SendTextMessage()
{
mySerial.println("AT+CMGF=1"); //To send SMS
delay(1000);
mySerial.println("AT+CMGS=\"+528681566666\"\r");//phone number
delay(1000);
mySerial.println("ALERTA: SE HA DETECTADO UNA FUGA DE GAS.");// content of the message
delay(200);
mySerial.println((char)26);
delay(1000);
}