But I found some tips as below. I'll try these tomorrow.
There are several methods to prevent the pictured ESP8266 relay from triggering when powered:
Connect the GND pin of the relay module to the main power supply.
This will de-energize the relay coil, preventing the relay from tripping when you turn the power on. This method is simple and easy to implement, but it means the relay will always be closed. To avoid this, you need to use a separate signal to turn on the relay.
Connect a resistor and diode to the VCC pin of the relay module.
The resistor will limit current flow to the relay coil and the diode will prevent current from returning to the power supply. This will prevent the relay from tripping when you turn the power on. This method allows you to use a separate signal to turn on the relay.
Connect a transistor to the CH_PD pin of the relay module.
The transistor will be used to control current flow into the relay coil. When you turn on the power, you can trigger the relay by allowing current to flow into the transistor relay coil. However, after a while you can turn off the relay by turning off the transistor. This method allows you to use separate signals to turn the relay on and off.
Which method to use on the ESP8266 relay module pictured depends on your specific needs.
Additionally, you can take the following steps to prevent unwanted triggering of the relay:
Make sure your power supply is clean and stable.
Avoid connecting the relay module with long cables.
Use a filter circuit to protect the relay module from interference.
I hope this information helps!
Note: This information is for general information purposes only and it is recommended to consult an electrical engineer before use in any specific application.
If you would post a schematic diagram of your entire circuit, power source, relay module, lock solenoid or whatever it is, someone here would be more likely to offer help.
Ok. I will send them tomorrow too. I hope I can come up with another solution without playing with the circuit. Thank you for your intention to help. By the way, it is close to 01:00 at night here. What time is it there? I'm sorry if I disturbed you.
Try this: modify your code where the main loop is not active: Simply change the name to loopx or anything you like. Then do this, void loop (){} and see if the problem exists when powering on/off. If it solves it the problem is in your code, if not do the same thing with setup. Just add a delay(1000); and try again, if it does not resolve it you have a hardware problem and to fix it we must have a look at the Schematic and even then there is no guarantee it will be fixed.
During this be sure the power is clean. Leave the relay connected.
You're welcome. It's late afternoon here.
Put yourself in the place of those trying to help you. What information would you need to solve the problem? I think you can understand that you are not supplying enough data for anyone to help you.
A completely blank ESP? That looks like an ESP-01 module and it comes preprogrammed with some initialization firmware that runs as soon as power is applied.
Thank you for your help. I think I didn't explain the issue fully. I'm sorry to bother you. The circuit is currently working. My only concern is to prevent the relay from triggering during power fluctuations. I will try the solution shown by ZX80. Still, thank you very much.