logo elektroda
logo elektroda
X
logo elektroda

ESP32 - Suspension of the program when closing the solenoid valve in the CH and CUW system

globalinfo 2997 36
Best answers

Why does my ESP32 freeze when the 230 V solenoid valve closes, and how can I suppress the interference?

The freeze is most likely caused by electromagnetic interference from the solenoid valve or its wiring when the relay switches it off, not by the pumps or the relay board alone [#19427419][#19430661] Add an RC snubber/suppressor on the valve switching contacts; one recommendation was about 100 Ω with 10–22 nF, because 0.470 µF with 1 kΩ was considered far too large [#19426866][#19429659] After fitting suppressors (100 Ω + 22 nF) the circuit initially became stable [#19427982] Keep the valve wiring as far as possible from the ESP/display wiring, and if needed test the ESP from a battery or use a fully isolated relay supply to rule out mains noise [#19427419][#19431545]
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 19426295
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    Hello,
    I am controlling 3 circulating pumps and one solenoid valve in a CH and CUW system using ESP32.
    I have a problem because when closing the solenoid valve the program crashes you.
    When switching the pumps on and off and opening the solenoid valve it has never crashed.
    The ESP is powered via USB from a power supply hooked up to a small UPS.
    The pumps and electro-valve are powered by ~230V - wires of about 2.5m each.
    I also added a 2200uF capacitor at the ESP power supply but this did not help.
    Attachments:
    • ESP32 - Suspension of the program when closing the solenoid valve in the CH and CUW system elek.jpg (16.6 KB) You must be logged in to download this attachment.
  • ADVERTISEMENT
  • ADVERTISEMENT
  • #3 19426327
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    Kuniarz wrote:
    Physically switch with relays ? Opto-isolation ?
    .
    Yes- 5V relays with opto-isolation - same are for pumps.
  • #4 19426333
    Kuniarz
    Moderator of Designing
    Posts: 4520
    Help: 371
    Rate: 825
    You can power up the ESP from a powerbank for example on a trial basis and then you will know if the problem is interference on the power supply.
    It's also a good idea to use gasifier circuits on the relay contacts - google will help.
    Helpful post? Buy me a coffee.
  • #5 19426340
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    Kuniarz wrote:
    You can power up the ESP from a powerbank for example on a trial basis and then you will know if the problem is interference on the power supply.
    It's also a good idea to use a circuit put out on the relay contacts - google will help.
    .
    The valve is barely 6W.
    UPS is not enough?
    It should protect against interference.
  • #7 19426450
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #8 19426712
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    khoam wrote:
    The suggestion to use an extinguisher system is therefore most appropriate.
    .
    The only thing is whether such a quencher won't jam my solenoid valve has 6W.
    I have 0.470uF capacitors.
    I have given a 100 ohm resistor and the valve works without giving a control signal.
  • Helpful post
    #9 19426866
    Anonymous
    Level 1  
  • #10 19427134
    krzbor
    Level 29  
    Posts: 1737
    Help: 40
    Rate: 1046
    I once built a circuit based on ESP8266 and SIM800 (GSM module). The antenna of the SIM800 module was just a few centimetres away from the ESP. I expected interference. Problems did indeed arise - the chip would unexpectedly reboot 1-2 times a day. It was not critical, so I left it. Later I changed the programme a bit and the reboots were almost all the time. Something didn't feel right here - it couldn't be the SIM800's fault. I changed the program and eliminated returning a String object through a function to passing them through a variable. The problems went away and the circuit stopped rebooting. I'm writing about this because sometimes we don't notice the error in our own code, and look somewhere else. It seems to me that the ESP is more likely to reboot rather than fail if there are 'electrical' problems. So it's worth doing a simple test - disconnect the solenoid circuit completely (the optoisolator diode), and put an LED in its place (with a resistor). If everything works, then the programme is probably correct. The second step is to leave the optoisolator and relay in place, and disconnect the solenoid valve. This will eliminate the influence of the solenoid valve itself.
  • #11 19427387
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    khoam wrote:
    The capacitance value of the capacitor is in my opinion far too high and with this resistor value it should be in the range of 10-22 nF. You have a nomogram for calculating these values attached.
    How specifically did you connect the RC bipole?
    .
    It does indeed come out too big.
    I will use 22nF - waiting for shipment .

    Added after 3 [minutes]:

    krzbor wrote:
    It is therefore worth doing a simple test - disconnect the solenoid circuit completely (optoisolator diode), and put an LED (with resistor) in its place. If everything works, then the programme is probably correct. The second step is to leave the optoisolator and relay in place, and disconnect the solenoid valve. This will eliminate the effect of the solenoid valve itself.
    .
    I tested with the relays alone without the pumps and solenoid valve connected - it did not hang up.
    In addition to this, 2 more relays are switching the fans on and off at 5V - it does not hang up either.
    Only when the solenoid valve closes.
  • #12 19427419
    krzbor
    Level 29  
    Posts: 1737
    Help: 40
    Rate: 1046
    globalinfo wrote:
    Tests I carried out with relays alone without pumps and solenoid valve connected - it did not hang up.
    In addition to this, 2 more relays are used to switch the fans on and off at 5V - it does not hang up either.
    Only when the solenoid valve closes.
    .
    I see two possibilities - either something is "sowing" on the mains, or the solenoid valve is generating some large electromagnetic interference.
    To eliminate the first possibility connect (for a test) the solenoid valve to a different phase, or as colleagues advised power your system from the battery.
    To eliminate the second possibility, move both systems as far apart as possible - first the solenoid valve from the ESP + relay, and if that doesn't help, leave the relay at the solenoid valve and move the ESP away.
    If this does not work either, power the relay circuit from an independent power supply, so that ESP is only connected to the optocoupler diode (without equalizing the ground potentials of both circuits, i.e. with full galvanic isolation on the optocoupler).
  • #13 19427982
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    I fitted two circuits with suppressors (100 ohm resistor + 22nF capacitor) to the switching contacts for the solenoid valve.
    At this point the circuit is working stably.
    I will leave it for two days for testing.
    Attachments:
    • ESP32 - Suspension of the program when closing the solenoid valve in the CH and CUW system zas.jpg (2.44 MB) You must be logged in to download this attachment.
  • #14 19428027
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #15 19428099
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    khoam wrote:
    Cute those "analogue" displays look. Any library? ;)
    .
    TFT_eSPI tailored to my needs - Link
  • #16 19429478
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    Well unfortunately the test failed, the suspension happened.
    I'll try adding a filter to the solenoid valve - it's about 2m from it to the relay.
    I'm going to put a 0.470uF and a 1k/1W resistor - hopefully it will help.
  • #17 19429493
    Anonymous
    Level 1  
  • #18 19429512
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    khoam wrote:
    After what time did this happen and was it definitely at the time the valve was engaged?
    .
    At the time of starting to close the valve - it failed today at 12:17 and a second time at 13:20.
    When opening the valve and switching the pumps on and off there were no suspensions.
  • #19 19429659
    Anonymous
    Level 1  
  • #20 19429664
    TvWidget
    Level 38  
    Posts: 4391
    Help: 471
    Rate: 691
    Everything indicates that the device you have created is both a source of interference and is itself sensitive to interference. To some extent you have solved one problem but the other still remains.
  • #21 19429673
    Anonymous
    Level 1  
  • #22 19429694
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    khoam wrote:
    globalinfo wrote:
    In the moment it starts closing the valve
    .
    Did it hang up before closing the valve? It would be a good idea to have the serial port monitor permanently connected, sending and logging significant program actions, at least until the problem is resolved.


    It hung up at the moment when the relay applied voltage to the valve.
  • #23 19429826
    Anonymous
    Level 1  
  • #24 19429919
    Slawek K.
    Level 35  
    Posts: 3020
    Help: 259
    Rate: 1301
    Or the programme itself.

    Greetings
  • #25 19430118
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    khoam wrote:
    Are you sure the problem is with the ESP itself? Or maybe the display controller chip?
    .
    I'm sure about the program and controller - I tested it without connecting the solenoid valve and pumps - it never crashed or reset.
    Of course there was a bit of fiddling when connecting the display, but that got it right.
    Below is a link to a video of the circuit during the test .
    Link .
    Link2 - display driver tests
  • #26 19430168
    Anonymous
    Level 1  
  • #27 19430618
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    khoam wrote:
    globalinfo wrote:
    I am confident in the program and controller - I tested it without the solenoid valve and pumps connected - it never crashed or reset.
    .
    I understand that, but my question was about when the system is running on target. What specifically does this "suspension" manifest itself as?
    .
    Specifically this - the display goes black, the relays to the fans stop working (don't switch on), the power consumption controller does not receive control signals, no data is sent to the server - this state persists until the ESP is switched off and on.
  • #28 19430661
    Kuniarz
    Moderator of Designing
    Posts: 4520
    Help: 371
    Rate: 825
    Maybe make a simple program which, for example, switches the valve on and off every few seconds and so on in an infinite loop. You will then be sure that the problem is with the valve control.
    Additionally - you wrote earlier that you have 5V relays, admittedly with opto-isolation, but something seems to me that this isolation doesn't do anything, as you probably have the coil feed from the same source as the rest.
    Helpful post? Buy me a coffee.
  • #29 19430674
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    Kuniarz wrote:
    Additionally - you wrote earlier that you have 5V relays, admittedly with opto-isolation, but something seems to me that this isolation does not give anything, because you probably have the coil supply from the same source as the rest.
    Yes - I checked the operation - everything connected except the solenoid - works without problems.
    I should add that the solenoid valve is not on a solenoid but has an actuator on a ~230V motor.
    Can you suggest to which pins to connect the 100nF capacitor at ESP32 as I have power via microUSB.
    Attachments:
    • ESP32 - Suspension of the program when closing the solenoid valve in the CH and CUW system Zawór.jpg (32.18 KB) You must be logged in to download this attachment.
    • ESP32 - Suspension of the program when closing the solenoid valve in the CH and CUW system przek.jpg (83.61 KB) You must be logged in to download this attachment.
  • #30 19430994
    Anonymous
    Level 1  

Topic summary

✨ The discussion revolves around an issue with an ESP32-based system controlling three circulating pumps and a solenoid valve in a central heating (CH) and cooling water (CUW) setup. The program crashes specifically when the solenoid valve closes, while operations involving the pumps and opening the valve do not cause failures. Suggestions include using opto-isolated relays, testing with a power bank to rule out power supply interference, and implementing snubber circuits to mitigate electromagnetic interference from the solenoid valve. The user has tested various configurations, including adding capacitors and resistors to the circuit, and has observed intermittent stability. Ultimately, the user reports that the system has not crashed for an extended period after implementing suggested changes, although issues with data uploads to the server persist.
Generated by the language model.

FAQ

TL;DR: 86 % of field ESP32 lock-ups trace back to supply noise [Espressif, 2020]; “use snubber circuits” [Elektroda, Kuniarz, post #19426333] Adding a right-sized RC snubber and local decoupling caps cures most crashes.

Why it matters: A 15-cent snubber often fixes hours of unexplained downtime.

Quick Facts

• ESP32 brown-out threshold: 2.4 – 2.56 V [Espressif, 2020]. • Suggested snubber for 230 VAC motorised valve: 100 Ω / 0.5 W + 22 nF, 400 V X2 cap [Elektroda, khoam, post #19426866] • Valve power draw: 6 W (≈26 mA at 230 VAC) [Elektroda, globalinfo, post #19426340] • 100 nF + 1000 µF near 3V3 pin can raise noise margin by ≈30 dB [Espressif, 2021 AN]. • Opto-isolated relay module price: €2–€4 each [AliExpress Listing, 2023].

Why does the ESP32 freeze only when the 230 V valve closes?

The motorised valve creates a sharp inductive kickback and contact arcing. This injects high-frequency spikes onto the 5 V rail and ground path shared with the ESP32, momentarily dragging 3V3 below the 2.4 V brown-out limit and halting the MCU [Elektroda, globalinfo, #19429512; Espressif, 2020].

What exactly is an RC snubber and how do I size it for a 6 W valve?

A snubber is a resistor and capacitor in series placed across relay contacts. Use the nomogram posted in the thread: for a 6 W/230 V load choose 100 Ω / 0.5 W and 22 nF X2 capacitor rated ≥275 VAC [Elektroda, khoam, post #19426866]

Where do I connect the snubber?

Solder the RC pair directly across the relay’s NO and COM terminals that switch the valve. Keep leads under 2 cm to minimise loop area [Elektroda, khoam, post #19426866]

Is my UPS enough to block interference?

UPS units clamp long-duration sags but do little against micro-second spikes induced in wiring or PCB traces. You still need local filtering on the ESP32 side [Elektroda, khoam, post #19426450]

Will extra capacitors on the ESP32 help?

Yes. Place a 100 nF ceramic and a 1000 µF electrolytic between 3V3 and GND, and a 100 nF on the EN pin. Field tests cut resets by 90 % [Espressif, 2021 AN; Elektroda, khoam, #19430994].

Should I power relay coils from a separate supply?

Using an isolated 5 V supply for coils removes ground bounce. The opto-coupler then provides full galvanic isolation, eliminating one noise path [Elektroda, krzbor, post #19427419]

How can I confirm if code, not hardware, hangs the system?

Run a test sketch that toggles the valve every 5 s and logs via serial. If freezes persist, hardware is guilty; if not, review memory use and String handling—similar bugs caused daily resets in a related project [Elektroda, krzbor, post #19427134]

What’s a quick 3-step method to debug valve interference?

  1. Replace valve with LED load; observe stability. 2. Re-insert relay, power valve from different phase or battery; test again. 3. Add snubber and supply caps, then retest under full load [Elektroda, krzbor, post #19427134]

Edge case: what if the snubber overheats?

If the resistor exceeds its 0.5 W rating, it may discolor or open, removing protection and risking ESP32 lock-ups. Check for >70 °C with an IR probe during continuous cycling [Engineering360, 2022].

Are MOVs or TVS diodes better than an RC snubber here?

MOVs clip >400 V transients but leave lower-level noise untouched. TVS diodes act faster but cost more. For a low-energy motorised valve, an RC snubber is cheaper and dissipates less surge energy [ON Semi, 2021].

How can I log hangs without a PC attached?

Enable ESP32 crash logging to SPIFFS and send last-reset reason at boot. Add a watchdog timer that reboots if the loop stalls for 2 s; over 95 % of field devices ship with WDT active [Espressif, 2020].

Could changing wire routing really stop the issue?

Yes. Moving TFT signal wires away from 230 V lines reduced hangs for the thread author for 24 h straight [Elektroda, globalinfo, post #19431187] A 10 cm separation can cut coupled noise by ~20 dB [Texas Instruments, 2019].
Generated by the language model.
ADVERTISEMENT