当前位置:首页 > 科学研究 > 电子编程 > 正文内容

Arduino Project 045 - RFID Servo and LED Control System

RonWang1个月前 (12-11)电子编程103

Arduino Programming Basic -- RFID Servo and LED Control System

Project 45 RFID Servo and LED Control System

Arduino RFID Access Control System Circuit

Arduino RFID Access Control System Schematic

RFID Servo and LED indicator Control System


/* Project 45 RFID - Access Servo and Control / Gate LED indicator 
   Circuit Design  By Ron Wang 2024 NY
 Schematic Design By Ron Wang 2024 NY
*/ 
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h> 
Servo microservo9g;
#define SS_PIN 10    // RC522 module pin definitions
#define RST_PIN 9

MFRC522 mfrc522(SS_PIN, RST_PIN);
int led_concedido = 5; // Leds indicating access granted or denied
int led_negado = 6;
char st[20];

void setup()
{
  pinMode(led_concedido, OUTPUT);
  pinMode(led_negado, OUTPUT);
  // Defines that the servo is connected to digital port 3
  microservo9g.attach(3);
  // Moves the servo to the start position (cancel closed)
  microservo9g.write(90);
 // Start the serial
  Serial.begin(9600);
  // Start SPI  Bus
  SPI.begin();
  // Start MFRC522
  mfrc522.PCD_Init();
 // Initial messages on the serial monitor
  Serial.println("Bring your card closer to the reader...");
  Serial.println();
}

void loop()
{
 // Wait for the card to approach
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
 // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }
 // Show UID on serial
  Serial.print("UID da tag :");
  String conteudo= "";
  byte letra;
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     conteudo.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     conteudo.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Mensagem : ");
  conteudo.toUpperCase();
 
  // Test if card2 has been read,you can modification the Value your RFID tag value
  if (conteudo.substring(1) == "C1 41 38 1D")  
  {
    // Raises the gate and lights the green LED
    microservo9g.write(-90);
    digitalWrite(led_concedido, HIGH);
    Serial.println("Card1 - Access granted!");
    Serial.println();
    delay(3000);
    microservo9g.write(90);
    digitalWrite(led_concedido, LOW);
    }
   
 // Test if card2 has been read
  if (conteudo.substring(1) == "C1 41 38 1D")
  {
    Serial.println(";Card2 - Access granted!!!");
    Serial.println();
    // Flashes the red LED
    for (int i= 1; i<5 ; i++)
    {
      digitalWrite(led_negado, HIGH);
      delay(200);
      digitalWrite(led_negado, LOW);
      delay(200);
    }
  }
  delay(1000);
}


版权声明:本文为原创文章,版权归donstudio所有,欢迎分享本文,转载请保留出处!

本文链接:http://parentscn.com/?id=302

标签: Arduino

相关文章

Arduino Programming Basic - Variables

Arduino Programming Basic - Variables

Arduino 程序基础,介绍Arduino程序的基本组成,第一部分编写了10个例子,关于变量及变量名称,串口监视器,if循环,for循环,while循环等。第二部分介绍了函数,全局变量,局部变量和静...

Arduino Project 042 - SD Card Information Basic

Arduino Project 042 - SD Card Information Basic

Arduino Programming Basic -- Reading and Writing to an SD CardProject 42A SD Card InformationArduino...

Arduino Project 039 - Ultrasonic Distance Display

Arduino Project 039 - Ultrasonic Distance Display

Ultrasonic sensors measure distance by sending and receiving the ultrasonic wave. The ultrasonic sen...

Arduino Programming Basic - If and Loop

Arduino Programming Basic - If and Loop

Arduino 程序基础,介绍Arduino程序的基本组成,第一部分编写了10个例子,关于变量及变量名称,串口监视器,if循环,for循环,while循环等。第二部分介绍了函数,全局变量,局部变量和静...

Arduino UNO Mp3音乐播放代码

Arduino UNO Mp3音乐播放代码

Arduino UNO Mp3音乐播放代码今天我们将使用Arduino UNO 和SD卡制作音乐播放器。这个播放器不需要添加多余的模块,只需要SD读卡器和Arduino UNO开发板就可以播放音频文件...

 Arduino Project 037 - 18B20 Temperature Sensor

Arduino Project 037 - 18B20 Temperature Sensor

The DS18B20 Temperature Sensor is a digital temperature sensor capable of measuring temperatures wit...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。