IOT
🔑 Arduino Password System with Buzzer Alert
A simple Arduino project that checks a password via Serial Monitor and alerts with a buzzer if incorrect.
📌 Code
int buzzerPin = 10;
String password = "1234";
String inputPassword = "";
void setup() {
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
Serial.println("Enter password:");
}
void loop() {
if (Serial.available()) {
inputPassword = Serial.readStringUntil('\n');
inputPassword.trim();
if (inputPassword == password) {
Serial.println("Access Granted");
} else {
Serial.println("Wrong Password!");
wrongPasswordBeep();
}
}
}
void wrongPasswordBeep() {
for (int i = 0; i < 3; i++) {
digitalWrite(buzzerPin, HIGH);
delay(200);
digitalWrite(buzzerPin, LOW);
delay(200);
}
}
📖 Explanation
1. Variable Setup
- buzzerPin → Pin number where the buzzer is connected.
- password → The fixed correct password ("1234").
- inputPassword → Stores user input from Serial Monitor.
2. setup() Function
- Configures buzzer pin as output.
- Starts serial communication at 9600 baud.
- Prompts user to enter a password.
3. loop() Function
- Checks if user typed something in Serial Monitor.
- Reads input until newline (
\n). - Compares entered password with correct one:
- If correct → prints "Access Granted".
- If wrong → prints "Wrong Password!" and calls buzzer function.
4. wrongPasswordBeep() Function
- Makes buzzer beep 3 times when password is incorrect.
- Each beep lasts 200 ms followed by 200 ms silence.
⚙️ Summary
This project is a simple password-protected system using Arduino:
- User enters a password via Serial Monitor.
- If correct → Access granted.
- If wrong → Buzzer beeps 3 times as an alert.
💡 Great for beginners learning Arduino input/output and security basics!
Comments
Post a Comment