PCBX
Published

Crafting a Password Lock Project: An Arduino Simulation

Unlock the fun of coding! Create a secure password lock system with Arduino simulation—perfect for beginners and tech enthusiasts!

BeginnerProtip195

Things used in this project

Story

Read more

Schematics

password_lock_j76Ih1YqX3.png

Code

Password Lock

Arduino
int segmentPins[] = {2, 3, 4, 5, 6, 7, 8};
int digitPin = 9;
int buttonPin[] = {A0, A1, A2, A3, A4, A5};
int ledPin = 11;
byte numbers[10] = {
    0x3F, // 0
    0x06, // 1
    0x5B, // 2
    0x4F, // 3
    0x66, // 4
    0x6D, // 5
    0x7D, // 6
    0x07, // 7
    0x7F, // 8
    0x6F  // 9
};

int password = random(1,7);

void setup() {
    for (int i = 0; i < 7; i++) {
        pinMode(segmentPins[i], OUTPUT);
    }
    for (int j = 0; j < 6; j++) {
        pinMode(buttonPin[j], INPUT);
    }
    pinMode(digitPin, OUTPUT);
    pinMode(ledPin, OUTPUT);
}

void loop() {
    for(int i = 0; i < 7; i++){
        if(digitalRead(buttonPin[i]) == HIGH) {
            if(i + 1 == password) {  // correct
                displayNumber(password);
                password = random(1,7);
            }
        }
    }
}

void displayNumber(int num) {
    for (int i = 0; i < 7; i++)
        digitalWrite(segmentPins[i], numbers[num] & (1 << i));
    digitalWrite(digitPin, LOW);
    delay(1000);
    digitalWrite(digitPin, HIGH);
}

Credits

PCBX
33 projects • 10 followers
Customer Success: Your one-stop solution for PCB and PCBA services, plus component sourcing. Enjoy FREE online simulation and EDA.
Contact

Comments

Please log in or sign up to comment.