• 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

esp32 power loss relay

Q&A Forum › Category: ESP32 › esp32 power loss relay
0 Vote Up Vote Down
self.raymond asked 6 years ago

I have 2 relays I am using with the esp32.  The problem I am having if the project loose power… When it reboots the relay has a dull blinking light on.  When I unplug the power to the relay they reset and back to normal. This is a big problem in my project.  Need the esp32 to reset without have to unplug power to the relay. 

7 Answers
0 Vote Up Vote Down
Rui Santos Staff answered 6 years ago

If the ESP32 looses power, when you apply power again it will automatically restart the program (you shouldn’t need to reset the board manually).
If you need to re-apply power to restar the board, it looks like your code crashed and it wasn’t a power issue…

0 Vote Up Vote Down
Rui Santos Staff answered 6 years ago

I’m also not sure, if you just want to remember the last relay states when the ESP32 restarts. Is that the case?

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

Actually I am going to try to hook it up powering the relays with another source without using the 5volt pin.  The esp8266 did not have this problem during boot. 

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

Right now I am trying to put relays into the esp32s I want to see what is the best pins just for relays.  I will be using spi and i2c in this project  The code is simple  Pin 26 is a dac pin and pin 32 is an analog pin.  With this code those pins appear to be not working. 

Start your code here
*/
int relayPin0 = 12;
int relayPin1 = 27;
int relayPin2 = 26;
int relayPin3 = 32;
 
void setup() {
	pinMode(relayPin0, OUTPUT);
	pinMode(relayPin1, OUTPUT);
	pinMode(relayPin2, OUTPUT);
	pinMode(relayPin3, OUTPUT);
	digitalWrite(relayPin0, HIGH);
	digitalWrite(relayPin1, HIGH);
	digitalWrite(relayPin2, HIGH);
	digitalWrite(relayPin3, HIGH);
}
 
void loop() {
	digitalWrite(relayPin0, LOW);
	delay(2000);
	digitalWrite(relayPin0, HIGH);
	delay(4000);
 
	digitalWrite(relayPin1, LOW);
	delay(2000);
	digitalWrite(relayPin1, HIGH);
	delay(4000);
 
	digitalWrite(relayPin2, LOW);
	delay(2000);
	digitalWrite(relayPin2, HIGH);
	delay(4000);
 
	digitalWrite(relayPin3, LOW);
	delay(2000);
	digitalWrite(relayPin3, HIGH);
	delay(4000);
}
0 Vote Up Vote Down
Rui Santos Staff answered 6 years ago

Powering the relays with an external source shouldn’t make a difference and it shouldn’t cause that issue. Those pins should also work just fine during boot…. To be honest, I’m not sure what’s missing that is causing you those issues. The code and GPIO usage seems right to me.

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

I am using Visual Micro with Visual Studio to program the ESP32.  With the same sketch as about I get the following error…  but when I run it in the Arduino IDE no errors.  Any idea??
Error compiling project sources
Debug build failed for project ‘Relays_Test’
Relays_Test_esp32.ino: 6:5: error: redefinition of ‘int relayPin0
int relayPin0 = 12
Relays_Test.ino:6: note int relayPin0 previously defined here
int relayPin0 = 12
Relays_Test_esp32.ino: 7:5: error: redefinition of ‘int relayPin1
int relayPin1 = 27
Relays_Test.ino:7: note int relayPin1 previously defined here
int relayPin1 = 27
Relays_Test_esp32.ino: In function void setup()
Relays_Test_esp32.ino: 11:6: error: redefinition of ‘void setup()

0 Vote Up Vote Down
Rui Santos Staff answered 6 years ago

I’ve never used Visual Micro, so I don’t know why that’s happening… 
Note: With Python you don’t need to define variable types, but I don’t know how Visual Micro works…

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

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

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

Copyright © 2013-2025 · 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.