125KHz RFID code schrijven

Hallo,

ik zit al even met mijn handen in het haar door een code welke ik probeer te schrijven, het betreft een code waarbij ik een functie wil maken waarbij een RFID tag wordt herkend en hier dan een actie op laten uitvoeren.
Alle RFID tags welke niet in het de String accessGranted staan wil ik dat de boolean False blijft.
Dit laatste gaat mij wel lukken maar het lukt me steeds niet om de "Serial.println ("Toegang goedgekeurd");" uit te laten voeren op alleen de opgeslagen RFID tags, het ene moment wordt het wel uitgevoerd maar dan ook bij RFID tags welke niet zijn opgeslagen??? Ik kom er niet meer uit, misschien kan iemand mij hierin helpen?

Mijn vraag slaat voornamelijk op het stukje van de "void checkAccess"

Groet, Artur.

#include <SoftwareSerial.h>
 
SoftwareSerial SoftSerial(2, 3);
unsigned char buffer[64];       // buffer array for data receive over serial port
unsigned char str[16];     //MAX_LEN is 16: size of the array 
int count = 0;                    // counter for buffer array

String accessGranted [2] = {"750069FA9F79", "750069FBC720"};  //RFID serial numbers to grant access to
int accessGrantedSize = 2;                                //The number of serial numbers
 
void setup()
{
    SoftSerial.begin(9600);     // the SoftSerial baud rate
    Serial.begin(9600);         // the Serial port of Arduino baud rate.
}
 
void loop()
{
  //Toegevoegde code


  //tot hier
    // if date is coming from software serial port ==> data is coming from SoftSerial shield
    if (SoftSerial.available())              
    {
        while(SoftSerial.available())               // reading data into char array
        {
            buffer[count++] = SoftSerial.read();      // writing data into array
            String buffer = "";
            for (int i = 0; i < 4; i++)
            {
              buffer = buffer + (0x0F & (str[i] >> 4));
              buffer = buffer + (0x0F & str[i]);
            }
            if(count == 64)break;
        }
        Serial.print("The card's ID number is : ");
        Serial.write(buffer, count);     // if no data transmission ends, write buffer to hardware serial port
        checkAccess (buffer);
        clearBufferArray();             // call clearBufferArray function to clear the stored data from the array
        count = 0;                      // set counter of while loop to zero
    }
    if (Serial.available())             // if data is available on hardware serial port ==> data is coming from PC or notebook
    SoftSerial.write(Serial.read());    // write it to the SoftSerial shield
    
}
void checkAccess (String buffer)
{
  boolean granted = false;
  for (int i=0; i <= (accessGrantedSize-1); i++)    //Controleerd of het ID nummer in de lijst staat              (int i=0; i <= (accessGrantedSize-1); i++)
  {
    if(accessGranted[i] == buffer)      //Als een van de ID's aanwezig zijn, voer onderstaande uit                (accessGranted[i] == buffer)
    {
      Serial.println ("Toegang goedgekeurd");
      granted = true;
    }
  }
}


void clearBufferArray()                 // function to clear buffer array
{
    // clear all index of array with command NULL
    for (int i=0; i<count; i++)
    {
        buffer[i]=NULL;
    }                  
}

Hello,

I've been in my hair for a while because of a code that I'm trying to write, it's a code where I want to make a function that recognizes an RFID tag and then has an action performed on it.
All RFID tags that are not in the String accessGranted I want the boolean to remain False.
I will be able to do the latter, but I keep failing to get the "Serial.println("Access approved");" to be executed on only the stored RFID tags, one moment it will be executed, but then also on RFID tags that are not stored??? I can't figure it out, maybe someone can help me with this?

My question mainly pertains to the "void checkAccess" part

Regards, Artur.

#include <SoftwareSerial.h>
 
SoftwareSerial SoftSerial(2, 3);
unsigned char buffer[64];       // buffer array for data receive over serial port
unsigned char str[16];     //MAX_LEN is 16: size of the array 
int count = 0;                    // counter for buffer array

String accessGranted [2] = {"750069FA9F79", "750069FBC720"};  //RFID serial numbers to grant access to
int accessGrantedSize = 2;                                //The number of serial numbers
 
void setup()
{
    SoftSerial.begin(9600);     // the SoftSerial baud rate
    Serial.begin(9600);         // the Serial port of Arduino baud rate.
}
 
void loop()
{
  //Toegevoegde code


  //tot hier
    // if date is coming from software serial port ==> data is coming from SoftSerial shield
    if (SoftSerial.available())              
    {
        while(SoftSerial.available())               // reading data into char array
        {
            buffer[count++] = SoftSerial.read();      // writing data into array
            String buffer = "";
            for (int i = 0; i < 4; i++)
            {
              buffer = buffer + (0x0F & (str[i] >> 4));
              buffer = buffer + (0x0F & str[i]);
            }
            if(count == 64)break;
        }
        Serial.print("The card's ID number is : ");
        Serial.write(buffer, count);     // if no data transmission ends, write buffer to hardware serial port
        checkAccess (buffer);
        clearBufferArray();             // call clearBufferArray function to clear the stored data from the array
        count = 0;                      // set counter of while loop to zero
    }
    if (Serial.available())             // if data is available on hardware serial port ==> data is coming from PC or notebook
    SoftSerial.write(Serial.read());    // write it to the SoftSerial shield
    
}
void checkAccess (String buffer)
{
  boolean granted = false;
  for (int i=0; i <= (accessGrantedSize-1); i++)    //Controleerd of het ID nummer in de lijst staat              (int i=0; i <= (accessGrantedSize-1); i++)
  {
    if(accessGranted[i] == buffer)      //Als een van de ID's aanwezig zijn, voer onderstaande uit                (accessGranted[i] == buffer)
    {
      Serial.println ("Toegang goedgekeurd");
      granted = true;
    }
  }
}


void clearBufferArray()                 // function to clear buffer array
{
    // clear all index of array with command NULL
    for (int i=0; i<count; i++)
    {
        buffer[i]=NULL;
    }                  
}

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum. It will help you get the best out of the forum in the future.

Thank you.


Which version do you prefer to keep?

The moderators can and are happy to move threads.

@arturvdb, if you'd like this thread moved to another section in the hopes of getting more eyes / attention just flag a post in the thread then let us know.

Hoi arturvdb.

Ik heb heel even door jouw sketch gekeken, en daarbij viel me op dat jij in de functie checkAccess een boolean variabele aanmaakt, die alleen daar geldig is.
Dat betekent dat zodra je die functie verlaat, de variabele 'granted' verdwijnt.
Ik vraag me af of dat de bedoeling is.
Verder is het natuurlijk zo dat wanneer je granted true maakt, je deze weer moet resetten zodra je je bedoelde handeling hebt afgerond, zodat iemand anders niet ook meteen toegang heeft omdat de deur nog open stond.
Binnen de sketch die je nu hebt gebeurt dat ook, omdat granted vervliegt zodra je de functie verlaat (omdat je alle ID's gecontroleerd hebt).
Ik zie dat je ook je buffer nog wist, maar in principe zou dat ook al moeten gebeuren wanneer je loop naar de volgende iteratie gaat.
Om daar zeker van te zijn, kun je tijdens het debuggen ook de inhoud van buffer nog naar serial dumpen, zodat je op je pc kunt zien of het doet wat je verwacht.
Dat kun je later eenvoudig aan en uitzetten (om verder te debuggen) door er commentaar regels van te maken.

Je gebruikt nu in 2 functies (loop en checkAccess) telkens de variabele 'buffer'.
Dat kan ook want het is de bedoeling dat die vluchtig zijn.
Alleen bestaat zo de kans dat je er zelf van in de war raakt, en daarom is het raadzaam ze een unieke naam te geven.

Ik zie ook dat het commentaar in regel 50 in ieder geval niet klopt, want is die regel wordt er alleen geteld en niets gecontroleerd.
Dat zeg ik niet om te zeuren, maar omdat commentaar alleen zinvol is als het ook klopt.

Met dit antwoord is jouw probleem niet opgelost, maar je kunt wel wat nader onderzoeken of de sketch doet wat jij er van verwacht dankzij serial.
Serial is een krachtig debug middel wanneer je het goed weet toe te passen.

Dankjewel voor je reactie!
Inmiddels heb ik de code werkend gekregen en kan ik verder gaan met het hardware matige gedeelte van mij project.

De oplossing welke ik heb toegepast is misschien een beetje slordig, maar het is voor een persoonlijk huis, tuin, keuken project, dus hier maak ik mij niet te druk om.

Het probleem lag dus bij de variabele welke de opgeslagen ID nummers lijst moest koppelen aan de CheckAccess functie, op de een of andere manier nam de variabele het nummer niet juist over.
Hierdoor werd dus ook het nummer steeds niet juist herkend.

Om dit op te lossen heb ik de lijst met ID codes gewoon verplaatst naar de plaats van de CheckAccess, zodat hier dus direct de controle op uitgevoerd wordt.
De oplossing is een beetje simpel minder en het maakt het toevoegen van meerder ID's een beetje meer zoekwerk, maar het werkt wel :wink:

Hieronder staat de nieuwe werkende code (betreft voornamelijk vanaf regel 204), + volledig afgerond voor mijn project.

#include <SoftwareSerial.h>
#include <Adafruit_GFX.h>
#include <PWMServo.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeMonoBoldOblique24pt7b.h>

#define SCREEN_WIDTH 128 //OLED diplay breedte in pixels
#define SCREEN_HEIGHT 64 //OLED display hoogte in pixels
#define OLED_RESET     -1 //Reset pin nummer
#define SCREEN_ADDRESS 0x3C //I2C address van het display
#define bitmap_height   128 //Hoogte van de bitmap afbeelding in pixels
#define bitmap_width    64 //Breedte van de bitmap afbeelding in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

PWMServo myservo; //Servo object aanmaken
 
SoftwareSerial SoftSerial(2, 3); //I2C Pins bepalen voor data van de RFID lezer
unsigned char buffer[64]; //Buffer voor de data ontvangen van de RFID lezer
unsigned char str[16]; //Variabele voor ID code
int count = 0; //Variabele leeg maken

PWMServo lockServo;
int pos = 100; //Start positie van de Servo op "Open", (in geval van storing zal de sluiting open gaan bij spanningsreset)

int redLED = 6; //Pin locatie bepalen voor rode LED
int greenLED = 7; //Pin loactie bepalen voor groene LED

byte redledstate = LOW; //I/O status voor de rode LED genereren
byte greenledstate = LOW;//I/O status van de groene LED genereren

static const unsigned char PROGMEM yes[] = //Bitmap code voor afbeelding van een vinkje
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xF0, 0x07, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFF, 0x00, 0x00, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFC, 0x00, 0x00, 0x1F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xF0, 0x00, 0x00, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xC0, 0x00, 0x00, 0x03, 0xC7, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x01, 0x8F, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xF0, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xF0, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x3F, 0xFE, 0x30, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x38, 0x00, 0x00, 0x7F, 0xFC, 0x70, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x7C, 0x00, 0x00, 0xFF, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0xFE, 0x00, 0x01, 0xFF, 0xF0, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1F, 0x01, 0xFF, 0x00, 0x03, 0xFF, 0xE0, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1F, 0x01, 0xFF, 0x80, 0x07, 0xFF, 0xC0, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1F, 0x03, 0xFF, 0xC0, 0x0F, 0xFF, 0x80, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1F, 0x03, 0xFF, 0xC0, 0x0F, 0xFF, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1F, 0x03, 0xFF, 0xE0, 0x1F, 0xFF, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1F, 0x03, 0xFF, 0xF0, 0x3F, 0xFE, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1F, 0x01, 0xFF, 0xF8, 0x7F, 0xFC, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0xFF, 0xFC, 0xFF, 0xF8, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x7F, 0xFE, 0xFF, 0xF0, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x3F, 0xFF, 0xFF, 0xF0, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x1F, 0xFF, 0xFF, 0xE0, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x0F, 0xFF, 0xFF, 0xC0, 0x01, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x07, 0xFF, 0xFF, 0x80, 0x01, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x03, 0xFF, 0xFF, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x01, 0xFF, 0xFF, 0x00, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x00, 0xFF, 0xFE, 0x00, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x00, 0x7F, 0xFC, 0x00, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xF0, 0x00, 0x3F, 0xFC, 0x00, 0x0F, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xF8, 0x00, 0x1F, 0xF8, 0x00, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x0F, 0xF0, 0x00, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x07, 0xE0, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x03, 0xE0, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0xC0, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xC0, 0x00, 0x00, 0x01, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x07, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xF8, 0x00, 0x00, 0x1F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFE, 0x00, 0x00, 0x7F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xC0, 0x03, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static const unsigned char PROGMEM no[] = //Bitmap code voor afbeelding van een kruisje
{ 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFC, 0x0F, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xC0, 0x00, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFE, 0x00, 0x00, 0x3F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xF0, 0x00, 0x00, 0x07, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xC0, 0x00, 0x00, 0x01, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x80, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x0F, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x1F, 0x80, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x3F, 0xC0, 0x00, 0x3E, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x7F, 0xC0, 0x00, 0x7F, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xF0, 0xFF, 0xC0, 0x00, 0xFF, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xF0, 0xFF, 0xE0, 0x01, 0xFF, 0x83, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xF0, 0xFF, 0xE0, 0x03, 0xFF, 0x83, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0xFF, 0xF0, 0x07, 0xFF, 0x81, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x7F, 0xF8, 0x0F, 0xFF, 0x81, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x7F, 0xF8, 0x1F, 0xFF, 0x01, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x1F, 0xFE, 0x7F, 0xFC, 0x01, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x1F, 0xFF, 0xFF, 0xF8, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x0F, 0xFF, 0xFF, 0xF0, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x07, 0xFF, 0xFF, 0xC0, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x07, 0xFF, 0xFF, 0x80, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x03, 0xFF, 0xFF, 0x80, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x01, 0xFF, 0xFF, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x00, 0xFF, 0xFE, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x00, 0x7F, 0xFC, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x00, 0x7F, 0xFC, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x00, 0xFF, 0xFE, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x01, 0xFF, 0xFF, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x03, 0xFF, 0xFF, 0x80, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x07, 0xFF, 0xFF, 0x80, 0x01, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xC0, 0x0F, 0xFF, 0xFF, 0xC0, 0x01, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x3F, 0xFF, 0xFF, 0xF0, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x7F, 0xF9, 0xFF, 0xF8, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0xF0, 0xFF, 0xF0, 0xFF, 0xFC, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xF1, 0xFF, 0xE0, 0x7F, 0xFE, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xF1, 0xFF, 0xC0, 0x3F, 0xFE, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xF3, 0xFF, 0xC0, 0x1F, 0xFE, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xE7, 0xFF, 0xC0, 0x0F, 0xFE, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x4F, 0xFF, 0x80, 0x07, 0xFC, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0x00, 0x01, 0xFC, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFE, 0x00, 0x00, 0xF8, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFC, 0x00, 0x00, 0x60, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xF8, 0x00, 0x00, 0x01, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xF8, 0x00, 0x00, 0x07, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xF0, 0x00, 0x00, 0x0F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xC7, 0xC0, 0x00, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x87, 0xFE, 0x3F, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup()
{
  myservo.attach(SERVO_PIN_A); //Pin locatie bepalen voor aansturing van de servo
  SoftSerial.begin(9600); //The SoftSerial baud rate
  Serial.begin(9600); //The Serial port of Arduino baud rate
  pinMode(redLED, OUTPUT); //PinMode bepalen voor de Pin van de rode LED
  pinMode(greenLED, OUTPUT); //PinMode bepalen voor de Pin van de groene LED
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Conecctie maken met het display D.M.V. I2C
  display.clearDisplay(); //Display leeg maken (stand-by maken)
  display.display(); //Laatste commando uitvoeren op display
}

void loop()
{
    //Als er data over de serial port komt dan data in variable opslaan
    if (SoftSerial.available())              
    {
        while(SoftSerial.available()) //Data opslaan in variabele
        {
            buffer[count++] = SoftSerial.read(); //Data schrijven...
            String buffer = "";
            for (int i = 0; i < 4; i++)
            {
              buffer = buffer + (0x0F & (str[i] >> 4));
              buffer = buffer + (0x0F & str[i]);
            }
            if(count == 64)break;
        }
        Serial.print("The card's ID number is : ");
        Serial.write(buffer, count); //wanneer data schrijven ophoud, doorzetten en schrijven naar de serial monitor
        checkAccess (buffer); //Functie oproepen om ID te controleren
        clearBufferArray(); //Functie oproepen om de variabele van de ID code weer leeg te maken
        count = 0; //Counter weer op "0" zetten
    }
    if (Serial.available()) //if data is available on hardware serial port ==> data is coming from PC or notebook
    SoftSerial.write(Serial.read()); //write it to the SoftSerial shield
    
}
void checkAccess (String buffer)
{
    if(buffer == "750069FA9F79", "750069FBC720") //Als een van de ID's aanwezig zijn, voer onderstaande uit
      for(pos = 1; pos < 100; pos += 1) { //Positie van de servo aanpassen naar "open"
        myservo.write(pos); //Servo commando uitvoeren
        delay(5); //vertraging
      }
      welkomsbericht(); //Funtie voor welkomsbericht oproepen
      display.clearDisplay(); //Na welkomsbericht display weer op stand-by zetten
      display.display(); //Laatste commando uitvoeren op display
      for(pos = 100; pos>=1; pos-=1) { //Servo positie weer terug zetten naar "gesloten"
        myservo.write(pos); //Servo commando uitvoeren
        delay(5); //vertraging
      }
    }
    else //Functie voor siatuatie waar de ID code niet is herkend
    {
      Serial.println (" Toegang geweigerd");
      toeganggeweigerd(); //Functie toeganggeweigerd oproepen
      display.clearDisplay(); //Display weer op stand-by zetten
      display.display(); //Laatste commando op display uitvoeren
    }
}

void showBitmapyes(void) { //Bitmap afbeelding van "vinkje" weergeven
  display.clearDisplay();
  display.drawBitmap(0, 0, yes, bitmap_height, bitmap_width, WHITE);
  display.display();
}

void showBitmapno(void) { //Bitmap afbeelding van "kruisje" weergeven
  display.clearDisplay();
  display.drawBitmap(0, 0, no, bitmap_height, bitmap_width, WHITE);
  display.display();
}

void welkomsbericht() { //Functie van het welkomsbericht, incl. de groene LED aansturen
  showBitmapyes();
  greenledstate = HIGH;
  digitalWrite(greenLED, greenledstate);
  delay(100);
  greenledstate = LOW;
  digitalWrite(greenLED, greenledstate);
  delay(100);
  greenledstate = HIGH;
  digitalWrite(greenLED, greenledstate);
  delay(100);
  greenledstate = LOW;
  digitalWrite(greenLED, greenledstate);
  delay(100);
  greenledstate = HIGH;
  digitalWrite(greenLED, greenledstate);
  delay(100);
  greenledstate = LOW;
  digitalWrite(greenLED, greenledstate);
  delay(100);
  greenledstate = HIGH;
  digitalWrite(greenLED, greenledstate);
  delay(400);
  display.clearDisplay();
  display.display();

  display.setTextSize(3);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(10,13);
  display.println(F("Welkom"));

  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(30,40);
  display.println(F("Artur!"));
  display.display();

  delay(4600);
  greenledstate = LOW;
  digitalWrite(greenLED, greenledstate);
}

void toeganggeweigerd() { //Functie van toegang geweigerd, incl. de rode LED aansturen
  showBitmapno();
  redledstate = HIGH;
  digitalWrite(redLED, redledstate);
  delay(100);
  redledstate = LOW;
  digitalWrite(redLED, redledstate);
  delay(100);
  redledstate = HIGH;
  digitalWrite(redLED, redledstate);
  delay(100);
  redledstate = LOW;
  digitalWrite(redLED, redledstate);
  delay(100);
  redledstate = HIGH;
  digitalWrite(redLED, redledstate);
  delay(100);
  redledstate = LOW;
  digitalWrite(redLED, redledstate);
  delay(100);
  redledstate = HIGH;
  digitalWrite(redLED, redledstate);
  delay(400);
  display.clearDisplay();
  display.display();

  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(40,3);
  display.println(F("GEEN"));

  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(20,20);
  display.println(F("TOEGANG!"));

  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(8,44);
  display.println(F("BEL TELEFOONNUMMER:"));

  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(30,55);
  display.println(F("06 12185245"));
  display.display();

  delay(3600);
  redledstate = LOW;
  digitalWrite(redLED, redledstate);
}

void clearBufferArray() // function to clear buffer array
{
    // clear all index of array with command NULL
    for (int i=0; i<count; i++)
    {
        buffer[i]=NULL;
    }                  
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.