• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

When rebooting turns relays on

Q&A Forum › Category: ESP32 › When rebooting turns relays on
0 Vote Up Vote Down
self.raymond asked 4 years ago

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)
6 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

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

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

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
 

0 Vote Up Vote Down
self.raymond answered 4 years ago

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)

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

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!

0 Vote Up Vote Down
self.raymond answered 4 years ago

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)

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

I’m glad it’s working.
If you need further help, you just need to ask a new question in our forum.
Thank you.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] SMART HOME with RPi, ESP32, and ESP8266 (version 1.2) March 8, 2023
  • [eBook Updated] ESP32-CAM Projects (version 1.3) January 7, 2023

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2023 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.