I have a code that works absolutely fine for sending SMS after using command 's' in the serial monitor.
But can you please help in modifying the code, so that the GSM module can automatically send SMS to the mobile after the sensor (connected to A0 pin) hitting certain value (say 650 above)?
If you don't need (your?) switch-case procedure anymore, something like this might work.
void loop()
{
//This is for enabling sms sending procedure
boolean smsEnabled = false;
//This is for storing measured sensor value
int analogValue0 = analogRead(A0);
//These two variables are for setting the limits for sensor value.
//When upper limit has been reached, the sms will be sent and to avoid sending 1000 messages while sensor value is over upperValue,
//therefore there is a lowerValue which has to be reached to activate upperValue limit again. This 650-300 is called hysteresis. Value of the lowerValue depends how low you'd like go go until sms sending procedure will activated again.
int upperLimit = 650, lowerLimit = 300;
if(analogValue > upperLimit && smsEnabled == true)
{
smsEnabled = false;
// send an SMS!
// Here you'll send an sms.
...
}
if(analogValue < lowerLimit && smsEnabled == false)
{
smsEnabled = true;
}
}
Edit: What I'm not sure about, is it too fast to read analogRead so often. It has to be tested.
Well I can modify the code saying: take the reading for every 5 minutes or so and then respond with SMS. But what I can understand is.. how can I use sendto variable to set a default number and message variable to send specific text/s?
Also with this part of my code:
if (!fona.sendSMS(sendto, message)) {
Serial.println(F("Failed"));
} else {
Serial.println(F("Sent!"));
}
if fona.sendSMS is responsible for sending text message, how can I use this function in your version of code?
thnk u..