Variables

Is there any way to change a variable while the program on the arduino is working like send some value thru the serial and if the arduino is restarted the variable continue with the last value change.

Yes but you will need to store this variable in EEPROM so that the value is retained over power cycles/restarts. You can read in a new value from the serial port, update your variable and then write it to EEPROM. Upon startup, you would read the value from EEPROM and assign it to your variable.

blh64:
Yes but you will need to store this variable in EEPROM so that the value is retained over power cycles/restarts. You can read in a new value from the serial port, update your variable and then write it to EEPROM. Upon startup, you would read the value from EEPROM and assign it to your variable.

How? (sorry there are some thins in arduino that i am a noob)

Simple demo code

#include <EEPROM.h>

char ch;
int eepromAddress = 0;

void setup()
{
  Serial.begin(57600);
  
  EEPROM.get(eepromAddress, ch);
  Serial.print("read from EEPROM: ");
  Serial.println(ch, HEX);
}


void loop()
{
  if (Serial.available() > 0)
  {
    char data = Serial.read();
    EEPROM.put(eepromAddress, data);
    Serial.print(data, HEX);
    Serial.println(" written to EEPROM");
  }
}

The code uses EEPROM.put and EEPROM.get instead of EEPROM.write and EEPROM.read. There are two advantages.
EEPROM.put only writes the EEPROM if the data that you want to store has changed preventing wear of the EEPROM cell.
EEPROM.put allows you to write any type of data (bytes, ints, floats, structs etc). Strings (capital S) are an exception as it will not write the actual text; but you should not use String objects anyway ;).

The above code simply writes a character that is received. If you want to write more than one variable, you will have to increment eepromAddress with the size of the variable.

Code compiles but is not tested.