Arduino ticket gate – part 1

Alex is obsessed with automatic ticket gates and desperately wants one to play with in the house. Don’t ask me why.

The mechanisms in automatic paper ticket gates are extraordinarily complicated and not something I could hope or want to recreate at home. However, modern gates tend to use RFID stored value cards to trigger them.

Using parts from an Arduino education kit along with an RFID module I bought at Jaycar I was able to build a simple system that triggers a servo motor when an RFID card is tapped on the sensor. It also changes the red LED to the green and plays a sound. I put a delay in to “hold the gate open”.

The cheap RFID module seems a bit dodgy and the system often requires a few reboots to work. This is the first time I’ve soldered and used a circuit board in years. I haven’t used the Arduino much either, just following a few of the examples given in the book. Still, I’m pretty pleased with the result!

Using the Arduino is so much easier than the electronics I did at uni and as a kid.

The next step is to put it in some housing and attach a “gate” to the servo. Going to get Alex’s help to do that.

Sketch


/**
 * Ticket gate model
 * Detect RFID chip and trigger a servo
 */

#include  
#include
#include

#define SS_PIN 10
#define RST_PIN 9
#define GREEN_PIN 6
#define RED_PIN 7
#define PIEZO_PIN 8
#define SERVO_PIN 5

Servo gateServo;
int openTime = 5000;

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance.

void setup() {
  Serial.begin(9600); // Initialize serial communications with the PC
  gateServo.attach(SERVO_PIN);
  gateServo.write(90);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(RED_PIN, OUTPUT);
  pinMode(PIEZO_PIN, OUTPUT);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(RED_PIN, HIGH);
  
  SPI.begin();      // Init SPI bus
  mfrc522.PCD_Init(); // Init MFRC522 card
}

void loop() {
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }

  gateServo.write(180);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(RED_PIN, LOW);
  tone(PIEZO_PIN, 261, 100);
  delay(100);
  tone(PIEZO_PIN, 392, 200);
  delay(openTime);
  gateServo.write(90);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(RED_PIN, HIGH);
  mfrc522.PICC_HaltA();
}

Submit a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s