Allan Gallop
Published © Apache-2.0

IOT2020 Access Control

Integrate a Weigand-26 RFID reader with an IOT2020 for cloud-based door access control and monitoring using Node-Red.

IntermediateFull instructions provided4 hours9,747
IOT2020 Access Control

Things used in this project

Hardware components

SIMATIC IOT2020
Siemens SIMATIC IOT2020
×1
Arduino 4 Relays Shield
Arduino 4 Relays Shield
×1
Weigand 26bit Reader
×1
12v Magnetic Lock
×1
Arduino Nano R3
Arduino Nano R3
×1
12V/29A Power Supply
OpenBuilds 12V/29A Power Supply
×1
Ethernet Cable
×1

Software apps and online services

Node-RED
Node-RED
Arduino IDE
Arduino IDE
Apache Web Server
Rufus
PuTTY

Hand tools and fabrication machines

Wire Strippers
Screw Driver

Story

Read more

Schematics

Node Red Template

Basic blocks here are quite simple, our first input is a Serial block listening to our arduino via ttyS0, upon reading a card number it is formatted as a GET request and sent to our webserver. Depending on the response from the server (bit value) we trigger the lock & green LED on the reader panel or the trigger a pulse to the red LED

Arduino (Weigand - Serial) layout

Connect pins 1&2 (Serial Tx/Rx) to pin 1&2 of the relay shield [IOT2020]. Pins 2&3 connect to the reader clock and data pins respectfully.

Relay Shield Connections

PHP Sample Script

Code

Arduino (Weigand - Serial) Convertor

Arduino
Arduino sketch for converting Weigand 26bit to serial logic for use with the IOT2020. Based on work by Daniel Smith (www.pagemac.com)
/*
 * HID RFID Reader Wiegand Interface for Arduino Uno
 * Written by Daniel Smith, 2012.01.30
 * www.pagemac.com
 *
 */
 
 
#define MAX_BITS 100                // max number of bits
#define WEIGAND_WAIT_TIME  3000      // time to wait for another weigand pulse. 
 
unsigned char databits[MAX_BITS];    // stores all of the data bits
unsigned char bitCount;              // number of bits currently captured
unsigned char flagDone;              // goes low when data is currently being captured
unsigned int weigand_counter;        // countdown until we assume there are no more bits
 
unsigned long facilityCode=0;        // decoded facility code
unsigned long cardCode=0;            // decoded card code
 
void ISR_INT0()
{
  bitCount++;
  flagDone = 0;
  weigand_counter = WEIGAND_WAIT_TIME; 
 
}
 
void ISR_INT1()
{
  databits[bitCount] = 1;
  bitCount++;
  flagDone = 0;
  weigand_counter = WEIGAND_WAIT_TIME; 
}
 
void setup()
{
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  pinMode(2, INPUT);     // DATA0 (INT0)
  pinMode(3, INPUT);     // DATA1 (INT1)

  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  Serial.begin(9600);

  attachInterrupt(0, ISR_INT0, FALLING); 
  attachInterrupt(1, ISR_INT1, FALLING);
 
  weigand_counter = WEIGAND_WAIT_TIME;
}
 
void loop()
{
  if (!flagDone) {
    if (--weigand_counter == 0)
      flagDone = 1; 
  }

  if (bitCount > 0 && flagDone) {
    unsigned char i;
    
    if (bitCount >= 26)
    {
      for (i=2; i<14; i++)
      {
         facilityCode <<=1;
         facilityCode |= databits[i];
      }
 
      // card code = bits 15 to 34
      for (i=74; i<100; i++)
      {
         cardCode <<=1;
         cardCode |= databits[i];
      }
 
      printBits();
    }
   
     bitCount = 0;
     facilityCode = 0;
     cardCode = 0;
     for (i=0; i<MAX_BITS; i++)
     {
       databits[i] = 0;
     }
  }
}
 
void printBits()
{
      Serial.println(cardCode);
}

Credits

Allan Gallop

Allan Gallop

0 projects • 3 followers
Engineer, systems developer and linux guy.

Comments