Replies: 4 comments
-
|
Bro although I'm a student majored in communication engineering, this isn't the reason you post this here... But quick answer: Try to add a 1N4007 diode across the solenoid (cathode to +, anode to -). Consider using a separate power supply too |
Beta Was this translation helpful? Give feedback.
-
|
Thanks I'll give it a try.
…On Wed, Dec 31, 2025, 9:45 PM Bingxi Zhao (Frank) ***@***.***> wrote:
Closed #16 <#16> as
resolved.
—
Reply to this email directly, view it on GitHub
<#16>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOBJSNDCWAJYVVXOWGZF3TD4ESC57AVCNFSM6AAAAACQNOK7FCVHI2DSMVQWIX3LMV45UABFIRUXGY3VONZWS33OIV3GK3TUHI5E433UNFTGSY3BORUW63R3GIZTGMZRHA2Q>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
|
I just reread your answer. At first I read diode across the relay. Which is
5vdc.
You said across the solenoid.
The solenoid is 25v ac. It has it's own power supply. Could EMF
Be the cause of the problem?
…On Wed, Dec 31, 2025, 11:23 PM Will Gre ***@***.***> wrote:
Thanks I'll give it a try.
On Wed, Dec 31, 2025, 9:45 PM Bingxi Zhao (Frank) <
***@***.***> wrote:
> Closed #16 <#16> as
> resolved.
>
> —
> Reply to this email directly, view it on GitHub
> <#16>, or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AOBJSNDCWAJYVVXOWGZF3TD4ESC57AVCNFSM6AAAAACQNOK7FCVHI2DSMVQWIX3LMV45UABFIRUXGY3VONZWS33OIV3GK3TUHI5E433UNFTGSY3BORUW63R3GIZTGMZRHA2Q>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
|
Beta Was this translation helpful? Give feedback.
-
|
Maybe an ecteronic engineer could tell me why this worked. I added another relay. I have the 5v relay triggering a 12v relay with its own power supply. I have the 25vac power going thru the 12v relay. now the system works. successfully triggered the solenoid door latch 24 times in a row. and the a maglock 6 times. before the added relay the most I could get is 3 times usually only 1 before program would freeze. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am Having an Issue with my RFID door control code. It works perfectly tripping the relay until I hook up solenoid door latch to it.
The it trips the relay and activates the door latch and the program freezes. it won't read another card.
here is the code. any Ideas why connecting a solenoid to the relay would crash the program?
#include <SPI.h>
#include <MFRC522.h>
#include <EEPROM.h>
#define SS_PIN 8
#define RST_PIN 9
#define RELAY_PIN 7
#define GREEN_LED 2
#define RED_LED 3
MFRC522 mfrc522(SS_PIN, RST_PIN);
byte masterCard[4];
bool programMode = false;
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
pinMode(RELAY_PIN, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(RED_LED, OUTPUT);
digitalWrite(RELAY_PIN, LOW); // Lock initially
// Check if Master Card is defined in EEPROM (using address 1 as a flag)
if (EEPROM.read(1) != 143) {
Serial.println("No Master Card Set. Scan a card now...");
while (!getCardUID()); // Wait for first card
for (int i = 0; i < 4; i++) EEPROM.write(2 + i, mfrc522.uid.uidByte[i]);
EEPROM.write(1, 143);
Serial.println("Master Card Saved.");
}
// Load Master Card from EEPROM
for (int i = 0; i < 4; i++) masterCard[i] = EEPROM.read(2 + i);
}
void loop() {
if (!getCardUID()) return;
if (isMaster(mfrc522.uid.uidByte)) {
programMode = !programMode;
Serial.println(programMode ? "Entering Program Mode" : "Exiting Program Mode");
flashLED(programMode ? GREEN_LED : RED_LED, 3);
return;
}
if (programMode) {
toggleUserCard(mfrc522.uid.uidByte);
} else {
if (checkAccess(mfrc522.uid.uidByte)) {
grantAccess();
} else {
denyAccess();
}
}
}
bool getCardUID() {
if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) return false;
return true;
}
bool isMaster(byte tag[]) {
for (int i = 0; i < 4; i++) {
if (tag[i] != masterCard[i]) return false;
}
return true;
}
void grantAccess() {
digitalWrite(GREEN_LED, HIGH);
digitalWrite(RELAY_PIN, HIGH);
Serial.println("Access Granted");
delay(2000); // Door open time
digitalWrite(RELAY_PIN, LOW);
digitalWrite(GREEN_LED, LOW);
}
void denyAccess() {
Serial.println("Access Denied");
digitalWrite(RED_LED, HIGH);
delay(1000);
digitalWrite(RED_LED, LOW);
}
// Logic to check EEPROM for stored user tags
bool checkAccess(byte tag[]) {
for (int i = 10; i < EEPROM.length(); i += 5) { // Start user cards at address 10
if (EEPROM.read(i) == 1) { // 1 indicates a valid slot
bool match = true;
for (int j = 0; j < 4; j++) {
if (EEPROM.read(i + 1 + j) != tag[j]) match = false;
}
if (match) return true;
}
}
return false;
}
void toggleUserCard(byte tag[]) {
int slot = -1; // To store the first empty slot found
bool found = false;
// Search EEPROM starting from address 10 (user slots)
for (int i = 10; i < EEPROM.length(); i += 5) {
if (EEPROM.read(i) == 1) { // Slot is occupied
bool match = true;
for (int j = 0; j < 4; j++) {
if (EEPROM.read(i + 1 + j) != tag[j]) match = false;
}
}
// Card not found: ADD it to the first available empty slot
if (!found) {
if (slot != -1) {
EEPROM.write(slot, 1); // Set "valid" flag
for (int j = 0; j < 4; j++) {
EEPROM.write(slot + 1 + j, tag[j]); // Store UID bytes
}
Serial.println("User Card Added to EEPROM.");
flashLED(GREEN_LED, 2); // Visual confirmation of addition
} else {
Serial.println("EEPROM Full! Cannot add more cards.");
flashLED(RED_LED, 5);
}
}
}
void flashLED(int pin, int times) {
for (int i = 0; i < times; i++) {
digitalWrite(pin, HIGH); delay(200); digitalWrite(pin, LOW); delay(200);
}
}
Beta Was this translation helpful? Give feedback.
All reactions