Turn On Lamp Using RFID

How To Turn On/Off Lamp Using RFID RC522 Arduino?

Posted on

Lamp Using RFID Arduino – RFID Is a technology for identifying code between devices wirelessly. The use of RFID in the community is very much because the system is very practical such as door lock systems, parking systems, product tracks, libraries, shopping, and others. In this article we will make an RFID device that is useful for turning on or turn off lights.

The RFID that we use here is MFRC522 RFID chips or RC522 modules. If you still don’t understand how RFID works, please read this article Arduino RC522 RFID Tutorial.

The description of this Lamp Using RFID Arduino project are as follows: “Each RFID card has an ID code that is different from the other cards. This card another word is tag. The ID code of the known card is stored in the microcontroller. When the card is brought to the RFID reader, the microcontroller will compare the ID code received by the reader with the stored ID code in the controller. If the ID code is the same, the light will turn on. If not the same, there will be no change. To turn off the lights, we will use the same card.

 

Schematic

Please connect your existing RFID to Arduino as shown picture below.

Schematif RFID Turn On Lamp LED

 

Scan Of The ID Code From Tag

To be used RFID We must know the ID code of the card or tag that we use. To be able to display the ID code of the card please upload the following program then open the serial monitor on the Arduino IDE. For example, after I put my card at RFID Reader, I got my ID code is “5A86340”. This ID code that we will use in the program main.

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

#define SS_PIN 10
#define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup()
{

  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  Serial.println("Put your card or tag at RFID Reader...");
  Serial.println();

}
void loop()
{
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }
  Serial.print("ID tag :");
  String content = "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    Serial.print(mfrc522.uid.uidByte[i], HEX);
    content.concat(String(mfrc522.uid.uidByte[i], HEX));

  }
  Serial.println();
  delay(2000);
}

Main Program

For example, we have got the RFID ID code above with ID code “5A86340”. But in program I convert capital letters to lowercase letters to be “5a86340”.  I have made a program to turn on / off lights with RFID. Please use the program below . Please replace the myID code program line according to the ID code you have.

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

#define SS_PIN 10
#define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN);

String myID = "5a86340";
int lamp = 8;
int cond = 0;

void setup()
{

  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  Serial.println("Put your card or tag at RFID Reader...");
  Serial.println();
  pinMode(lamp, OUTPUT);

}
void loop()
{
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }
  Serial.print("ID tag :");
  String content = "";
  byte letter;

  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    Serial.print(mfrc522.uid.uidByte[i], HEX);
    content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  
  if ((content == myID) && (cond == 0)) {
    digitalWrite(lamp, HIGH);
    Serial.println("Turn On Lamp");
    cond = 1;
    content = "";
    delay(2000);
  }
  if ((content == myID) && (cond == 1)) {
    digitalWrite(lamp, LOW);
    Serial.println("Turn Off Lamp");
    cond = 0;
    content = "";
    delay(2000);
  }
}

Then upload it to your arduino. See your circuit or serial monitor. May be useful.

Read other articles  How To Use Nokia LCD 5110 With Arduino

 

One thought on “How To Turn On/Off Lamp Using RFID RC522 Arduino?

Leave a Reply

Your email address will not be published. Required fields are marked *