@rayan said: If i do understand you correctly you want to toggle the relay when the switch is toggled regardless which state it is in? If so just remove the && state == LOW and the relay whill be toggled each time stateChagened toggles if ( stateChanged ) { if ( ledState == LOW ) { ledState = HIGH; } else { ledState = LOW; }