Arduino hangs when connecting 220v to relay board

Hi. I'm having a problem with a relay that controls a light bulb that is connected to 220v.
I have everything connected like this:

Relay switches every 2 seconds on/off. It works fine if the light bulb isn't connected to 220v, if I plug the light bulb in, then it works for a couple of seconds ant then the whole thing freezes. As far as I understand the problem is that the on/off switching generates some kind of interfering current?

In future I will replace the light bulb with a solenoid valve and I thing the problem will be even worse with it.
Can I solder in a diode from relay to light bulb to make sure no current can flow back to the relay? I found some forum posts about similar problems, but I still cant figure it out.

A little help would be much appreciated.

try connecting the relay to 5volt .....not 3.3volt :slight_smile:

The relay is connected to 5v, the drawing above is just for illustrative purposes.

—- If it’s a 3.3V relay module...
Where’s the rest of your schematic... power supply?

lastchancename:
Where’s the rest of your schematic… power supply?

Arduino get powered by a 9V DC PSU. Thats it.

the drawing above is just for illustrative purposes.
:::
Relay switches every 2 seconds on/off. It works fine if the light bulb isn’t connected to 220v, if I plug the light bulb in, then it works for a couple of seconds ant then the whole thing freezes.

So it does only one thing… on or off ?
I think it’s time to see what else is going on.
Full schematic, and code.

It can't be the code. It works fine if the lamp is not connected to the wall power outlet.

The relay switches on/off for 5h without any problem. As soon as I plug in the lamp in the wall it works for 5 - 30 seconds (sometimes less, sometimes longer) and then everything freezes.

What freezes ? Put some Serial.print statements in your code when it switches the relay to see if it is the Arduino. It can “freeze” and leave the light on or off or both ?
Your relay module is like the one illustrated with an inbuilt led?

  1. The cheap 9volt power supply is not immune to mains power hash (try a 5volt cellphone charger connected to the USB socket)

or

  1. The incandescent lightbulb is only there for "illustrative purposes", but is really a complex load,
    like a CFL or LED lightbulb that needs a snubber circuit (a solenoid/valve definately needs one).
    Leo..

Wawa:

  1. The cheap 9volt power supply is not immune to mains power hash (try a 5volt cellphone charger connected to the USB socket)

or

  1. The incandescent lightbulb is only there for “illustrative purposes”, but is really a complex load,
    like a CFL or LED lightbulb that needs a snubber circuit (a solenoid/valve definately needs one).
    Leo…

Yes, for now it is a LED light. In future it will be a solenoid valve. What is a snubber circuit?

st3:
What is a snubber circuit?

Google can tell you.

Did you try with an incandescent lightbulb?
Leo..

6v6gt:
What freezes ? Put some Serial.print statements in your code when it switches the relay to see if it is the Arduino. It can “freeze” and leave the light on or off or both ?
Your relay module is like the one illustrated with an inbuilt led?

I have serial outputs. It seams like the whole Arduino freezes.

Wawa:
Did you try with an incandescent lightbulb?
Leo..

No, I didn't.

How about powering the Arduino from the PC/laptop, without that external 9volt supply.
The extra current draw of one relay module (~75mA) should be ok.

Or powering the setup with the cellphone charger I mentioned before.

This is simple fault finding stuff.
Can't (shouldn't) fix something if you don't know what's causing it.
Leo..

Wawa:
How about powering the Arduino from the PC/laptop, without that external 9volt supply.
The extra current draw of one relay module (~75mA) should be ok.

Or powering the setup with the cellphone charger I mentioned before.

This is simple fault finding stuff.
Can't (shouldn't) fix something if you don't know what's causing it.
Leo..

Ok, I will try this later. Thx!