I’m nearly done with my RFID gate control. I’m working on the code to lift the gate. I’m at a pause because I only have one relay. But I’ve run into some unpredictable and erratic behavior.
The main problem, it will stop reading RFID Tags if i have an actuator attached to the relay.
This is the very first line of the loop
if (!mfrc522.PICC_IsNewCardPresent()) { //if PICC_IsNewCardPresent returns 1, a new card has been found and we continue
Serial.println("looking for new card");
return; //if it did not find a new card is returns a '0' and we return to the start of the loop
}
All it does is look for a card to scan. It loops through this until there is a card near the scanner. It loops pretty fast. more on this in a moment.
This bit of code I added to start working the logic to raise and lower the gate. It will run fine without anything attached to the relay, but attach the motor to the relay and everything stops functioning.
Remember that first line? I notice that when it faults, the whole arduino, or at least the rate its printing the comment, slows down??? I don’t know what to make of this. on the occation i can run the loop 2 or 3 times it doesn’t slow down.
unsigned long interval=5000; // the time we need to wait
unsigned long previousMillis=0; // millis() returns an unsigned long.
unsigned long startMillis = millis(); // grab current time
raisegate();
Serial.println("gate is raised");
//lower gate
previousMillis=0;
startMillis = millis();
while((unsigned long)(millis() - startMillis) <= interval){// check if "interval" time has passed (5000 milliseconds)
if(digitalRead(2) == LOW){
lowergate();
}else if(digitalRead(2) == HIGH){
raisegate();
}else{
digitalWrite(3,HIGH);
}
}
in fact it seems this has kinda been sparatic, sometimes i seem to need to compile and upload the code a couple times in order to get the rfid tag to read, sometimes i need to load a different sketch then reload my sketch then itl read.
i’m not sure where to go from here. I’ve attached the whole sketch. Everything seems to be working up till i attach an actuator motor up to the relay.
thank you very much for the help.
and thank you forum for helping me get this far. i’ve learned quite a bit. slowly but, you know.
ppcc_gate.ino (13.5 KB)