ESP32 crash with simple program

Hi all,

I’m new on this forum, but not with electronic and microcontrollers.
I usually solve my problem on my own, but this time i need help

I’m working on a simple project of plant watering.
My ESP32 controls a 3.3V relay that is driving a small 230V pump.

The problem is that the ESP sometimes crashes when driving off the relay.
This problem only comes when the power stage of the relay is connected to 230VAC and the pump
When the project is running without the pump, there is no problem. The relay works fine
When the problem happened, my debug console is showing a lot of incomprehensible characters. See attachement
Never see that before…

I checked the output current of the ESP’s output pin : 0.54mA (i think its ok)
I checked all my wiring. You can find it in attachement.
For the test, i created a small program that is driving on and off the relay alternatively by 5s. Even with this small program, the problem is happening. Here is the code :

#define RLY 14

void setup() {
  Serial.begin(9600);
  pinMode(RLY, OUTPUT);
  digitalWrite(RLY, LOW);
}

void loop() {
  digitalWrite(RLY, HIGH);
  Serial.println("rly ON");
  delay(5000);
  digitalWrite(RLY, LOW);
  Serial.println("rly OFF");
  delay(5000);
}

Anyone knows this kind of error ?
Do i have wiring problem or electrical issue ?

Thanks in advance for your help

Does it happen when the pump turns on/off?

Try a snubber circuit across the relay contacts.
Leo…

When the project is running without the pump, there is no problem. The relay works fine
When the problem happened, my debug console is showing a lot of incomprehensible characters. See attachement
Never see that before...

I didn't check but probably just data send at the debug baud-rate.

Do i have wiring problem or electrical issue ?

You must have if the pump's presence is the cause. What kind of 5v Power Supply are you using ? Seeing that the relay appears to be of the opto-coupler driven kind (given the 3 lines, one of which for control) that can hardly be the issue, although the relay still draws considerable current on the 3.3v rail. It would appear as if the 5v power supply has a temporari difficulty to supply the required current the moment that the pump turns on. I would add a fair size (100uF) Capacitor on the 5v Rail, and also another smaller one (10uF) on the 3.3v rail.
Pumps can draw a lot of current, though normally speaking AC-mains should not be very sensitive to those kind of things, so it is a bit of an anomaly. Does it still happen when the pump is connected to a power socket a few meters away from the the power supply ? Other possibility is interference, how far away from the pump did you put the ESP ?

Thanks for your replies

Wawa,
It happens only when the pump turns off
I will try a snubber circuit, i keep you informed
PS : I also tried with a rollback diode

Deva_Rishi,

I didn't check but probably just data send at the debug baud-rate.

I tried all the available baud-rate. No result.

What kind of 5v Power Supply are you using ?

I'm using a simple 5V/1A smartphone power supply that i disassemble to put it into my case (next to the ESP)

It would appear as if the 5v power supply has a temporari difficulty to supply the required current the moment that the pump turns on

I forgot to precise that the problem only happens when the pump turns off
And like i said, the driving pin of the relay only takes 0.54mA. I measured that with an ammeter. Do you think that a current peak (that i couldnt see on the ammeter) of more than 12mA (max current output of the ESP) would happen ?

Does it still happen when the pump is connected to a power socket a few meters away from the the power supply ? Other possibility is interference, how far away from the pump did you put the ESP ?

I didn't try to move the pump away of the case that containing the electronic parts (power supply, ESP, relay). Actually the pump is about 15cm away. I will try that. I keep you informed
PS: it's a very small aquarium pump 230V/3W

PS : I also tried with a rollback diode

On the pump ? it's AC isn't it ?

Do you think that a current peak (that i couldnt see on the ammeter) of more than 12mA (max current output of the ESP) would happen ?

No, but what happens on the 3.3v Rail when the relay turns off is a possible cause, and the relay itself probably draws something in the order or 60mA, the onboard capacitor if the nodeMCU may not be big enough to provide momentary peak requirements, and actually the 3.3v regulator might not provide enough power for the relay (probably does though)
Can you specify the exact type of relay ? could you power the relay with 5v instead ? (3.3v logic should be fine to drive it) is there a fly-bakc diode on the relay ? (many opto-coupler driven relay units don't have one)

Actually the pump is about 15cm away

That is probably far enough away, the nodeMCU is pretty well shielded.
I am still puzzled by the problem only occurring when the pump is connected. turning it off might cause a power surge, but you powersupply should not be sensitive to that. Anyway try swapping the AC-pins of the powersupply. (if there is only 1 capacitor in the supply, it should be on the same pin as AC-line of the pump that does not get disconnected)

Happens when the pump is switched off by the relay? Or when the pump turns off regardless?

If it happens when the pump is switched by the relay I would have thought it's back EMF up the 3.3v line. Put your diode cathode to + and anode to -, closer to the relay board is better. Alternatively try a separate supply for your relay

Deva_Rishi,

On the pump ? it's AC isn't it ?

I put a fly-back diode between IN and GND on the relay. But after a few reflexion, i saw that there is already a diode on the little PCB of the relay.
And yes it's a AC pump (230V/3W)

Can you specify the exact type of relay ?

Here is the link where i bought it : relay 3v3 aliexpress

could you power the relay with 5v instead ?

Before insterting it into my project, i made some test. I can't powering it with 5V...

is there a fly-bakc diode on the relay ?

I can see a small diode on the PCB so i think that it is the fly-back diode

try swapping the AC-pins of the powersupply

I tried that, but no result

trojanhawrs,

Happens when the pump is switched off by the relay? Or when the pump turns off regardless?

Yes, it happens when the pump is switched off by the relay

Put your diode cathode to + and anode to -

I have already tried that :confused:
I don't think that the problem comes from the 3v3 side

Alternatively try a separate supply for your relay

I tried that and i have some good results. Just 1 crash of the ESP in 15min of test I powered the pump across the relay from a wall plug next to the 5v power supply's wall plug. This way, there is approximatively 3.5m of cable between the pump and the 5v power supply.
I'm now sure that the problem comes from here. I put an oscilloscope on the 5V rail, just after the power supply. And I see some peaks when the relay cut off the AC power. See this in attachement
You can see a AC parasites of more than 10V peak-to-peak !!! The pump's coils resist against the loss of current and create these parasites

So now, what can I do ?
I already tried to put a capacitor (1500uF/6.3V) on the 5v rail, but no result
Maybe I could change the power supply by another one of better quality ?
I could also change the AC pump by another one of 5VDC. I used this AC pump because I already had it.
Do you see another solution ? more electronic than mine ?

Forgot the attachement :-\

Try powering the relay with a pair of AA batteries in series (3V) instead of the 3V3 pin of the Arduino. If you can turn the pump off and on with the relay powered separately, then you have narrowed down the cause.

Why can't you use a 5V relay module?

SteveMann,

Try powering the relay with a pair of AA batteries in series (3V) instead of the 3V3 pin of the Arduino

It’s a good idea, this way i could definitely be sure that the 3v3 part is not the cause. I will try that

Why can’t you use a 5V relay module?

Because of the 3v3 output of the ESP that cannot drive a 5v relay

Thanks for your help

Powering a 3.3volt relay module (~150mA) from the 3.3volt supply is a really bad idea.
The 3.3volt regulator, and it's heatsink area, is not designed to do this.
Should have seen that with my first reply.

Get a 5volt relay module, and power it from the 5volt/raw/V-in/USB pin of the ESP32 module.

And what is that ADC block for the moisture sensor.
Shouldn't that be powered from the 3.3volt pin.
Bad idea to connect 5volt logic to an ESP32 I/O.
Leo..

I already tried to put a capacitor (1500uF/6.3V) on the 5v rail, but no result
Maybe I could change the power supply by another one of better quality ?

That would be a good idea, do you see upward spikes on the 5v rail when you turn the pump off, in that case how about just an extra zener diode ?. and maybe a choking coil on the GND.

Here is the link where i bought it

Ah well, those are not Opt-coupler driven, but transistor driven. Yes it does have a fly-back diode, but i would expect it to draw a considerable amount of current, and although the nodeMCU probably can power it

The 3.3volt regulator, and it's heatsink area, is not designed to do this.

the regulator can take up to 600mA and the heatsink of a nodeMCU is considerable, still i would prefer to power the relay separately using a 3.3v TO-220 package regulator would do, and i would for sure add an extra capacitor on the 3.3v rail

I already tried to put a capacitor (1500uF/6.3V) on the 5v rail, but no result

then just a 100uF on the 3.3v rail, and try to give a bit more room on the voltage rating, 20% is not a lot.

Because of the 3v3 output of the ESP that cannot drive a 5v relay

That is not true ! even the transistor driven relays can be used with lower voltage logic (in fact more so than the opto-coupler driven ones because the value of the current limiting resistor is less relevant, and won't need modification)
Anyway, if there are 5v spikes that does clarify the issue for me, the nodMCu's onboard regulator will have to dissipate more heat at higher input voltages, and you are probably already stretching it to it's limits, and the crashes are caused by the overheat protection of the regulator kicking in.
I'd say, the best and cheapest solution would be a separate 3.3v regulator (TO-220) that gets' it's power from the 5v power supply with another capacitor. Or just get a 5v relay (you may even be able to run the 3.3v one of 5v if you add a small value high wattage resistor in line with vcc, for that you would need to measure it's resistance and do some calculating)