I'm trying to get one ESP32 to trigger one relay and that relay to trigger a second ESP32.
I am able to activate the relay but it is not turning on the second ESP32. I think I'm making the wrong connections.
I connected the COM to the ESP32's GND pin and the NO to the VIN pin. Is correct?
This is the code that triggers the relay:
#include <esp_now.h>
#include <WiFi.h>
#define Rele 14
bool Estado_Do_Rele = LOW;
#include <timeObj.h>
timeObj tempoMax(15 * 1000.0);
// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
String a;
} struct_message;
// Create a struct_message called myData
struct_message myData;
// callback function that will be executed when data is received
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&myData, incomingData, sizeof(myData));
Serial.print("Bytes received: ");
Serial.println(len);
Serial.print("Dado: ");
Serial.println(myData.a);
tempoMax.start();
}
void setup() {
// Initialize Serial Monitor
Serial.begin(115200);
// Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA);
// Init ESP-NOW
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}
// Once ESPNow is successfully Init, we will register for recv CB to
// get recv packer info
esp_now_register_recv_cb(OnDataRecv);
pinMode(Rele, OUTPUT);
digitalWrite(Rele, LOW);
tempoMax.start();
}
void loop() {
if(tempoMax.ding()){
digitalWrite(Rele, HIGH);
delay(10000);
digitalWrite(Rele, LOW);
tempoMax.start();
}
}
If the code that triggers the relay works then it is not the problem. I don’t know what you mean by ‘trigger’ the second esp32. Do you mean send a signal to it or do you mean supply power to it? A relay is just a switch. You can attach your power to com and then it will go to NC until the relay is activated and then it will go to NO. If you want to power the esp32 then simply attach to the pin that accepts the power supplied (look online for how to power my esp32 for options) (vin is one) and attach the negative of your supply to the esp32 negative.
You really should provide a schematic how you have things wired together
This does not really explain what you want to do. It is unclear.
A relay does not deliver energy. If the contact is closing the electric power will be conducted from what ? to the second ESP32?
Ok. Make sure you have an appropriate power source for your esp32. Look up online, there is a 5v pin and a 3.3v. The 5v can take a wider voltage range depending on the dev board IIRC up to 12v. Set it up.
Then think about adding a switch (this is the relay). A switch is just a break in the power cable which can be opened or closed (off or on). The relay will join COM to NO when active and join COM to NC when not active. You probably want the former so join power to com and the 5v pin to NO
I have an ESP32 powered by a 5V source.
I plugged the relay into this already powered ESP32 and I would like to control the power of a second ESP32 with that relay.
My intention was that when activating the relay by the first ESP32, the second ESP32 would turn on. So I could control the power of the second WIFI, with the relay on the first ESP32. That first ESP32 would control the energy of the second.
So if you have a 5v power source you power them both the same. Red wire from 5v to vin on each board. Black wire from negative terminal to ground on both boards. Cut the red wire to board 2, attach the 5v side to COM on relay. Attach the other side to NO on relay. Job done
to make it very clear to you:
this description leaves a lot of questions open that can be easily answered by a schematic:
with which pins is the relay connected? an ESp32 has 30 pins. Which pins???
what of the relay is connected to what pins of the second ESP32??
From your questions I can conclude that you are a beginner.
But you did not tell anything how much you know about electronics
If you connected the coil of a sole relay to IO-pins. It is very likely that these IO-pins or the whole ESP32 is damaged. because ESp32-io-pins can only deliver 10 mA. Most relay-coils will pull more current => destroyed
If it is a relay-module with transistor it will work
if it is a reklay-module with optocoupler it is likely to not work
So please post links to the datasheets of the used components
The intention is just to be able to control the energy of that second ESP32.
It will keep sending a signal to the first ESP32, if it doesn't send it for 15 seconds, the ESP32 will de-energize the second and turn it on again. It's just a way to reboot for energy.
That's what I'd like to do with a relay, but as they said, I'm a real beginner and I don't know if it's possible. But this was my idea.
I'm sure that this is still not the final purpose of wanting to restart the ESP32
Are you trying to "repair" a bad coded program that makes the second ESP32 crash completely?
Do you want to switch on/off Wifi on the second ESP32?
I know you want to be able to control the energy of the second ESP32. In order for you to do that we have some things you should respond to. Take post#11 is full of good questions that should be answered. Yet here I am asking a few of the same questions again. If your response to every questions is going to be,
then we will not get very far.
If you can post a schematic of your project.
If you can post a few images of your project.
What kind of relay is being used? Such as is the relay an opto-isolated relay or is the ESP32 driving the coil power from its GPIO pin?
use google-translate. Write in detail what you want to say in your native language
then let google-translate do the translation.
The grammar won't be brilliant but the more words are 300% better to understand than a few poor english sentences
You are free to choose:
investing time by waiting for the next asking-backposting
or
investing time in writing in your motherlanguage a detailed description
and let do google-translate the translation
best regards Stefan
It's very common for an ESP to control a relay. It's very common for a relay to control power. ESP runs on power. What is your difficulty, then? Connecting your ESP would be no different than connecting a light bulb.
through a relay-module specified to work on 3.3V and knowing if it is low-active or high-active
==> post a datasheet of your relay.
trying to supply a second ESP32 through the 3.3V pin of a first ESP32 will not work
not enough power ===> post a schematic how is everything wired together.
The microcontrollerworld is not super-standardised like USB-devices.
You have to take care of more things than just "does the plug fit (mechanically) into the socket?"
you don’t know how to wire a relay (that has been explained)
you think you have a solution to a problem and have been asking how to implement it when you should be explaining the problem as your solution sounds weird
Nobody here has confidence you will not damage your esp32s because you don’t post schematics and it is obvious you have very little knowledge