Bonjour, comme vous avez vu dans le titre, je cherche a ouvrir la porte en passant mon badge, et pour la refermer, repasser le même badge. Pour l’instant j’arrive juste a l’ouvrir mais après un certain temps la porte se ferme, or moi je veut passer le badge pour quel se ferme. Voici mon code:
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);
const int LR = 5;
const int LV = 6;
Servo monServomoteur;
void setup()
{
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
Serial.println("Approximate your card to the reader...");
Serial.println();
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
monServomoteur.attach(2);
}
void loop()
{
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) == "A6 66 D5 1A")
{
Serial.println("Authorized access");
Serial.println();
delay(10);
digitalWrite (LV, HIGH);
for (int position = 140; position >= 40; position--) {
monServomoteur.write(position);
delay(2);
}
{
monServomoteur.write(40);
delay(3000);
}
for (int position = 40; position <= 140; position++) {
monServomoteur.write(position);
delay(15);
}
digitalWrite (LV, LOW);
}
else {
Serial.println(" Access denied");
delay(10);
digitalWrite (LR, HIGH);
delay(2000);
digitalWrite (LR, LOW);
}
}
Merci à ceux qui m’aiderons.