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.
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…
I’m also not sure, if you just want to remember the last relay states when the ESP32 restarts. Is that the case?
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.
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); }
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.
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()