Code not looping?

I am working on a school project and am not very familiar with coding. The idea is that we have an RFID card reader (MFRC522) and we use it to give security clearance. I found a code on this website- RFID reader tutorial The code provided works itself, however when I add a digitalWrite to pin 6 (which isn’t being used by the reader) to switch a solid-state relay that opens a door, it does not read another card until we reset the arduino or re-upload the code. (Might be un-related, but opening the serial monitor also seems to reset it aswell) If there is something I am missing that will help you understand my problem, please ask.

/*
*

*/

#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.

void setup()
{
pinMode(6, OUTPUT);
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.println(“Approximate your card to the reader…”);
Serial.println();

}
void loop()
{
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Show UID on serial monitor
Serial.print(“UID tag :”);
String content= “”;
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte < 0x10 ? " 0" : " ");
_ Serial.print(mfrc522.uid.uidByte*, HEX);_
_ content.concat(String(mfrc522.uid.uidByte < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte, HEX));
}
Serial.println();
Serial.print(“Message : “);
content.toUpperCase();
if (content.substring(1) == “BD 31 15 2B”) //change here the UID of the card/cards that you want to give access*

* {
Serial.println(“Authorized access”);
Serial.println();
digitalWrite(6, HIGH); //THIS IS THE PROBLEM*

* delay(3000);
digitalWrite(6, LOW);
}
else {
Serial.println(” Access denied”);
delay(3000);
}
}*_

Do not return from void loop().

Perehama:
Do not return from void loop().

If you are referencing these-

if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}

I have no idea what they do (I didn't write the code, only slightly modified) and if I delete them, the code doesn't read the RFID cards anymore.

I doubt it's the code though the use of String is generally discouraged. I think returning void from loop() is fine; it already does that when you hit the end of the loop anyway...

What is the solid-state relay switching and how is that powered?

Blackfin:
I doubt it's the code though the use of String is generally discouraged. I think returning void from loop() is fine; it already does that when you hit the end of the loop anyway...

What is the solid-state relay switching and how is that powered?

So when the approved card is read, pin 6 is set to high, which goes into the relay, and when it is switched it completes a 24v circuit to open a door. The circuits are completely separate however, and the 24v wont effect the arduino.

How much current does the SSR take ?

UKHeliBob:
How much current does the SSR take ?

I don't know, however it works just fine (The first time). I do know it is activated around 3v to 7v however.

If you comment out that digitalWrite(...,HIGH), you don't see the problem, correct?

Q: Do you have a snubbing diode across the relay coil terminals?

Blackfin:
If you comment out that digitalWrite(...,HIGH), you don't see the problem, correct?

Q: Do you have a snubbing diode across the relay coil terminals?

If I get rid of the digitalWrite, the code works just fine. I can scan as many cards and it will say "approved" or "denied." The problem is when the digitalWrite is there, once I scan one card, it wont scan anymore and it needs to reset. We have tried the reset pin, but I don't know how that works.

I am not familiar with what a snubbing diode is, but the relay does have an LED that is on when the relay is switched.

rexleyme:
If I get rid of the digitalWrite, the code works just fine. I can scan as many cards and it will say "approved" or "denied." The problem is when the digitalWrite is there, once I scan one card, it wont scan anymore and it needs to reset. We have tried the reset pin, but I don't know how that works.

I am not familiar with what a snubbing diode is, but the relay does have an LED that is on when the relay is switched.

A few thoughts:

  1. A snubbing diode is used to tame the inductive kick a relay coil can produce when it is de-energized. Without it, large voltage spikes can occur that can damage the coil-drive circuit.
https://www.azatrax.com/image/CoilDiode.png[/code

There are a few ways to snub the spike; the above diagram is not the best but it's better than nothing.

2) How close physically is the relay to the Arduino and to the equipment being switched? Is there wiring bundled together powering both? Proximity and/or inductive coupling can allow things like an arc when a relay makes/breaks to generate enough RFI to screw up sensitive electronics. If sensitive wires are running closely large currents in the load wiring can produce fields that couple into the sensitive wiring, screwing it up.

Is sounds like you have one or more of these issues as well as a power-integrity problem.

Is a snubber required on an SSR?

when it is switched it completes a 24v circuit

AC or DC?

Thanks for all the help. I am going to try and make a snubbing diode for the relay and maybe that will work. If there is anything else I can try I am always open to suggestion and will definitely try it.

Also, if there is a simple way to set a snubbing diode up, I'd highly appreciate a quick write up on that.

You stated you are using a solid state relay. No snubber (flyback diode) required as there is no coil to generate a kickback voltage as the magnetic field collapses.

Although I misread; thought the SSR was switching a larger relay (my bad), the operation of the door lock is still in question for me. If it's a solenoid, for example, it may as well be a big relay even though it's removed 1-device from the Arduino...

OP, can you show the schematic? Can you disconnect the load-side of the SSR and see if it's okay then? Perhaps put a lesser load in its place (coil of a small relay, for example) and see how it is then?

Blackfin:
Although I misread; thought the SSR was switching a larger relay (my bad), the operation of the door lock is still in question for me. If it's a solenoid, for example, it may as well be a big relay even though it's removed 1-device from the Arduino...

OP, can you show the schematic? Can you disconnect the load-side of the SSR and see if it's okay then? Perhaps put a lesser load in its place (coil of a small relay, for example) and see how it is then?

The SSR switches an input signal on a completely separate controller (nanoline controller by Phoenix contact) which only accepts voltages of 12-24v. That is why we need the relay, as it doesn't read the smaller voltage from the arduino. So basically the relay is just a step-up.

I will definitely try disconnecting the load side of the SSR and see if that changes anything. However I cannot do it until tomorrow, as it is a school project and everything is there.

Update: So when I disconnect the load, the code works just fine. The led on the relay turns on and I can scan as many cards as I want. So is it something past the relay? I don't know how something past a relay could effect the arduino, but I'm really not that experienced with arduinos or anything for that matter.

Can you post the specs of the SSR?

evanmars:
Can you post the specs of the SSR?

I don't know exactly what specs you need, but this is the website where we got it.
https://www.phoenixcontact.com/online/portal/us?uri=pxc-oc-itemdetail:pid=2900375&library=usen&tab=1