Solenoid Lock with RFID sensor only working once

Hello, I'm currently working on a project which is an upgraded miniature room with basic features. Essentially, it has a 16x2 lcd I2C screen which displays the humiture sensor's data. A fire sensor connected to a passive buzzer. And the RFID which is supposed to open a Solenoid lock via a relay module.

The problem I'm encountering is that once the RFID scans any of the keys I have granted access to, it opens the solenoid lock only once, when I tap it again, it doesn't do anything, the serial monitor also doesn't update. Until I reset the Arduino uno 3, then it works but only once again. For specifications, the solenoid is powered by 3x3.7v battery, the RFID is powered via the Arduino's 3.3v, and the Arduino itself is powered by a 12 volts battery.

The possible problems I have deduced are either;

  • Poorly soldered wires (I have extended wires by soldering, which doesn't seem like the case because it does work but only once.)

  • Power overload or lack of power (I have tried to power the Arduino with 5, 9, and 12 volts. all worked previously when I was testing a couple of weeks ago.)

  • Circuit overload? (cant the Arduino handle this much workload?)

  • Project Image:

  • Possible coding error?;

#include <SPI.h>
#include <MFRC522.h>
#include <dht.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

dht DHT;

const int DHT11_PIN = 7;
unsigned long previousMillis = 0UL;
unsigned long interval = 1000UL;
int flameSensorReading;

#define SS_PIN 10
#define RST_PIN 9
#define RELAY 3
#define ACCESS_DELAY 2000
#define flameSensorPin 0
#define buzzerPin 8
MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() {
  Serial.begin(9600);
  pinMode(buzzerPin, OUTPUT);
  SPI.begin();
  lcd.init();
  lcd.backlight();
  mfrc522.PCD_Init();
  pinMode(RELAY, OUTPUT);
  digitalWrite(RELAY, LOW);
  Serial.println("Put your card to the reader...");
  Serial.println();
}

void loop() {

  unsigned long currentMillis = millis();
  {

    if (currentMillis - previousMillis > interval) {
      int chk = DHT.read11(DHT11_PIN);
      switch (chk) {
        case DHTLIB_OK:
          break;
        case DHTLIB_ERROR_CHECKSUM:
          break;
        case DHTLIB_ERROR_TIMEOUT:
          break;
        default:
          break;
      }
      // DISPLAY DATA
      lcd.setCursor(0, 0);
      lcd.print("Temp:");
      lcd.print(DHT.temperature, 1);
      lcd.print(char(223));
      lcd.print("C");
      lcd.setCursor(0, 1);
      lcd.print("Hum:");
      lcd.print(DHT.humidity, 1);
      lcd.print("%");
      previousMillis = currentMillis;
    }
  }

  flameSensorReading = analogRead(flameSensorPin);
  if (flameSensorReading < 1200) {
    digitalWrite(buzzerPin, LOW);
  } else {
    digitalWrite(buzzerPin, HIGH);
  }

  if (!mfrc522.PICC_IsNewCardPresent()) {
    return;
  }
  if (!mfrc522.PICC_ReadCardSerial()) {
    return;
  }
  Serial.print("UID tag :");
  String content = "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
    content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "94 E5 D3 85" || "03 76 9D 2F")  //change here the UID of the card/cards that you want to give access
  {
    Serial.println("Authorized access");
    Serial.println();
    digitalWrite(RELAY, HIGH);
    delay(ACCESS_DELAY);
    digitalWrite(RELAY, LOW);
  }
}


I would very much appreciate any advice and help I could get, and I thank you for taking the time to take a look at the issue.

Help us help you.

Hi! thanks for the reply, I have addressed some of the issues that you mentioned.

  • There was no error message when compiling the sketch so I have nothing to show for that.
  • As for the schematic, sorry, I'm not capable of doing schematics, nor I have learned where I can do them online.
  • If the image of the project is still bad, I can try to update it tomorrow when I get back to school.
  • The Arduino is an Arduino Uno Rev3 which is powered by ATmega328P
  • I'm not sure what simulation code means, but this is the code I have been using since testing and when the project was put inside the diagram.

I will try to comprehensively explain it better. Every other sensors that are connected works. But the only problem I am encountering is when I first upload the sketch/reset the Arduino with the uploaded sketch, the first RFID scan works, it unlocks the solenoid and the serial monitor shows what key I used and says Access Granted. But when I try to scan it again after a second, nothing happens. It doesn't do anything. its as simple as that.

I apologize again for any mistakes I have made when posting this forum, it is my first time here. Thanks for the reply still.

post an image of the project, please.

And when posting code do not just post over post#1. Instead post new stuff in a new post.

I have posted the image, sorry for the first since it said I cant embed and image as I am a new user, but it seems like it works now.

and once again you edited the original post instead of posting the image as a new post. Good luck with your project.

Problem, bread board power rail split:


Solution, bread board power rail split:

Do all breadboards have that? Cause mine doesn't have the power split in the middle, it has one continuous line of negative and positive printed on it. another thing is, each side is connected to a different power source, one is 3.3v and the other is 5v. both having different ground connected to it as well.

Hi,

So how did you know how to connect your circuit?

Google;

how to draw a circuit diagram

Literally tons of examples and YouTube video clips.

There is nothing stopping you from hand drawing a circuit and posting an image of it.
No CAD needed, no looking for symbols to use, etc.

Tom.. :smiley: :+1: :coffee: :australia:

Hello!

I just eyeballed it :sweat_smile:

I actually just started creating one using this online tool, its a bit off, but I did my best trying to replicate my circuit, I hope you can understand and that it will be useful to anyone who wants to help as well.

Thanks for the diagram, pretty well done for first try. :+1:

If you are using a UNO you cannot use it is advisable not to use pins 0 ans 1, as they are the UART pins used to program the UNO.

Can you post link to specs/data of your flame sensor?
Can you post link to solenoid lock?

The wiring of the 12V supply, the solenoid and relay appears wrong, why are you feeding 12V into D3 and how are you making the relay work?
Your power board distributor, what are the internal connections?
What pins are connected to what?

I see in your image enough batteries for 9V (6 x AA), what voltage are you using?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Hi,
I think this is what you mean with the relay;

Tom.. :smiley: :+1: :coffee: :australia:

Well, if that picture is accurate..
I recommend a full rewire..
Go slow, only hook up wires that need to be..
No exposed conductors, wires should be as short as possible..
sorry.. ~q

I have currently removed the flame sensor for a while until I fix the solenoid.

The flame sensor was included in this kit, as for as for the solenoid lock. I have bought them both in their store about 2 months ago.

As for these questions, I hope this image can explain it. Since I do not know how I would answer or explain some of it. Sorry.

Extra Image of the relay

Thanks for the suggestion! Unfortunately I already have re-wired and fixed a couple of wirings, still the same problem. However a temporary fix I did was that the entire code resets after 1 second of getting a signal from the rfid.

Here's the updated code

#include <SPI.h>
#include <MFRC522.h>
#include <dht.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

dht DHT;

const int DHT11_PIN = 7;
unsigned long previousMillis = 0UL;
unsigned long interval = 1000UL;
int flameSensorReading;

#define SS_PIN 10
#define RST_PIN 9
#define RELAY 3
#define ACCESS_DELAY 2000
#define flameSensorPin 0
#define buzzerPin 8
MFRC522 mfrc522(SS_PIN, RST_PIN);

void (*resetFunc)(void) = 0;
 
void setup() {
  Serial.begin(9600);
  pinMode(buzzerPin, OUTPUT);
  SPI.begin();
  lcd.init();
  lcd.backlight();
  mfrc522.PCD_Init();
  pinMode(RELAY, OUTPUT);
  digitalWrite(RELAY, LOW);
  Serial.println("Put your card to the reader...");
  Serial.println();
}

void loop() {

  unsigned long currentMillis = millis();
  {

    if (currentMillis - previousMillis > interval) {
      int chk = DHT.read11(DHT11_PIN);
      switch (chk) {
        case DHTLIB_OK:
          break;
        case DHTLIB_ERROR_CHECKSUM:
          break;
        case DHTLIB_ERROR_TIMEOUT:
          break;
        default:
          break;
      }
      // DISPLAY DATA
      lcd.setCursor(0, 0);
      lcd.print("Temp:");
      lcd.print(DHT.temperature, 1);
      lcd.print(char(223));
      lcd.print("C");
      lcd.setCursor(0, 1);
      lcd.print("Hum:");
      lcd.print(DHT.humidity, 1);
      lcd.print("%");
      previousMillis = currentMillis;
    }
  }

  flameSensorReading = analogRead(flameSensorPin);
  if (flameSensorReading < 1200) {
    digitalWrite(buzzerPin, LOW);
  } else {
    digitalWrite(buzzerPin, HIGH);
  }

  if (!mfrc522.PICC_IsNewCardPresent()) {
    return;
  }
  if (!mfrc522.PICC_ReadCardSerial()) {
    return;
  }
  Serial.print("UID tag :");
  String content = "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
    content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "94 E5 D3 85" || "03 76 9D 2F")  //change here the UID of the card/cards that you want to give access
  {
    Serial.println("Authorized access");
    Serial.println();
    digitalWrite(RELAY, HIGH);
    delay(ACCESS_DELAY);
    digitalWrite(RELAY, LOW);
    delay(1000);
    resetFunc();
  }
}

Can you draw a BLOCK diagram that has boxes for the major components and add lines for the connections between the components?

But have you completely removed it from your code?
Your solenoid;

12V Solenoid Lock

12V Solenoid lock are basically electromagnets: they are made of a big coil of copper wire with an armature (a slug of metal) in the middle. When the coil is energized, the slug is pulled into the center of the coil. This makes the solenoid able to pull from one end.
This solenoid lock in particular is nice and strong, and has a slug with a slanted cut and a good mounting bracket. It’s basically an electronic lock, designed for a basic cabinet or safe or door. Normally the lock is active so you can’t open the door because the solenoid slug is in the way. It does not use any power in this state. When 9-12VDC is applied, the slug pulls in so it doesn’t stick out anymore and the door can be opened.

So you have it wired so if the relay is not activated, the relay is ON, and unlocked.
Also your power connections.

Tom.. :smiley: :+1: :coffee: :australia:

Do you have a reverse biased diode connected across the solenoid coil?

The need for one is all explained in this pinned topic in the general electronics section:
Flyback diodes and why you need them

I encountered that problem too. The method I used was wrap a aluminum foil around it(only solenoid lock). And then it might functioned normally.