CIPAD 40. Comment gérer plusieurs mots de passe, protéger 9 casiers et 9 clients. Arduino C++

4 min read 19 hours ago
Published on Oct 02, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial guides you through setting up a secure system to manage multiple passwords for nine lockers using Arduino and C++. Each locker is protected by a unique Personal Identification Number (PIN), along with a master PIN for overall access. This project is ideal for beginners looking to enhance their programming skills while creating a practical security solution.

Step 1: Gather Your Components

Before starting, ensure you have the following components:

  • Arduino board (e.g., Arduino Uno)
  • 4x4 keypad
  • LCD display (I2C preferred)
  • 9 lock mechanisms (can be electronic locks or servos)
  • Jumper wires
  • Breadboard
  • Power supply (if needed)

Practical Advice

  • Verify compatibility of components with your Arduino model.
  • Consider using a solderless breadboard for easy connections.

Step 2: Set Up the Hardware

  1. Connect the Keypad:

    • Connect the rows and columns of the 4x4 keypad to the Arduino pins.
    • Use the following common connections:
      • Row pins to Arduino digital pins 2-5.
      • Column pins to Arduino digital pins 6-9.
  2. Connect the LCD Display:

    • Use I2C interface for easier wiring.
    • Connect the SDA and SCL pins from the LCD to the Arduino (typically A4 and A5 for Uno).
  3. Connect the Lock Mechanisms:

    • Connect each lock mechanism to a separate digital pin on the Arduino.
    • Ensure the power supply matches the requirements of your locks.

Practical Advice

  • Double-check all connections to avoid short circuits.
  • Use color-coded wires for easier identification.

Step 3: Install Required Libraries

To communicate with the keypad and LCD, you'll need to install specific libraries in your Arduino IDE:

  • Keypad library
  • LiquidCrystal_I2C library

Installation Steps

  1. Open the Arduino IDE.
  2. Go to Sketch > Include Library > Manage Libraries.
  3. Search for "Keypad" and "LiquidCrystal I2C" and install them.

Step 4: Write the Arduino Code

Create a new sketch and include the necessary libraries. Here's a basic structure to get started:

#include <Keypad.h>
#include <LiquidCrystal_I2C.h>

const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8, 9};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Define your PINs and logic for the lockers here

void setup() {
  lcd.begin();
  lcd.backlight();
  // Initialize other components
}

void loop() {
  // Logic for handling input and unlocking lockers
}

Practical Advice

  • Make sure to define the PINs for each locker and include logic for the master PIN.
  • Comment your code for clarity.

Step 5: Implement Locking Logic

  1. Define PINs for Each Locker:

    • Create an array to store the PINs for each of the nine lockers and the master PIN.
  2. Handle User Input:

    • Use loops to read input from the keypad and compare it against stored PINs.
    • Display messages on the LCD to indicate success or failure.
  3. Control Lock Mechanisms:

    • Use digitalWrite to activate or deactivate the lock mechanisms based on the correct PIN input.

Example Code Snippet

String lockerPins[9] = {"1234", "2345", "3456", "4567", "5678", "6789", "7890", "8901", "9012"};
String masterPin = "0000";
// Add logic for checking PINs and unlocking

Conclusion

In this tutorial, you learned how to set up a secure locker system using Arduino, where each locker is protected by a unique PIN and a master PIN. This project not only enhances your programming skills but also provides a practical application for security management.

Next Steps

  • Experiment with adding features, such as changing PINs or logging access attempts.
  • Consider integrating a real-time clock (RTC) module for timestamped access logs.
  • Explore advanced security measures, like biometric authentication.