Hello! Complete newbie here looking for advice on this project. I have a MFRC522 reading tag IDs and controlling a 5v songle srd-05vdc-sl-c relay, but it gets stuck randomly and won't read IDs until reset. Do I need to get one of those relay boards with an opto on it, power it separately from a 5V1A supply, and add a flyback diode to make this project stable? Or is it something else? I'm sure the code isn't helping either. Open to any suggestions on how to fix this!
If you have just the bare relay, then you definitely need a flyback diode for your solenoid. The sketch also does not show your grounds tied together (from 5V and 12V)
Powering the relay 5V from the controller 5V is probably what is causing your problem.
You need a separate 5V supply for the relay module.
The controller is probably locking up because of the voltage drop as the relay operates.
Also the way you have wired the output terminals of the relay, you will be shorting the power supply when the relay is activated.
The controller you are using has an onboard LED, can I suggest you put "blink without delay" code in your code so it will flash letting you know the controller is still running?
Thanks for the replies, could I ask how to wire up the external 5v power supply to the opto-isolated relay? and also how to fix the outputs of my relay? I can't get anything to work. I attempted tying all grounds together on the input side as well, still nothing. Using one of those HL-52S dual modules.