Timed Door Lock Using 555 Timer

by Mantavya in Circuits > Arduino

47 Views, 0 Favorites, 0 Comments

Timed Door Lock Using 555 Timer

Screenshot 2024-08-26 at 6.59.32 PM.png

This project involves creating an electronic lock for your door that can be accessed using a PIN pad or an IR remote. The lock provides feedback to the user via an LCD screen and automatically locks itself if left open for 5 seconds. The project utilizes an Arduino microcontroller, a servo motor to control the lock mechanism, and various input components.

Supplies

Building the Circuit

Circuit Connections:

1. Connecting the LCD with I2C Module

  • Connect VCC of the LCD to 5V on the Arduino.
  • Connect GND of the LCD to GND on the Arduino.
  • Connect SDA of the LCD to SDA on the Arduino.
  • Connect SCL of the LCD to SCL on the Arduino.

2. Connecting the Keypad

  • Connect the row pins of the keypad to digital pins 6, 7, 8, and 9 on the Arduino.
  • Connect the column pins of the keypad to digital pins 10, 11, 12, and 13 on the Arduino.

3. Connecting the IR Receiver

  • Connect the VCC of the IR receiver to 5V on the Arduino.
  • Connect the GND of the IR receiver to GND on the Arduino.
  • Connect the OUT pin of the IR receiver to digital pin 5 on the Arduino.

4. Connecting the Servo Motor

  • Connect the control wire of the servo motor to analog pin A0 on the Arduino.
  • Connect the VCC of the servo motor to 5V on the Arduino.
  • Connect the GND of the servo motor to GND on the Arduino.

5. Connecting the 555 Timer IC

The 555 timer needs to be set up in a monostable mode to generate a pulse after 5 seconds of inactivity. Here’s how you can connect it:

  • Pin 1 (GND): Connect to GND.
  • Pin 2 (Trigger): Connect to the output pin of the Arduino (e.g., digital pin 3).
  • Pin 3 (Output): Connect to the input pin of the Arduino (A1).
  • Pin 4 (Reset): Connect to VCC.
  • Pin 5 (Control Voltage): Connect to GND through a 10nF capacitor.
  • Pin 6 (Threshold): Connect to pin 7 (Discharge).
  • Pin 7 (Discharge): Connect to one end of a timing resistor. Connect the other end of the resistor to VCC.
  • Pin 8 (VCC): Connect to 5V.

555 Timer Theory

For the purpose of this project we will be using the 555 timer in monostable mode. In monostable mode, the 555 timer outputs a single pulse of current for a certain length of time. This is sometimes referred to as a one-shot pulse. An example of this can be seen with an push button and led. With one press of the button, the LED will light up, then turn off automatically after a predetermined length of time. The time the LED stays on depends on the values of a resistor and capacitor connected to the 555 timer. The time can be calculated from the equation:

Where t is the length of the electrical output in seconds, R is the resistance of the resistor in Ohms, and C is the capacitance of the capacitor in Farads.

As you can see from the equation, the length of the electrical output can be increased by using larger resistor or capacitor values. The opposite is also true. You can get a shorter output pulse with smaller resistor or capacitor values.

THE CODE

#include <Keypad.h> //library for the keypad

#include <Servo.h> //library for the servo motor

#include <IRremote.h> //library for the ir receiver

#include <Wire.h>

#include <LiquidCrystal_I2C.h> //library for the lcd display


Servo gate; //name your servo motor

LiquidCrystal_I2C lcd(0x27, 16, 2); //define your lcd display

const byte ROWS = 4; //define the number of rows and columns in your keypad

const byte COLS = 4;

int timerout = 3; // Pin connected to the 555 timer input

int timerin = A1; // Pin connected to the 555 timer output

int angle = 0; // Variable to store the current angle of the servo

unsigned long time = 0; // Variable to store the time of the last servo movement

const unsigned long interval = 5000; // 5 seconds interval


char hexaKeys[ROWS][COLS] = {

{'1', '2', '3', 'A'},

{'4', '5', '6', 'B'},

{'7', '8', '9', 'C'},

{'*', '0', '#', 'D'}

};


byte rowPins[ROWS] = {6, 7, 8, 9};

byte colPins[COLS] = {10, 11, 12, 13};


Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);


String enteredPin = ""; // To store the entered PIN

String correctPin = "1234"; // The correct PIN


const int RECV_PIN = 5; // Pin connected to the IR receiver

IRrecv irrecv(RECV_PIN);

decode_results results;


void setup() {

lcd.init(); // Initialize the LCD

lcd.backlight();

Serial.begin(9600);

gate.attach(A0);

irrecv.enableIRIn(); // Start the IR receiver

pinMode(timerout, OUTPUT); // Set the timer output pin as output

pinMode(timerin, INPUT); // Set the timer input pin as input

gate.write(angle); // Initialize servo to the starting position

}


void loop() {

char customKey = customKeypad.getKey();


if (customKey) {

Serial.println(customKey);

enteredPin += customKey; // Append the entered key to the PIN string


// If the entered PIN length is the same as the correct PIN length

if (enteredPin.length() == correctPin.length()) {

if (enteredPin == correctPin) {

lcd.setCursor(0, 0);

lcd.print("OPEN");

Serial.println("open");

angle = 180;

gate.write(angle); // Move the servo to 180 degrees

time = millis(); // Update the last movement time

lcd.clear();

} else {

lcd.setCursor(0, 0);

lcd.print("Wrong PIN");

Serial.println("wrong PIN");

angle = 0;

gate.write(angle); // Move the servo to 0 degrees

lcd.clear();

}

enteredPin = ""; // Reset the entered PIN

}

}


// Check for IR remote signals

if (irrecv.decode(&results)) {

Serial.println(results.value, HEX); // Print the IR code received

if (results.value == 0xFFFFFFFF) { // Replace with your specific IR code

lcd.setCursor(0, 0);

Serial.println("IR remote button pressed, open");

lcd.print("OPEN");

angle = 180;

gate.write(angle); // Move the servo to 180 degrees

time = millis(); // Update the last movement time

lcd.clear();

}

irrecv.resume(); // Receive the next value

}


// Check if 5 seconds have passed since the last movement

if (millis() - time >= interval && angle != 0) {

Serial.println("Timer expired, returning servo to 0");

angle = 0;

gate.write(angle); // Move the servo to 0 degrees

}


// Check the 555 timer output separately

if (digitalRead(timerin) == HIGH && angle != 0) {

Serial.println("555 timer signal detected, returning servo to 0");

angle = 0;

gate.write(angle); // Move the servo to 0 degrees

}

Final Look and Setup

Screenshot 2024-06-18 at 8.11.42 AM.png
Screenshot 2024-06-18 at 8.11.50 AM.png

finally set up your lock in a safe of its own. You can make your own safe using cardboard or using a more robust material like wood.