Built-in project · Arduino Uno R3

Fingerprint door lock on an Arduino Uno

An optical fingerprint sensor checks the finger on its glass: an enrolled one swings a servo latch open for three seconds, a stranger gets a red light. The whole build, an Arduino Uno and 3 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Intermediate Runs in your browser. Free, and no account needed.

The parts retail for about $45. On Mokxi they're free.

Step by step, with the wiring and the common mistakes: Arduino Fingerprint Sensor: Door Lock Code

Fingerprint door lock · Arduino Uno R3live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// Fingerprint door lock: an optical fingerprint sensor, a servo latch and a
// traffic light module.
//
//   pins 2, 3      SoftwareSerial: the sensor's TX into 2, its RX from 3
//   pins 12, 11, 10  the light's R, Y and G (resistors on its board)
//   pin 9          the latch servo's signal
//
// The door starts locked and red. A finger on the glass turns the light
// yellow while the sensor searches its library. An enrolled finger turns it
// green and swings the latch open for three seconds; a stranger gets the red
// light blinking. Either way the lock waits for the finger to lift before it
// looks again.

#include <Adafruit_Fingerprint.h>
#include <Servo.h>
#include <SoftwareSerial.h>

const int RED_PIN = 12, YELLOW_PIN = 11, GREEN_PIN = 10;
const int LATCH = 9;
const int LOCKED = 0, OPEN = 90;
const unsigned long OPEN_MS = 3000;

SoftwareSerial sensorSerial(2, 3);
Adafruit_Fingerprint finger(&sensorSerial);
Servo latch;

void lights(bool r, bool y, bool g) {
  digitalWrite(RED_PIN, r ? HIGH : LOW);
  digitalWrite(YELLOW_PIN, y ? HIGH : LOW);
  digitalWrite(GREEN_PIN, g ? HIGH : LOW);
}

void waitForLift() {
  while (finger.getImage() != FINGERPRINT_NOFINGER) delay(50);
}

void setup() {
  Serial.begin(9600);
  pinMode(RED_PIN, OUTPUT);
  pinMode(YELLOW_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  latch.attach(LATCH);
  latch.write(LOCKED);
  lights(true, false, false);

  finger.begin(57600);
  if (!finger.verifyPassword()) {
    Serial.println("No fingerprint sensor found");
    while (true) {
      lights(true, false, false);
      delay(200);
      lights(false, false, false);
      delay(200);
    }
  }
  finger.getTemplateCount();
  Serial.print("Sensor ready, ");
  Serial.print(finger.templateCount);
  Serial.println(" fingers enrolled");
}

void loop() {
  if (finger.getImage() != FINGERPRINT_OK) {
    delay(50);
    return;
  }
  lights(false, true, false);
  if (finger.image2Tz() != FINGERPRINT_OK) {
    lights(true, false, false);
    waitForLift();
    return;
  }

  if (finger.fingerFastSearch() == FINGERPRINT_OK) {
    Serial.print("Welcome, finger #");
    Serial.println(finger.fingerID);
    lights(false, false, true);
    latch.write(OPEN);
    delay(OPEN_MS);
    latch.write(LOCKED);
    Serial.println("Locked");
  } else {
    Serial.println("Access denied");
    for (int i = 0; i < 3; i++) {
      lights(true, false, false);
      delay(150);
      lights(false, false, false);
      delay(150);
    }
  }
  lights(true, false, false);
  waitForLift();
}

Parts list

5 parts, plus the jumper wires. They retail for about $45; on Mokxi they're free.

How it is wired

8 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • Arduino Uno R3 pin 12; Traffic light module pin R
  • Arduino Uno R3 pin 11; Traffic light module pin Y
  • Arduino Uno R3 pin 10; Traffic light module pin G
  • Arduino Uno R3 pin 9; Hobby servo pin PWM
  • Arduino Uno R3 pin 3; Fingerprint sensor, R30x / AS608 pin RX
  • Arduino Uno R3 pin 2; Fingerprint sensor, R30x / AS608 pin TX
  • Arduino Uno R3 pin 5V; Fingerprint sensor, R30x / AS608 pin VCC; Hobby servo pin VCC
  • Ground: Arduino Uno R3 pin GND; Fingerprint sensor, R30x / AS608 pin GND; Traffic light module pin GND; Hobby servo pin GND

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.