Trying to reset a loop when external lights change

Search the forum for "optocoupler".