Arduino Fingerprint Sensor & Solenoid Lock w/LCD
How to build and code with an AI assistant
Components and supplies
1
I2C LCD 1602 Module
1
Buzzer, Piezo
1
Resistor 330 ohm
1
Jumper wires (generic)
1
HiLetgo 2pcs 5V One Channel Relay Module Relay Switch with OPTO Isolation High Low Level Trigger
1
5mm Green LED
1
Optical Fingerprint Reader Sensor Module
1
5mm Red LED
1
ATOPLEE Electromagnetic Solenoid Lock
1
Arduino UNO Wifi Rev.2
1
UCTRONICS DC 9V 12V 24V 36V 5A Variable Voltage Power Supply
Apps and platforms
1
Arduino IDE 2.0 (beta)
1
Google Gemini Advanced
Project description
Code
VTM_Finger_LCD
cpp
Fingerprint Access Control System
1/* 2 Fingerprint Access Control System 3 Code Created by Spark - VideotronicMaker's Personal AI Assistant 4 AI directed by VideotronicMaker 5 Date: May 5, 2024 6 7 Description: 8 This Arduino sketch uses an Adafruit Fingerprint sensor to authenticate users via fingerprints. 9 When an authorized fingerprint is detected, a relay is activated, a green LED lights up, 10 and a success message is displayed on the LCD; if unauthorized, a red LED lights up 11 and an error message is displayed along with a stop sign animation. 12 The sketch is designed to demonstrate basic fingerprint sensor usage with Arduino for educational purposes. 13 14 License: 15 This work is licensed under the MIT License. You are free to use, modify, and distribute 16 this software in any medium, provided that the above copyright notice and this permission 17 notice are included with all copies. 18 19 Connections: 20 - Fingerprint Sensor: 21 - VCC to Arduino 5V - Power supply for the fingerprint sensor. 22 - GND to Arduino GND - Common ground for power and signal. 23 - RX (White wire) to Arduino digital pin 3 (TX of SoftwareSerial) - Receives data from the Arduino. 24 - TX (Green wire) to Arduino digital pin 2 (RX of SoftwareSerial) - Sends data to the Arduino. 25 26 - LCD Display (I2C): 27 - SDA to Arduino A4 - Serial Data for I2C communication. 28 - SCL to Arduino A5 - Serial Clock for I2C communication. 29 - VCC to Arduino 5V - Power supply for the LCD. 30 - GND to Arduino GND - Common ground for power and signal. 31 32 - LEDs: 33 - Connect the anode of the red LED directly to Arduino pin 10 34 - Connect the anode of the green LED directly to Arduino pin 9 35 - Connect the cathode of the red LED to a 330-ohm resistor, then connect the other end of the resistor to the ground (GND) - Lights up for unauthorized access. 36 - Connect the cathode of the green LED directly to Arduino GND - Common ground for the LEDs. 37 38 - Relay: 39 - IN to Arduino pin 7 - Control pin for the relay. 40 - VCC to Arduino 5V - Power supply for the relay module. 41 - GND to Arduino GND - Common ground for the relay module. 42 43 - Buzzer: 44 - Positive to Arduino pin 8 - Outputs sound for feedback. 45 - Negative to Arduino GND - Common ground for the buzzer. 46 47 Components: 48 - Arduino Uno 49 - Adafruit Fingerprint sensor 50 - LiquidCrystal_I2C LCD display 51 - Green LED 52 - Red LED 53 - Relay module 54 - Buzzer 55 - 220-ohm resistors for each LED 56*/ 57 58#include <Wire.h> 59#include <LiquidCrystal_I2C.h> 60#include <Adafruit_Fingerprint.h> 61#include <SoftwareSerial.h> 62 63// Pin Configuration 64SoftwareSerial mySerial(2, 3); // RX, TX for fingerprint sensor 65LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD I2C address 66Adafruit_Fingerprint finger(&mySerial); // Initialize fingerprint sensor with SoftwareSerial 67 68const int buzzerPin = 8; // Buzzer pin 69const int relayPin = 7; // Relay pin 70const int greenLEDPin = 9; // Green LED pin 71const int redLEDPin = 10; // Red LED pin 72 73// Define custom characters for the stop sign and arrow animations 74byte stopSign1[8] = { 75 0b00000, 76 0b01110, 77 0b11111, 78 0b11111, 79 0b11111, 80 0b01110, 81 0b00000, 82 0b00000 83}; 84 85byte stopSign2[8] = { 86 0b00000, 87 0b00000, 88 0b01110, 89 0b11111, 90 0b11111, 91 0b01110, 92 0b00000, 93 0b00000 94}; 95 96byte arrow1[8] = { 97 0b00000, 98 0b00000, 99 0b00000, 100 0b11111, 101 0b01110, 102 0b00100, 103 0b00000, 104 0b00000 105}; 106 107byte arrow2[8] = { 108 0b00000, 109 0b00000, 110 0b11111, 111 0b11111, 112 0b01110, 113 0b00100, 114 0b00000, 115 0b00000 116}; 117 118void setup() { 119 // Initialize Serial Monitor for debugging 120 Serial.begin(9600); 121 122 // Initialize the LCD 123 lcd.init(); 124 lcd.backlight(); 125 lcd.setCursor(0, 0); 126 lcd.print("VideotronicMaker"); // Display welcome message on the LCD 127 lcd.setCursor(0, 1); 128 lcd.print("Touch Sensor"); 129 130 // Set pin modes for LED, buzzer, and relay 131 pinMode(buzzerPin, OUTPUT); 132 pinMode(relayPin, OUTPUT); 133 pinMode(greenLEDPin, OUTPUT); 134 pinMode(redLEDPin, OUTPUT); 135 136 // Initialize the fingerprint sensor 137 mySerial.begin(57600); // Start SoftwareSerial for fingerprint sensor 138 finger.begin(57600); // Start communication with the fingerprint sensor 139 140 // Check if the fingerprint sensor is connected properly 141 if (finger.verifyPassword()) { 142 lcd.setCursor(0, 1); 143 lcd.print(" "); // Clear the line 144 lcd.setCursor(0, 1); 145 lcd.print("Sensor ready"); // Display sensor ready message 146 Serial.println("Fingerprint sensor is ready."); // Output to Serial Monitor 147 } else { 148 lcd.setCursor(0, 1); 149 lcd.print(" "); // Clear the line 150 lcd.setCursor(0, 1); 151 lcd.print("Init error"); // Display initialization error 152 Serial.println("Fingerprint sensor initialization failed."); // Output to Serial Monitor 153 } 154 155 // Create custom characters for animations 156 lcd.createChar(0, stopSign1); 157 lcd.createChar(1, stopSign2); 158 lcd.createChar(2, arrow1); 159 lcd.createChar(3, arrow2); 160 161 delay(2000); // Display initial message for 2 seconds 162 resetState(); 163} 164 165void loop() { 166 // Default state: Show "VideotronicMaker" on the LCD 167 lcd.setCursor(0, 0); 168 lcd.print("VideotronicMaker"); 169 lcd.setCursor(0, 1); 170 lcd.print("Touch Sensor"); 171 172 // Check if a finger is placed on the sensor 173 if (finger.getImage() == FINGERPRINT_OK) { 174 int id = getFingerprintIDez(); 175 if (id == -1) { 176 handleAccessDenied(); // Unauthorized access 177 } else { 178 handleAccessGranted(); // Authorized access 179 } 180 181 // Reset state after handling access 182 resetState(); 183 } 184 185 delay(100); // Small delay to avoid overwhelming the sensor 186} 187 188void handleAccessDenied() { 189 // Handle unauthorized access 190 digitalWrite(relayPin, LOW); // Turn off relay 191 digitalWrite(redLEDPin, HIGH); // Turn on red LED 192 digitalWrite(greenLEDPin, LOW); // Turn off green LED 193 lcd.clear(); 194 lcd.setCursor(0, 0); 195 lcd.print("Access Denied"); 196 Serial.println("Access Denied - Unauthorized fingerprint."); // Output to Serial Monitor 197 198 // Animate stop sign 199 for (int i = 0; i < 16; i++) { 200 lcd.setCursor(i, 1); 201 lcd.write(byte(i % 2)); // Cycle through stop sign characters 202 delay(150); 203 } 204 205 // Sound buzzer for denied access 206 for (int i = 0; i < 3; i++) { 207 tone(buzzerPin, 1000, 200); // Beep three times quickly 208 delay(300); // Wait for 300ms between beeps 209 } 210 delay(2000); // Display "Access Denied" for 2 seconds 211} 212 213void handleAccessGranted() { 214 // Handle authorized access 215 digitalWrite(relayPin, HIGH); // Turn on relay 216 digitalWrite(redLEDPin, LOW); // Turn off red LED 217 digitalWrite(greenLEDPin, HIGH); // Turn on green LED 218 lcd.clear(); 219 lcd.setCursor(0, 0); 220 lcd.print("Access Granted"); 221 Serial.println("Access Granted - Authorized fingerprint."); // Output to Serial Monitor 222 tone(buzzerPin, 1000, 3000); // Beep for 3 seconds straight 223 224 // Animate progress arrows 225 for (int i = 0; i < 16; i++) { 226 lcd.setCursor(i, 1); 227 lcd.write(byte(2 + (i % 2))); // Cycle through arrow characters 228 delay(150); 229 } 230 231 delay(3000); // Display "Access Granted" for 3 seconds 232} 233 234void resetState() { 235 // Reset to default state 236 digitalWrite(relayPin, LOW); // Turn off relay 237 digitalWrite(redLEDPin, LOW); // Turn off red LED 238 digitalWrite(greenLEDPin, LOW); // Turn off green LED 239 lcd.clear(); 240 lcd.setCursor(0, 0); 241 lcd.print("VideotronicMaker"); 242 lcd.setCursor(0, 1); 243 lcd.print("Touch Sensor"); 244 delay(2000); // Display the default message for 2 seconds before next scan 245} 246 247// Helper function to get a fingerprint ID 248int getFingerprintIDez() { 249 uint8_t p = finger.image2Tz(); 250 if (p != FINGERPRINT_OK) return -1; 251 252 p = finger.fingerFastSearch(); 253 if (p != FINGERPRINT_OK) return -1; 254 255 // Found a match! 256 Serial.print("Fingerprint ID: "); // Output to Serial Monitor 257 Serial.println(finger.fingerID); // Output to Serial Monitor 258 return finger.fingerID; 259}
Documentation
Layout
Visual for how to connect it all
layout.png

Comments
Only logged in users can leave comments