storing latch solenoid state problem

Hi,
I have tried to use this in my code to store if the solenoid was closed or opened but not working...
I would like to use like:
if value is less than or equal to 60 and solenoid is closed, than open that
if value is less than or equal to 60 and solneoid is open, stay open ( solenoid_off)

if value is more than or equal to 61 and solenoid is opened, than close that
if value is lmore than or equal to 61 and solneoid is closed, stay closed ( solenoid_off)

Thanks for any help!

if ((moistvalue1mapped <= 60) && (solenoidclosed =true ))
  {
    solenoid_open();
    solenoidclosed = false;
    delay(200);
    solenoid_off();
    delay(200);
    Serial.println(F("Solenoid is opened"));
    lcd.setCursor(0, 0);
    lcd.print("ON");
    delay(100);
  }
  else if (solenoidclosed = false)
  {
    solenoid_off();
    delay(200);
    Serial.println(F("Solenoid is opened"));
    lcd.setCursor(0, 0);
    lcd.print("ON");
    delay(100);
  }
  if ((moistvalue1mapped >= 61) && (solenoidclosed = false))
  {
    solenoid_close();
    solenoidclosed = true;
    delay(200);
    solenoid_off();
    delay(200);
    Serial.println(F("Solenoid is closed"));
    lcd.setCursor(0, 0);
    lcd.print("OFF");
    delay(200);
  }
  else if (solenoidclosed = true)
  {
    solenoid_off();
    delay(200);
    Serial.println(F("Solenoid is closed"));
    lcd.setCursor(0, 0);
    lcd.print("OFF");
    delay(200);
  }

solenoidclosed =true``if (solenoidclosed = false)
BZZZZZT

AWOL, I have modified from solenoidclosed =true to solenoidclosed = true...
but...
I mean I need to work like if it is closed and <=60 let's open else if it was opened, stay opened (use solenoid_off) and
if it is opened and >=61 let's close else if it was closed, stay closed.

have modified from solenoidclosed =true to solenoidclosed = true...

You're assigning ("=") the value "true" to solenoidclosed, and then testing the result of the assignment to see if it true or false.
It will always be true.
And, if you assign the value false to a variable, then the result will always be false.

Use "==" to test.

ooohhhh....serious mistake...testing that...

working fine! :slight_smile: sorry for the rookie question! :):):slight_smile: And thanks!!