0% found this document useful (0 votes)
25 views

Arduino RFID

The document describes an Arduino code for an RFID access control system. It includes initializing an RFID reader module, reading RFID tags, and controlling outputs like LEDs, buzzer and LCD based on valid or invalid tags. The code checks the tag UID and allows or denies access by activating corresponding outputs.

Uploaded by

hakima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Arduino RFID

The document describes an Arduino code for an RFID access control system. It includes initializing an RFID reader module, reading RFID tags, and controlling outputs like LEDs, buzzer and LCD based on valid or invalid tags. The code checks the tag UID and allows or denies access by activating corresponding outputs.

Uploaded by

hakima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

#include <SPI.

h>
#include <Servo.h> // Télécharger la bibliothèque Servo.h comme vu précédemment
#include <MFRC522.h>

#define RST_PIN 9
#define SS_PIN 10
MFRC522 module_rfid(SS_PIN, RST_PIN);

int buzzer = 8;
int led_rouge = 14;
int led_verte = 15;
Servo monServo;
int etat_init = 1 ;

void setup() {
pinMode(led_rouge, OUTPUT);
pinMode(led_verte, OUTPUT);
pinMode(buzzer, OUTPUT);
monServo.attach(7); // leservomoteur sur le pin 7 de la carte Arduino
monServo.write(0);// mettre le servomoteur à la position 0
Serial.begin(9600); // demarrage de la fréquence du moniteur seris
SPI.begin(); // demarrage de la communication SPI
module_rfid.PCD_Init(); //initialisation du module rfid
}

void loop() {
if ( ! module_rfid.PICC_IsNewCardPresent())
{
return;
}
if ( ! module_rfid.PICC_ReadCardSerial())
{
return;
}
String UID = "";
for (byte i = 0; i < module_rfid.uid.size; i++) {
UID.concat(String(module_rfid.uid.uidByte[i] < 0x10 ? " 0" : " "));
UID.concat(String(module_rfid.uid.uidByte[i], HEX));
}
UID.toUpperCase();
if (UID.substring(1) == "D0 16 53 7E" or "A0 16 33 5E") // si le module detecte
le badge ou le port clé
{
Serial.print("etat_init");
if(etat_init%2 == 1)

1
{
digitalWrite(led_verte, HIGH);
tone(buzzer, 1200, 100);
delay(125);
tone(buzzer, 1200, 100);
delay(2000);
digitalWrite(led_verte, LOW);
monServo.write(120);
etat_init++;
delay(1000);
}
else
{
monServo.write(0);
etat_init++;
delay(1000);
}
}
else {

digitalWrite(led_rouge, HIGH);
tone(buzzer, 200, 750);
delay(2000);
digitalWrite(led_rouge, LOW);
}
}

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

#define RST_PIN 9 // Configurable, see typical pin layout above


#define SS_PIN 10 // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

void setup() {
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


mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}

3
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

#define RST_PIN 9
#define SS_PIN 10
MFRC522 module_rfid(SS_PIN, RST_PIN);

int buzzer = 8;
int led_rouge = 14;
int led_verte = 15;

void setup() {
pinMode(led_rouge, OUTPUT);
pinMode(led_verte, OUTPUT);
pinMode(buzzer, OUTPUT);
lcd.begin(16, 2);
SPI.begin();
module_rfid.PCD_Init();
lcd.print("détecteur");
lcd.setCursor(0, 1);
lcd.print("de carte");
delay(3000);
lcd.clear();
}

void loop() {
lcd.print("Scannez votre");
lcd.setCursor(1, 1);
lcd.print("carte ou badge..");
if ( ! module_rfid.PICC_IsNewCardPresent())
{
return;
}
if ( ! module_rfid.PICC_ReadCardSerial())
{
return;
}
String UID = "";
for (byte i = 0; i < module_rfid.uid.size; i++) {
UID.concat(String(module_rfid.uid.uidByte[i] < 0x10 ? " 0" : " "));
UID.concat(String(module_rfid.uid.uidByte[i], HEX));
}
UID.toUpperCase();

4
if (UID.substring(1) == "D0 16 53 7E")
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ACCES AUTORISE");
digitalWrite(led_verte, HIGH);
tone(buzzer, 1200, 100);
delay(125);
tone(buzzer, 1200, 100);
delay(2000);
digitalWrite(led_verte, LOW);
lcd.clear();
}
else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ACCES REFUSE");
digitalWrite(led_rouge, HIGH);
tone(buzzer, 200, 750);
delay(2000);
digitalWrite(led_rouge, LOW);
lcd.clear();
}
}

5
6

You might also like