I'm exploring the EEPROM of arduino on how to change data using serial , and text it to phone number ,
In my code i have a default string that will text in my phone number , i want to change that default string in Serial of the arduino , but when i power up again the arduino the default string or text is still sending in my number . This is my code
#include <SoftwareSerial.h>
#include <EEPROM.h>
String x = "myString";
SoftwareSerial mySerial(9, 10);
void setup()
{
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
for(int i=0; i<x.length(); i++){
EEPROM.write(i, x[i]);
}
reads();
delay(5000);
SendMessage();
}
void loop()
{
x="";
while(Serial.available() > 0){
x = Serial.readString();
x.substring(x.indexOf("\n"));
x.replace("\n","");
Serial.println(x);
}
for(int i=0; i<x.length(); i++){
EEPROM.update(i, x[i]);
}
if (mySerial.available()>0)
Serial.write(mySerial.read());
}
void SendMessage()
{
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=\"+639290584072\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println(x);// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void reads(){
for(int i=0; i<x.length(); i++){
byte z = EEPROM.read(i);
char a = char(z);
Serial.print(a);
}
}