Error in using SIM800L V.2

Good day! I am having an error in sending SMS using SIM800L v.2 because it cannot send variable value. Can anyone help me.

mySerial.println("AT");
      updateSerial();
      mySerial.println("AT+CMGF=1"); 
      updateSerial();
      mySerial.println("AT+CMGS=\"+639351898981\"");
      updateSerial();
      mySerial.print("This is your bill:" + price);
      updateSerial();
      mySerial.write((char)26);
      delay (1000);
      Serial.println(message);

This looks odd...
Does this work better?

mySerial.print("This is your bill: ");
mySerial.print(price);

Thank you for posting it code tags, and welcome to the forum!

This might work if "price" is a String object. If "price" is some other type of variable it will either do unexpected things or fail to compile.

For example, if 'price' is an integer containing 5:
"This is your bill:" + price
results in:
"is your bill:"
(The 5 is used as an index into the character array.)

A better way to write it might be:

      mySerial.print("This is your bill:");
      mySerial.print(price);

This will work for any type of 'price' a long as it is printable.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.