When I reboot my esp32 both relay pins goes high and turns on. (Not Good)
Program works find but the boot is a big problem. I have tried to pull pins high and low. Does not seem to work.
Start your code here
import machine
from machine import Pin
import time
relay1 = Pin(14, Pin.OUT, machine.Pin.PULL_DOWN)
relay2 = Pin(13, Pin.OUT, machine.Pin.PULL_DOWN)
#relay3 = Pin(12, Pin.OUT, machine.Pin.PULL_DOWN)
#relay4 = Pin(15, Pin.OUT, machine.Pin.PULL_DOWN)
while True:
relay1.value(0) # to switch it off
time.sleep(2)
relay1.value(1) # to switch it on
time.sleep(2)
relay2.value(0) # to switch it off
time.sleep(3)
relay2.value(1) # to switch it on
time.sleep(2)
Hi.
When the ESP32 boots that are some pins that start at high and others that start at low.
Accordingly to this image: https://www.instructables.com/id/ESP32-Internal-Details-and-Pinout/
GPIO 14 starts at HIGH, when the ESP32 boots. So, it would be advisable to another pin that starts at low.
GPIO 15 also outputs a signal at boot (so, don’t use this gpio for a relay).
Can you read “Step 11” of this article and see if it helps: https://www.instructables.com/id/ESP32-Internal-Details-and-Pinout/
Also, check the ESP32 table pins here: https://espeasy.readthedocs.io/en/latest/Reference/GPIO.html
Then, let me know the results.
Regards,
Sara
Hi again.
I’ve quickly tested your sketch.
I have the problem you’ve described with GPIO 14. This GPIO starts HIGH on boot.
I didn’t have that problem with GPIO 13 – it starts LOW.
I’ve also experimented other “safe-to-use” GPIOs (for example, GPIO26) and I didn’t have that problem.
Can you use other GPIOs and see if your problem is solved?
Also, GPIO15 and GPIO12 also output a signal on boot.
The table in this article (scroll down for the ESP32 table) really helps choosing the pins: https://espeasy.readthedocs.io/en/latest/Reference/GPIO.html
Regards,
Sara
I have try to change the pins and still they come on when they boot. Has anyone else have this problem? What is wrong with this code??
Start your code here
import machine from machine import Pin import time
relay1 = Pin(32, Pin.OUT, machine.Pin. PULL_UP)
relay2 = Pin(33, Pin.OUT, machine.Pin. PULL_UP)
relay3 = Pin(25, Pin.OUT, machine.Pin. PULL_UP)
relay4 = Pin(26, Pin.OUT, machine.Pin. PULL_UP)
while True:
relay1.value(0) # to switch it off
time.sleep(2)
relay1.value(1) # to switch it on
time.sleep(2)
relay2.value(0) # to switch it off
time.sleep(3)
relay2.value(1) # to switch it on
time.sleep(2)
relay3.value(0) # to switch it off
time.sleep(2)
relay3.value(1) # to switch it on
time.sleep(1)
relay4.value(0) # to switch it off
time.sleep(1)
relay4.value(1) # to switch it on
time.sleep(2)
Can you try just this script instead?
import machine from machine import Pin relay1 = Pin(32, Pin.OUT, machine.Pin.PULL_UP) relay2 = Pin(33, Pin.OUT, machine.Pin.PULL_UP) relay3 = Pin(25, Pin.OUT, machine.Pin.PULL_UP) relay4 = Pin(26, Pin.OUT, machine.Pin.PULL_UP)
The script that you’ve posted is turning the relay on and off continuously. If you want to see the initial state of the GPIO on boot, you need just to initialize them.
By the way, are you using the normally closed or normally open connection for your relay?
Thanks!
Ok working. The relays are active low. Once I put in the value of the pin as (1) the relays stay off at boot and ran the rest of the code. Thank you for all your help.
Start your code here
import machine
from machine import Pin
import time
p32 = Pin(32, Pin.OUT)
p32.value(1)
p33 = Pin(33, Pin.OUT)
p33.value(1)
p25 = Pin(25, Pin.OUT)
p25.value(1)
p26 = Pin(26, Pin.OUT)
p26.value(1)
relay1 = Pin(32)
relay2 = Pin(33)
relay3 = Pin(25)
relay4 = Pin(26)
while True:
relay1.value(0) # to switch it off
time.sleep(2)
relay1.value(1) # to switch it on
time.sleep(2)
relay2.value(0) # to switch it off
time.sleep(3)
relay2.value(1) # to switch it on
time.sleep(2)
relay3.value(0) # to switch it off
time.sleep(2)
relay3.value(1) # to switch it on
time.sleep(1)
relay4.value(0) # to switch it off
time.sleep(2)
relay4.value(1) # to switch it on
time.sleep(1)