from machine import Pin
from time import sleep
#active relay using Pin 1
RLY = Pin(1,Pin.OUT) #ESP1 set as output for relay control
RLY.off() #reset PIN to native state
BTN = Pin(2,Pin.IN, Pin.PULL_UP) #pull up stops erratic triggeruing due to electrical noise
while True:
if not BTN.value(): # same as BTN.value() == 0
RLY.on()
sleep(0.05)
RLY.off()