Hi everyone,
beginning, I must state I am new to Arduino. So I decided to do a project with a Arduino RFID scanner but eventually ran into some issues, first off, my pins would float when loading my sketch into the Arduino MCU (mega 2560). I later found a fix to the issue though it started messing up some code later in the sketch, ill attach what the code was to specify. looking for a way to solve the issue, thanks. please note the first few lines under the startup were me testing out the fixes to the floating pins, please reply if you have an alternate way to stop the pins from floating without messing up later parts of the sketch.
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 5 // Configurable, see typical pin layout above
#define SS_PIN 53 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
byte accessUID[4] = {0xD3, 0x94, 0x25, 0x05};
int greenPin = 8;
int redPin = 9;
int buzzerPin = 10;
void setup() {
//pinMode(8, INPUT_PULLUP);
//pinMode(9, INPUT_PULLUP);
//pinMode(10, INPUT_PULLUP);
//digitalWrite(10, HIGH);
//digitalWrite(9, HIGH);
//digitalWrite(8, HIGH);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
void loop() {
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
if (mfrc522.uid.uidByte[0] == accessUID[0] && mfrc522.uid.uidByte[1] == accessUID[1] && mfrc522.uid.uidByte[2] == accessUID[2] && mfrc522.uid.uidByte[03] == accessUID[3]) {
Serial.println("Access Granted");
digitalWrite(greenPin, HIGH);
delay(2000); //here is where it ignored the next two statement and kept the pin (LED) on high
digitalWrite(greenPin, LOW);
} else {
Serial.println("Access Denied");
digitalWrite(redPin, HIGH);
digitalWrite(buzzerPin, HIGH);
delay(1500); //same thing here as above, these three upcoming lines were ignored,
digitalWrite(redPin, LOW);
digitalWrite(buzzerPin, LOW);
}
mfrc522.PICC_HaltA();
}
would also like to note that when holding up the card to the scanner (while the pins were stuck on high) would turn them off for a second or two and then turn back on again. please reply if you have a way to fix this issue.
Thanks