RFID kart ile röle açma, aynı RFID kart ile aynı röleyi kapatma

0 oy
4 gün önce hilalim sordu
Arkadaşlar Merhaba,

Elimde RDM300  RFID kart okuyucu var. Tanımlanmış bir RFID kart ile röle açmak ve tekrar kartı okuttuğumda aynı rölenin kapanmasını istiyorum. Aşağıda belirttiğim programı yazdım. Ama bu programa göre röle enerji verilir verilmez direk kontak kapalı konumunda yani açık oluyor. Kartı okuttuğumda kapanıyor fakat 5 sn sonra kontak tekrar açılarak kapalı konuma geliyor ve kart okutmadıkça da kapalı durumda kalıyor. Aynı zamanda röle açık konumdayken yeşil led ve kapalı konumdayken de kırmızı led yanıyor. Program aşağıdaki gibidir. Yardımcı olur musunuz?

#include <SoftwareSerial.h>
SoftwareSerial RFID(0, 1);                                                                                                                                
int data = 0;                                                                                                                                             
int ok = -1;                                                                                                                                              
int yes = 3;                                                                                                                                              
int no = 2;                                                                                                                                               
int relay=10;                                                                                                                                             

int tag1[14] = {2,56,48,48,48,54,55,51,65,49,49,67,67,3};                                                                                         
int tag2[14] = {2,50,48,48,48,55,70,57,57,54,70,65,58,3};                                                                                         
int newtag[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};                                                                                                    

void setup()

{

RFID.begin(9600);                                                                                                                                   
Serial.begin(9600);                                                                            
pinMode(yes, OUTPUT);                                                               
pinMode(no, OUTPUT);                                                                  
pinMode(relay,OUTPUT);                                                      

}

boolean comparetag(int aa[14], int bb[14])                                                
{
boolean ff = false;                                                                      
int fg = 0;                                                                                                                                
for (int cc = 0 ; cc < 14 ; cc++)                                                                                                               
{
if (aa[cc] == bb[cc])                                                                                                                                    
{
fg++;                                                                                                                                                  
}
}
if (fg == 14)                                                                                                                                       
{
ff = true;                                                                                                                                              
}
return ff;                                                                                                                                           
}

void checkmytags()                                                                                                                                        
{
ok = 0;                                                                                                                                              

if (comparetag(newtag, tag1) == true)  
{                                                                                                 
ok++;                                                                                                                                                    
}
if (comparetag(newtag, tag2) == true)    
{                                                                                       
ok++;                                                                                                                                         
}
}
void readTags()                                                                                                                                            
{
  
ok = -1;                                                                                                                                         
if (RFID.available() > 0)                                                                                                                            
{
delay(100);                                                                                                                         

for (int z = 0 ; z < 14 ; z++)                                                                                                                          
{
data = RFID.read();                            
newtag[z] = data;                              
}

RFID.flush();                                   

checkmytags();                                   
}
if (ok > 0)                                      
{
Serial.println("Accepted");                      
digitalWrite(yes,HIGH);                          
digitalWrite(relay,HIGH);                        

delay(1000);                                   
ok =-1;                                     
}
else if (ok == 0)                            
{
Serial.println("Rejected");                  
digitalWrite(no, HIGH);                          
digitalWrite(relay,LOW);                      
delay(1000);  

ok = -1;                                  
}

}

void loop()                          
{

  readTags();
  
}

Cevabınız

Adınız (isteğe bağlı):
Gizlilik: E-posta adresiniz yalnızca bu bildirimlerin gönderilmesi için kullanılacak.
Spam Koruması:
Gelecekte bu doğrulamadan kurtulmak için, lütfen giriş yapınız veya üye olunuz.
      Arduino Başlangıç Seti 
Uzman Sayfası
...