Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
PCBX
Published

Password Lock: Can You Guess the Next Randomly Generated Pas

Unlock the challenge! Guess the changing password by pressing the right switch. Test your skills and stay one step ahead!

BeginnerFull instructions provided112

Things used in this project

Story

Read more

Schematics

20241121155911_tpTjWQ1Fat.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 • 11 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.