How to Save Value from Counter to EEPROM in Arduino Uno [solved]

 EEPROM.write(sensorState, sensorState);

This will write 0 to EEPROM address 0 every time you start or reset the Arduino. Is that what you want ?

Then you never read from the EEPROM so why bother writing to it ?

  sensorState = analogRead(sensorPin);
  if (buttonPin == HIGH) sensorState = 0;

buttonPin has been set to 8 (ie HIGH) when declared and its value will never change so why test it ? Did you mean to digitalRead() the pin ?

Your program should write sensorCounter to EEPROM address 0 when its value changes and set the value of sensorCounter to the value at EEPROM address 0 in setup() to restore the previously written value after a reset or restart.

NOTE : The EEPROM write() and read() functions write a single byte to EEPROM and your counter is a 2 byte int. You need to look at the EEPROM get() and put() functions to read and write an int.

address