wiegand reads the card only one time, why?

Hello every one,
I’m trying to create a setup with uno, step motor, tcrt500, ultrasonic sensor and a wiegand rfid reader.
Here is the code I wrote by the help of examples;

//inculde library
#include <unistep.h>
#include <Wiegand.h>

WIEGAND wg;
//
//create a stepper instance
unistep stepper(4,5,6,7,4096,900);
//
//for serial
int incomingByte;
//sensor1 analog pin 0 - A4 
int sensorPin = A4; 
//ultrasound pins
#define trigPin A3
#define echoPin A2

void setup() 
{
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  Serial.begin(9600);  
  wg.begin();
}

void loop() 
{
   if(wg.available())
  {
      if(wg.getCode() == 1234567)
      {
           stepper.moves(5300,0);
           delay(5000);
      }
  }
   int deger = analogRead(sensorPin);
   Serial.println (deger);
   if(deger < 800)
   {
      Serial.println ("OPENED");
   }
   if(deger < 800)
   {
      long duration, distance;
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2); 
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10); // Added this line
      digitalWrite(trigPin, LOW);
      duration = pulseIn(echoPin, HIGH);
      distance = (duration/2) / 29.1;
      if(distance > 20)
      {
        Serial.println("NO OBJECT");
      }
      if(distance < 20)
      {
        Serial.println("OBJECT");
      }
      if(distance>20)
      {
        stepper.moves(5300,1);
      }
    }
    if(deger > 800)
    {
      Serial.println ("CLOSED");
    }
}

I’m having trouble with wiegand. It reads the card only one time. Motor turns. Sensors read the values and then motor turns to the oppsite. But after first read, wiegand doesn’t read any card.
I searched for different projects but I couldn’t find the reason for this problem.

Will it read card 1234567? This is the only card that will cause anything to happen.

Use serial print to output messages to follow where your program is. "Have read card", "program is at this point" type messages. If you don't get a message wher you expected it, check your code for why.

Weedpharma

{
   if(wg.available())
  {
      if(wg.getCode() == 1234567)
      {
           stepper.moves(5300,0);
           delay(5000);
      }
  }

This part is for rotation of motor

I think you have to change your code .Write rotation condition with sensor.

if(distance < 20)

weedpharma:
Will it read card 1234567? This is the only card that will cause anything to happen.

Use serial print to output messages to follow where your program is. “Have read card”, “program is at this point” type messages. If you don’t get a message wher you expected it, check your code for why.

Weedpharma

I don’t have any problem with other codes such as test code to get the id number or to light the led 13. There is a led on wiegan card that lights whlie it reads a card. This led lights when wiegan reads any card for the first time. But after that, led doesn’t light. So card reads only one time with this code. It doen’t matter if you try to read same card or different. It doesn’t read.

chinmoyrick:

{

if(wg.available())
 {
     if(wg.getCode() == 1234567)
     {
          stepper.moves(5300,0);
          delay(5000);
     }
 }




This part is for rotation of motor

I think you have to change your code .Write rotation condition with sensor. 



if(distance < 20)

But I need to operate the motor with rfid.

I couldn't find a solution yet.