Relay module problem with 220v lamp

Hi everyone,

I'm quite a beginner in Arduino and English. I want to light a lamp plug in 220V thanks to a relay and RFID technology.

When i use the good TAG, the arduino light the greend LED and activate the relay and when it's not, it lights only red LED.

It works here without any problem BUT.... when i connect the lamp to the 220V, the relay works one or two times with the good tag and suddenly.... nothing... like the tag is not recognized anymore by the MRFC522. Like the arduino is not doing anything. If i unplug the 220v, it works again (after i reset the arduino)

I didn't put a freewheeling diode for the relay. Do you have any idea

I used this code :

#include <SPI.h>
#include <MFRC522.h>
// ecrire ici le numero UID du bon badge
const byte bonUID[4] = {194, 74, 182, 115};
const int pinLEDVerte = 7; // LED verte
const int pinLEDRouge = 6; // LED rouge
const int buzzer = 3; // buzzer
const int relais = 4; // relais
const int pinRST = 9; // pin RST du module RC522
const int pinSDA = 10; // pin SDA du module RC522
MFRC522 rfid(pinSDA, pinRST);
void setup()
pinMode(pinLEDVerte, OUTPUT);
pinMode(pinLEDRouge, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(relais, OUTPUT);
void loop()
int refus = 0; // quand cette variable n'est pas nulle, c'est que le code est refusé
if (rfid.PICC_IsNewCardPresent()) // on a dédecté un tag
if (rfid.PICC_ReadCardSerial()) // on a lu avec succès son contenu
for (byte i = 0; i < rfid.uid.size; i++) // comparaison avec le bon UID
if (rfid.uid.uidByte[i] != bonUID[i]) {
if (refus == 0) // UID accepté
// allume LED verte et active relais pendant 3 secondes
digitalWrite(pinLEDVerte, HIGH);
digitalWrite(relais, HIGH);
digitalWrite(pinLEDVerte, LOW);
digitalWrite(relais, LOW);
else { // UID refusé
// allume LED rouge et active buzzer pendant 3 secondes
digitalWrite(pinLEDRouge, HIGH);
digitalWrite(buzzer, HIGH);
digitalWrite(pinLEDRouge, LOW);
digitalWrite(buzzer, LOW);

Hi @btek80 ,
maybe you are having an electrical noise problem perhaps caused by the relay contacts.
What type of lamp are you using?
If it is modern LED type lamps, they are inductive circuits and usually generate electrical noise when switching on and off.

Place a RC snubber on the relay contacts. Should solve.

RV mineirin

I expect that @ruilviana has nailed it for you, but you could add some serial printing to your code to see whether it has crashed.

HI @ruilviana ! Thanks a lot for your quick answer. I'm exactly using a LED type lamp (the first i found in my house in fact : LEXMAN 230V 9W 70mA)

So, either i put a snubber or i can change the type of lamp ? (like the older one)

When there is the electrical noise, it freezes the arduino ?

What's the difference between snubber and freewheeling/flyback diode ?

Thank you very much

I'm not sure I understand correctly, but is the diode you are referring to in parallel with the coil of the relay?
If so, this diode is intended to protect either the Driver or the transistor that operates the relay.
You can test without the snubber using only glow lamps.

I suggest you post a schematic of your project. Can be drawn freehand.

RV mineirin

The lamp type may indeed be problematic, but it's not an either or fix - you need to snub the relay coil regardless.

I'm not sure I understand correctly, but is the diode you are referring to in parallel with the coil of the relay? => Yes, it is

I post you the schematic

like this ?

Look snubber

good idea

i should use it for each step to see where it crashes ?

ok :slight_smile: thank you i'll try that so it's on the 220v circuit

To start with, no. Just something in loop to give you a clue that it has stopped. You can add stuff later if you need to narrow it down.

However, I think you need a snubber diode on the side of the relay where your Arduino powers the coil. I would expect that to be where your problems come from. It may be too, that the Arduino can't adequately power the relay coil.

"2RT relais" is written inside the relay block, which points to a bare 5volt relay.

An Arduino pin can't drive a bare relay directly.
Must use a drive transistor with base resistor and kickback diode.
Or a relay module with those parts already included.

Yes, switching a LED lamp without snubber circuit could weld the relay contacts eventually together.

The snubber on the 220V side does not make a lot of sense a relay is a galvanic separation between the low voltage circuit (arduino circuit) and the "high" voltage circuit, i assume 220V AC and not DC as indicated in the drawing.
Given the power consumption of the 7w lamp, it is most unlikely that the 220V causes a problem.
Then regarding the other side. The way to go as indicated in previous posts, is, you disconnect the relay and the buzzer and try to reproduce the problem.
Most likely you will not have a problem.
Then it is up to you to test with the relay and the buzzer. Indeed the relay will probably be the cause of the problem. Indeed there are relays that have a kind of fet, transistor or opto coupler that can be used as amplifier for the arduino output to drive the current of the coil. It is very well possible that the relay you are using has this kind of circuit.
Then, if you have a relay with an optocoupler, then there are 2 possiblilities to feed the cricuit between the opto coupler and the relay coil: or via the Arduino power supply or via a separate power supply. Many of these relay with optocoupler circuits have a jumper that you can remove and through wich you can apply a separate voltage supply. Then you have the following chain:
5V Arduino Output [Arduino supply] -> optocoupler input.
optocoupler output [separate 5V DC supply] -> relay input.
relay output [220V supply] -> lamp.
If you need a free running diode it will be in the cricuit feeding the relay coil and not on the 220V side.
Best regards,

I know.
But there were many similar threads in the past that were solved with a snubber circuit.

Why would OP write 2RT in the relay block.
Most relay modules use a blue sugar-cube relay, not a 2RT relay.

you're right, "2RT relais" is false, i'm using a "module"... Sorry for my mistake. The relay is plug on the 5V arduino and the pin 4 goes to "IN1"

In my module, is there already a snubber ?

If i use the LED lamp, i need a snubber on this part of the circuit ????

Thank you for answering.

It works perfectly if i don't plug the 220V lamp.

When i plug it, it'll work like 3 or 4 times and then.... nothing

It looks like you have optoisolation and snubber diodes on the input side. That's good, but you may have sabotaged the whole thing by powering it from the Arduino. Better to have a 5V power supply for the relay coils that isn't the Arduino and remove the jumper.

I don't know why you would need any snubbing on the lamp side, but I'm no expert.

Hi @btek80 ,
Look, this is the schematic of your relay module.
It already has the protect, ("flyback"), diode but no snubber.

RV mineirin


oh ok, i'll try that,
still dont know how tu use the jumper....

there are 3 pins "JDD-VCC" "VCC" "GND"
with swith on JDD-VCC+VCC

if i want to use an external supply, i should remove the switch and connect VCC + GND ? what does JD means ?