Arduino final year projects, NO IOT : Smart Home , Smart parking and Safe lock system.

 Arduino final year projects, NO IOT : Smart Home , Smart parking and Safe lock system. 

📘 General Introduction 

Welcome to this hands-on Arduino project article, where we explore real-world applications of microcontrollers through three practical and educational projects. Whether you're a student, hobbyist, or DIY enthusiast, this book offers you a solid foundation in Arduino-based electronics and embedded systems. 

Each chapter walks you through a unique project that integrates multiple components and sensors: 

  • Gas Detection and Safety Response System: Uses gas sensors, servos, and an LCD to detect and respond to gas leaks. 

  • Parking Spot Monitor with Shift Register: Demonstrates how to use a 74HC165 shift register to monitor multiple parking spots using minimal Arduino pins. 

  • Keypad-Protected Safe Lock: Implements a digital locking mechanism using a 4x4 keypad, LCD, and a servo motor to secure a compartment. 

These projects are designed not only to demonstrate individual component usage (like sensors, servos, and LCDs) but also to show how they can work together in more complex, interactive systems. You will learn pin configurations, logical flow, and basic embedded programming techniques, giving you confidence to expand and customize these systems further. 

All components are simulated using accessible platforms, and every step is explained clearly, making this book a perfect companion for both learning and tinkering. 

 

 

Contents 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Smart Home with Arduino 

Introduction 

Automated Home Safety and Parking System Using Arduino – Smart Gas Leak Detection & Parking Automation 

Enhance home safety and automation with an Arduino-based Automated Home Safety and Parking System that integrates gas leak detection, real-time temperature and humidity monitoring, and automatic parking assistance. This smart home automation project utilizes MQ gas sensors for instant gas leak detection, DHT11 sensors for environmental monitoring, and an RTC module for accurate time tracking. The system features an automatic parking gate, which operates via IR sensors, detecting vehicles and controlling servo motors for a seamless hands-free parking experience. Real-time updates, including gas alerts, temperature, humidity levels, and parking status, are displayed on an LCD screen. Ideal for IoT and smart home security, this Arduino safety system ensures home efficiency, real-time hazard prevention, and parking automation, with potential enhancements like buzzer alerts, Wi-Fi connectivity, and battery backup for uninterrupted operation.How This System Works 

The project is designed to provide two major functionalities: 

  1. Home Safety Automation – Detects gas leaks in different rooms and automatically triggers a water sprinkler system. 

  1. Parking Assistance – Automatically detects vehicles and opens/closes the parking gate accordingly. 

All actions are displayed on an LCD screen, ensuring that users can monitor system updates in real time. 

Outputs and inputs 

Component 

Pin 

Direction 

Function 

LCD (RS) 

13 

Output 

LCD Register Select 

LCD (Enable) 

12 

Output 

LCD Enable 

LCD (D4) 

11 

Output 

LCD Data Line 4 

LCD (D5) 

10 

Output 

LCD Data Line 5 

LCD (D6) 

9 

Output 

LCD Data Line 6 

LCD (D7) 

8 

Output 

LCD Data Line 7 

Servo - Gate 

A2 

Output 

Controls gate motor 

Servo - Room 1 Gas 

A3 

Output 

Activates water sprinkler for Room 1 

Servo - Room 2 Gas 

A1 

Output 

Activates water sprinkler for Room 2 

DHT11 Sensor 

A0 

Input 

Reads temperature and humidity 

Gas Sensor - Room 1 

3 

Input 

Detects gas (Interrupt enabled) 

Gas Sensor - Room 2 

4 

Input 

Detects gas 

IR Sensor (Parking) 

2 

Input 

Detects presence of a car 

RTC (DS3231) 

SDA/SCL 

I2C (A4/A5) 

Communicates via I2C 

 

 

 

 

 

 

Schematic 

 

Forme 

Key Components and Their Roles 

To achieve this automation, the system incorporates several key components. Below is an overview of their functionalities: 

1. LCD Display (16x2) 

  • Displays real-time environmental data (temperature, humidity, and time). 

  • Provides parking status updates (whether a parking spot is occupied or free). 

  • Shows alerts for gas leaks in Room 1 or Room 2. 

2. Servo Motors 

  • Gate Servo (A2): Controls the parking gate, opening it when a car is detected. 

  • Gas Servo 1 (A3) & Gas Servo 2 (A1): Activate water sprinklers in case of a gas leak. 

3. Gas Leak Detection (MQ Gas Sensors) 

  • Room 1 (Interrupt-Based on PIN 3) 

  • Uses an interrupt mechanism to detect gas leaks instantly. 

  • Triggers an emergency response if a gas leak is detected. 

  • Room 2 (Polled on PIN 4) 

  • The sensor is continuously checked in the loop. 

  • If a leak is detected, the system responds accordingly. 

  • Response Mechanism 

  • When gas is detected in any room, the system: 

  • Displays a gas leak alert on the LCD screen. 

  • Triggers the water sprinklers to minimize hazards. 

4. IR Sensor for Parking Spot Detection 

  • Pin 2: Detects if a car is present. 

  • If a car is detected: 

  • The gate servo opens the parking gate. 

  • After a short delay, it closes automatically. 

5. DHT11 Temperature and Humidity Sensor 

  • Measures environmental temperature and humidity. 

  • Displays data on the LCD screen. 

  • If the humidity sensor malfunctions, it reports "Err" to notify the user. 

6. RTC (Real-Time Clock - DS3231) 

  • Keeps track of real-time updates. 

  • If power is lost, it resets to the compilation time. 

 
 

 
 
 

Forme 

System Workflow 

Setup Phase 

During system initialization, the Arduino performs the following tasks: 

  • Initializes the LCD, sensors, servos, RTC, and interrupt handlers. 

  • Displays “RTC Error!” if the clock module is not detected. 

Loop Phase (Continuous Monitoring & Response) 

This phase consists of continuous monitoring and real-time responses: 

1. Environmental Monitoring 

  • Reads temperature and humidity from the DHT11 sensor. 

  • Fetches the current time from the RTC module. 

2. Gas Leak Detection 

  • Room 1 (Interrupt-based detection) – Ensures instant response to gas leaks. 

  • Room 2 (Polling-based detection) – Constantly checks for a gas leak within the loop. 

When a gas leak is detected: 

  • Displays "GasLeakRoomX" on the LCD. 

  • Triggers and deactivates water sprinklers twice to reduce risks. 

3. Parking Automation 

  • The IR sensor (PIN 2) detects vehicles: 

  • Opens the gate when a car is detected. 

  • Closes automatically after a brief delay. 

4. Real-Time Display Updates 

The LCD provides real-time information, including: 

  • Parking Status – "X" for occupied, "Y" for free. 

  • Temperature (°C) and Humidity (%). 

  • Time in HH:MM format. 

Forme 

 

#include <Wire.h> 

 

#include <LiquidCrystal.h> 

 

#include <Servo.h> 

 

#include <DHT.h> 

 

#include <RTClib.h> // RTC library 

 

 

 

 

// LCD pins 

 

LiquidCrystal lcd(13, 12, 11, 10, 9, 8); 

 

 

 

 

// Servo motors 

 

Servo gateServo;   // Gate motor (A4) 

 

Servo gasServo1;   // Gas sensor motor for Room 1 (A3) 

 

Servo gasServo2;   // Gas sensor motor for Room 2 (A1) 

 

 

 

 

// DHT11 setup (for humidity) 

 

#define DHT_PIN A0 

 

#define DHT_TYPE DHT11 

 

DHT dht(DHT_PIN, DHT_TYPE); 

 

 

 

 

// RTC setup 

 

RTC_DS3231 rtc; 

 

 

 

 

// Sensor pins 

 

#define GAS_SENSOR_PIN1 3   // Pin for gas detection Room 1 

 

#define GAS_SENSOR_PIN2 4   // Pin for gas detection Room 2 

 

#define IR_SENSOR_PIN 2     // Pin for parking spot (IR sensor) 

 

 

 

 

// Flags for interrupt handling 

 

volatile bool gasDetectedRoom1 = false; 

 

volatile bool gasDetectedRoom2 = false; 

 

 

 

 

void setup() { 

 

  // LCD setup 

 

  lcd.begin(16, 2); 

 

  lcd.clear(); 

 

 

 

 

  // Servo motors setup 

 

  gateServo.attach(A2); 

 

  gasServo1.attach(A3); 

 

  gasServo2.attach(A1); 

 

  gateServo.write(0);  // Initialize gate servo closed 

 

  gasServo1.write(0);  // Initialize gas servo idle for Room 1 

 

  gasServo2.write(0);  // Initialize gas servo idle for Room 2 

 

 

 

 

  // DHT11 setup 

 

  dht.begin(); 

 

 

 

 

  // RTC setup 

 

  if (!rtc.begin()) { 

 

    lcd.setCursor(0, 0); 

 

    lcd.print("RTC Error!"); 

 

    while (1); // Halt if RTC initialization fails 

 

  } 

 

  if (rtc.lostPower()) { 

 

    rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Set RTC to compile time 

 

  } 

 

 

 

 

  // Interrupt setup 

 

  pinMode(GAS_SENSOR_PIN1, INPUT_PULLUP); 

 

  pinMode(GAS_SENSOR_PIN2, INPUT); 

 

  pinMode(IR_SENSOR_PIN, INPUT); 

 

 

 

 

  attachInterrupt(digitalPinToInterrupt(GAS_SENSOR_PIN1), handleGasDetectionRoom1, RISING); 

 

 

 

 

  Serial.begin(9600); 

 

} 

 

 

 

 

void loop() { 

 

  // Read temperature and humidity 

 

  float temperature = dht.readTemperature(); 

 

  float humidity = dht.readHumidity(); 

 

 

 

 

  // Get current time 

 

  DateTime now = rtc.now(); 

 

  int hour = now.hour(); 

 

  int minute = now.minute(); 

 

 

 

 

  // Handle gas detection for Room 1 

 

  if (gasDetectedRoom1) { 

 

    gasDetectedRoom1 = false;  // Reset flag 

 

    for (int i = 0; i < 2; i++) { 

 

      lcd.setCursor(0, 0); 

 

      lcd.print("GasLeakRoom1"); 

 

      gasServo1.write(180); // Activate water sprinkler 

 

      delay(500); 

 

      gasServo1.write(0);   // Deactivate water sprinkler 

 

      delay(500); 

 

    } 

 

  } 

 

 

 

 

  // Handle gas detection for Room 2 

 

  if (digitalRead(GAS_SENSOR_PIN2) == HIGH) { 

 

    for (int i = 0; i < 2; i++) { 

 

      lcd.setCursor(0, 0); 

 

      lcd.print("GasLeakRoom2"); 

 

      gasServo2.write(180); // Activate water sprinkler 

 

      delay(500); 

 

      gasServo2.write(0);   // Deactivate water sprinkler 

 

      delay(500); 

 

    } 

 

  } 

 

 

 

 

  // Handle car detection 

 

  if (digitalRead(IR_SENSOR_PIN) == HIGH) { 

 

    gateServo.write(90);   // Open gate 

 

    delay(500);            // Keep gate open for 5 seconds 

 

    gateServo.write(0);    // Close gate 

 

  } 

 

 

 

 

  // Display parking and environmental data 

 

  lcd.clear(); 

 

  lcd.setCursor(0, 0); 

 

  lcd.print("P:"); 

 

  lcd.print(digitalRead(IR_SENSOR_PIN) == HIGH ? "X" : "Y"); // Parking spot status 

 

  lcd.print(" T:"); 

 

  lcd.print(temperature, 1);                                // Temperature 

 

 

 

 

 

 

 

  lcd.setCursor(0, 1); 

 

  lcd.print("H:"); 

 

  lcd.print(isnan(humidity) ? "Err" : String(humidity, 1));  // Humidity 

 

  lcd.print("%"); 

 

 

 

 

  // Display time on the right side of the first row 

 

  lcd.setCursor(11, 0); 

 

  lcd.print(hour < 10 ? "0" : ""); // Add leading zero if needed 

 

  lcd.print(hour); 

 

  lcd.print(":"); 

 

  lcd.print(minute < 10 ? "0" : ""); // Add leading zero if needed 

 

  lcd.print(minute); 

 

 

 

 

  delay(1000); // Refresh display every second 

 

} 

 

 

 

 

// ISR for gas detection in Room 1 

 

void handleGasDetectionRoom1() { 

 

  gasDetectedRoom1 = true; 

 

} 

 

 

 

Key Features & Benefits 

Automatic Gas Leak Detection & Response 

  • Uses interrupts for instant gas detection. 

  • Water sprinklers are activated automatically to control gas leaks. 

Automated Parking Gate 

  • Uses an IR sensor to detect vehicle presence. 

  • Servo motor automatically opens/closes the gate, ensuring a hands-free experience. 

Real-Time Environmental Monitoring 

  • Monitors temperature and humidity levels. 

  • Provides real-time data on the LCD display. 

Real-Time Clock (RTC) Integration 

  • Tracks the current time accurately. 

  • Resets automatically if power is lost. 

User-Friendly LCD Display 

  • Provides instant updates about gas leaks, temperature, humidity, and parking status. 

Forme 

Possible Enhancements 

While this project is already efficient, additional features can improve its performance: 

  • 🔔 Buzzer Alarm for Gas Leaks – Adds an audio alert for better emergency response. 

  • 📱 IoT Connectivity – Integrate Wi-Fi or Bluetooth for remote monitoring. 

  • 🔋 Battery Backup – Ensures functionality during power outages. 

Forme 

Final Thoughts 

The Automated Home Safety and Parking System is a perfect example of how technology can enhance home safety and convenience. By integrating gas leak detection, parking automation, and real-time monitoring, this system ensures a secure and efficient home environment. 

With potential improvements like buzzer alerts and IoT connectivity, the project can be further enhanced for better usability. Whether you’re looking to prevent hazards or automate daily tasks, this system offers an intelligent and practical solution. 

Forme 

Frequently Asked Questions (FAQs) 

1. How does the system detect gas leaks? 

The system uses MQ gas sensors in two rooms. Room 1 uses an interrupt-based detection method, while Room 2 continuously checks for leaks through polling. 

2. Can I manually control the parking gate? 

No, the parking gate operates automatically using an IR sensor. However, manual override can be added as an additional feature. 

3. What happens if the power goes out? 

The system resets to the compilation time after a power loss. Adding a battery backup can help maintain real-time functionality. 

4. Can the system be expanded with more sensors? 

Yes! Additional sensors (e.g., smoke detectors, fire alarms, or motion sensors) can be integrated for enhanced security. 

5. How accurate is the temperature and humidity monitoring? 

The DHT11 sensor provides reasonably accurate readings. However, for high-precision applications, a DHT22 sensor can be used instead. 

 

 

Arduino Smart parking 

Project Description 

This Arduino project with code is a smart parking status display system designed to monitor and show the availability of parking spots in real-time. It leverages a 74HC165 shift register to read the statuses of multiple parking spots using minimal Arduino pins and displays the results on a 16x2 LCD screen. 

Forme 

Key Features 

  1. Real-Time Parking Spot Monitoring: 

  • The system can monitor up to 8 parking spots using switches, sensors, or buttons connected to the 74HC165 shift register. 

  • Each spot’s availability is represented as either: 

  • X: Occupied. 

  • Y: Available. 

  1. Efficient Pin Usage: 

  • The 74HC165 shift register reads the states of 8 parking spots using only 3 Arduino pins for control and communication: 

  • SH/LD: Shift/Load Control. 

  • CLK: Clock Signal. 

  • SO: Serial Output. 

  1. Visual Feedback: 

  • A 16x2 LCD displays the parking statuses: 

  • Row 1: Labels the parking spots (1|2|3|4|5|6|7|8). 

  • Row 2: Shows real-time statuses (X|Y|X|Y...). 

  1. User-Friendly Design: 

  • Compact, scalable, and easy to implement in real-world parking lots. 

  • Minimal hardware requirements for efficient cost and power usage. 

 
 

Forme 

Schematic: 

 
 

Connections: 

Component 

Pin 

Direction 

Function 

LCD (RS) 

13 

Output 

LCD Register Select 

LCD (Enable) 

12 

Output 

LCD Enable 

LCD (D4) 

11 

Output 

LCD Data Line 4 

LCD (D5) 

10 

Output 

LCD Data Line 5 

LCD (D6) 

9 

Output 

LCD Data Line 6 

LCD (D7) 

8 

Output 

LCD Data Line 7 

74HC165 SH/LD 

A1 

Output 

Parallel load control for shift register 

74HC165 CLK 

3 

Output 

Clock signal to shift register 

74HC165 SO 

2 

Input 

Serial output (reads 8-bit data) 

 

Code: 

#include <Wire.h> 

#include <LiquidCrystal.h> 

#include <SPI.h> 

 

// LCD pins 

LiquidCrystal lcd(13, 12, 11, 10, 9, 8); 

 

// 74HC165 pins 

#define SH_LD A1  // Shift/Load Bar pin 

#define CLK 3     // Clock pin 

#define SO 2      // Serial Output pin 

 

// Number of parking spots 

const int NUM_SPOTS = 8; 

 

// Parking spot statuses 

bool spots[NUM_SPOTS]; 

 

void setup() { 

  // LCD setup 

  lcd.begin(16, 2); 

  lcd.clear(); 

 

  // 74HC165 control pins 

  pinMode(SH_LD, OUTPUT); 

  pinMode(CLK, OUTPUT); 

  pinMode(SO, INPUT); 

  digitalWrite(SH_LD, LOW); // Activate parallel load 

  digitalWrite(CLK, LOW);   // Prepare clock 

 

  Serial.begin(9600); 

} 

 

void loop() { 

  // Read parking spot statuses from shift register 

  readShiftRegister(spots); 

 

  // Display statuses on LCD 

  lcd.clear(); 

  lcd.setCursor(0, 0); 

  lcd.print("1|2|3|4|5|6|7|8"); 

 

  lcd.setCursor(0, 1); 

  for (int i = 0; i < NUM_SPOTS; i++) { 

    lcd.print(spots[i] ? "X|" : "Y|"); 

  } 

 

  delay(500); // Refresh every 500 ms 

} 

 

// Function to read the shift register 

void readShiftRegister(bool ar[8]) { 

  // Load parallel data into the shift register 

  digitalWrite(SH_LD, LOW);   // Activate parallel load 

  delayMicroseconds(5);       // Wait for data to load 

  digitalWrite(SH_LD, HIGH);  // Set to shift mode 

 

  // Shift out the bits one by one 

  for (int i = 0; i < NUM_SPOTS; i++) { 

    digitalWrite(CLK, LOW); 

    delayMicroseconds(5); 

    ar[i] = digitalRead(SO);  // Read the bit into the array 

    digitalWrite(CLK, HIGH); 

    delayMicroseconds(5); 

  } 

} 
 

 

 

 

 

How It Works 

  1. Parking Spot Detection: 

  • Each parking spot is connected to a parallel input pin (D0-D7) on the 74HC165 shift register. 

  • The sensors or switches indicate whether a spot is occupied (HIGH) or free (LOW). 

  1. Data Processing: 

  • The 74HC165 converts the parallel data from the parking spots into serialized data. 

  • The serialized data is sent to the Arduino via the SO pin. 

  1. Data Display: 

  • The Arduino decodes the data and updates the 16x2 LCD. 

  • The first row shows the spot labels, and the second row shows the availability status of each spot. 

  1. System Refresh: 

  • The system refreshes every 500 milliseconds, ensuring up-to-date information. 

Forme 

Applications 

  1. Parking Management: 

  • Ideal for monitoring parking lots in malls, offices, or residential complexes. 

  1. Smart Cities: 

  • Can be integrated into IoT systems for real-time parking availability tracking. 

  1. Scalable Design: 

  • Additional 74HC165 registers can be daisy-chained to monitor more parking spots. 

Or just get the project from this link:  

https://drive.google.com/file/d/1fv0RsBjE6PtrPl0H1EH10LGr1X9X0lDe/view?usp=drive_link 

Forme 

Advantages 

  1. Efficient Pin Usage: 

  • Only 3 Arduino pins are required to manage 8 parking spots. 

  1. Real-Time Updates: 

  • Instant feedback on parking statuses displayed on the LCD. 

  1. Scalability: 

  • Can expand to handle more spots by adding additional shift registers. 

  1. Cost-Effective: 

  • Uses readily available and affordable components. 

 

 

Keypad-Controlled Safe 

list of products from Amazon (Not mine, i just link them!) Scroll Down For Article! Note: Elegoo boards are not Arduino, but they are compatible with Arduino IDE and are mutch more affordable!This is an easy arduino uno project with code for beginners, it is a keypad controlled safe with cd display simulated online. 

Project description: 

This project implements a secure, servo-controlled safe with a 4x4 keypad for input and an LCD (16x2) display for user feedback. The safe is locked and unlocked based on a predefined 4-digit code (1234 by default). The servo motor controls the locking mechanism, while the keypad lets users enter the code to unlock the safe. Feedback messages such as "Access Denied" or "Safe Unlocked" are displayed on the LCD to enhance the user experience. 

The project is simulated on Wokwi.com, a powerful platform for simulating Arduino projects. A JSON file is provided to view the complete schematic of the components and connections. 

Forme 

Materials Required: 

  1. Arduino Uno (or compatible board) 

  1. 16x2 LCD Display with 4-bit interface 

  1. 4x4 Keypad 

  1. Servo Motor (e.g., SG90) 

  1. Resistors (for pull-up configurations, if needed) 

  1. Connecting Wires 

  1. Breadboard 

  1. Power Supply (or USB connection to the Arduino) 

 

Features: 

  • Secure Access: The safe unlocks only when the correct 4-digit code is entered. 

  • LCD Display: Provides real-time feedback for user interactions (e.g., "Enter Code," "Access Denied"). 

  • Auto-locking: After being unlocked for 3 seconds, the safe automatically locks. 

  • Customizable Code: The default code can be changed in the Arduino sketch. 

  • Simulation Ready: Designed for Wokwi, with a JSON file for schematic representation. 

 

Additional Notes: 

  • JSON File: Use the provided JSON file in Wokwi to visualize the project connections and simulate the safe’s functionality. 

  • Expansion: This setup can be expanded by adding features like an EEPROM to save the code or integrating a buzzer for failed attempts. 

Schematic: 

 
 
 

 
 

Pin connections: 

Component 

Pin 

Direction 

Function 

LCD (RS) 

12 

Output 

LCD Register Select 

LCD (Enable) 

11 

Output 

LCD Enable 

LCD (D4) 

10 

Output 

LCD Data Line 4 

LCD (D5) 

9 

Output 

LCD Data Line 5 

LCD (D6) 

8 

Output 

LCD Data Line 6 

LCD (D7) 

7 

Output 

LCD Data Line 7 

Servo Motor 

6 

Output 

Controls locking/unlocking the safe 

Keypad Row 0 

5 

Input/Output 

Row control for keypad scanning 

Keypad Row 1 

4 

Input/Output 

Row control for keypad scanning 

Keypad Row 2 

3 

Input/Output 

Row control for keypad scanning 

Keypad Row 3 

2 

Input/Output 

Row control for keypad scanning 

Keypad Column 0 

A3 

Input 

Column read for keypad 

Keypad Column 1 

A2 

Input 

Column read for keypad 

Keypad Column 2 

A1 

Input 

Column read for keypad 

Keypad Column 3 

A0 

Input 

Column read for keypad 

 

 

Code: 

-------------------------------------------------------------------------------------------------------------------------- 

// Pin definitions for LCD (16x2) 

const int rs = 12, en = 11, d4 = 10, d5 = 9, d6 = 8, d7 = 7; 

 

// Servo motor control 

const int servoPin = 6; 

int lockPosition = 20;    // Locked position (in degrees) 

int unlockPosition = 90;  // Unlocked position (in degrees) 

 

// Pin definitions for Keypad 

const int rowPins[4] = {5, 4, 3, 2}; 

const int colPins[4] = {A3, A2, A1, A0}; 

char keys[4][4] = { 

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

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

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

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

}; 

 

// Variables for safe state 

char code[5] = "1234"; // Default code 

char inputBuffer[5] = ""; 

int inputIndex = 0; 

 

// Servo control 

void setServoAngle(int angle) { 

int pulseWidth = map(angle, 0, 180, 544, 2400); 

for (int i = 0; i < 50; i++) { // Generate PWM signal for 1 second 

    digitalWrite(servoPin, HIGH); 

    delayMicroseconds(pulseWidth); 

    digitalWrite(servoPin, LOW); 

    delay(20); // Wait 20ms between pulses 

  } 

} 

 

// Initialize LCD 

void lcdCommand(byte cmd) { 

digitalWrite(rs, LOW); 

  sendToLCD(cmd); 

} 

 

void lcdData(byte data) { 

digitalWrite(rs, HIGH); 

  sendToLCD(data); 

} 

 

void sendToLCD(byte data) { 

// Send high nibble 

digitalWrite(d4, data & 0x10); 

digitalWrite(d5, data & 0x20); 

digitalWrite(d6, data & 0x40); 

digitalWrite(d7, data & 0x80); 

  lcdPulseEnable(); 

// Send low nibble 

digitalWrite(d4, data & 0x01); 

digitalWrite(d5, data & 0x02); 

digitalWrite(d6, data & 0x04); 

digitalWrite(d7, data & 0x08); 

  lcdPulseEnable(); 

} 

 

void lcdPulseEnable() { 

digitalWrite(en, HIGH); 

delayMicroseconds(1); 

digitalWrite(en, LOW); 

delayMicroseconds(100); 

} 

 

void lcdPrint(const char *message) { 

while (*message) { 

    lcdData(*message++); 

  } 

} 

 

void lcdSetCursor(byte col, byte row) { 

byte rowOffsets[] = {0x00, 0x40, 0x14, 0x54}; 

  lcdCommand(0x80 | (col + rowOffsets[row])); 

} 

 

void lcdClearWithDelay(unsigned long delayMillis) { 

delay(delayMillis); 

  lcdCommand(0x01); // Clear display 

} 

 

// Initialize Keypad 

char getKeypadKey() { 

for (int r = 0; r < 4; r++) { 

    pinMode(rowPins[r], OUTPUT); 

    digitalWrite(rowPins[r], LOW); 

 

    for (int c = 0; c < 4; c++) { 

      pinMode(colPins[c], INPUT_PULLUP); 

      if (digitalRead(colPins[c]) == LOW) { 

        while (digitalRead(colPins[c]) == LOW); // Wait for release 

        return keys[r][c]; 

      } 

    } 

    digitalWrite(rowPins[r], HIGH); 

    pinMode(rowPins[r], INPUT); 

  } 

return 0; 

} 

 

// Safe control logic 

void lockSafe() { 

  setServoAngle(lockPosition); 

  lcdSetCursor(0, 1); 

  lcdPrint("Safe Locked   "); 

  lcdClearWithDelay(1000); // Clear after 1 second 

} 

 

void unlockSafe() { 

  setServoAngle(unlockPosition); 

  lcdSetCursor(0, 1); 

  lcdPrint("Safe Unlocked "); 

delay(3000); // Keep safe unlocked for 3 seconds 

  lockSafe();  // Automatically lock after 3 seconds 

} 

 

void resetInputBuffer() { 

  inputIndex = 0; 

  memset(inputBuffer, 0, sizeof(inputBuffer)); 

} 

 

void checkCode() { 

if (strcmp(inputBuffer, code) == 0) { 

    unlockSafe(); 

  } else { 

    lcdSetCursor(0, 1); 

    lcdPrint("Access Denied "); 

    lcdClearWithDelay(1000); // Clear after 1 second 

    lcdSetCursor(0, 1); 

    lcdPrint("Enter Code    "); 

    lcdClearWithDelay(1000); // Clear after 1 second 

  } 

  resetInputBuffer(); 

} 

 

void setup() { 

// Initialize LCD pins 

pinMode(rs, OUTPUT); 

pinMode(en, OUTPUT); 

pinMode(d4, OUTPUT); 

pinMode(d5, OUTPUT); 

pinMode(d6, OUTPUT); 

pinMode(d7, OUTPUT); 

 

  lcdCommand(0x33); // Initialize LCD in 4-bit mode 

  lcdCommand(0x32); // Set to 4-bit mode 

  lcdCommand(0x28); // 2 lines, 5x7 matrix 

  lcdCommand(0x0C); // Display ON, cursor OFF 

  lcdCommand(0x06); // Increment cursor 

  lcdCommand(0x01); // Clear display 

 

// Display startup message 

  lcdSetCursor(0, 0); 

  lcdPrint("Arduino Safe"); 

delay(2000); 

  lcdClearWithDelay(0); // Clear immediately after delay 

 

// Initialize Servo 

pinMode(servoPin, OUTPUT); 

lockSafe(); 

  resetInputBuffer(); 

 

// Display prompt 

  lcdSetCursor(0, 1); 

  lcdPrint("Enter Code    "); 

  lcdClearWithDelay(1000); // Clear after 1 second 

} 

 

void loop() { 

char key = getKeypadKey(); 

if (key) { 

    lcdSetCursor(inputIndex, 1); 

    lcdData('*'); // Display * for each key pressed 

    inputBuffer[inputIndex++] = key; 

 

    if (inputIndex >= 4) { 

      delay(500); 

      checkCode(); 

    } 

  } 

} 

 

 

-------------------------------------------------------------------------------------------------------------------------- 

Json code(Just paste it in wokwi): 

{ 

"version": 1, 

"author": "https://www.youtube.com/@EasyElectronics2", 

"editor": "wokwi", 

"parts": [ 

    { "id": "uno", "type": "wokwi-arduino-uno", "top": 200, "left": 20 }, 

    { 

      "id": "keypad", 

      "type": "wokwi-membrane-keypad", 

      "left": 360, 

      "top": 140 

    }, 

    { 

      "id": "servo", 

      "type": "wokwi-servo", 

      "left": 400, 

      "top": 20, 

      "attrs": { "hornColor": "black" } 

    }, 

    { "id": "lcd", "type": "wokwi-lcd1602", "top": 8, "left": 20 }, 

    { 

      "id": "r1", 

      "type": "wokwi-resistor", 

      "top": 140, 

      "left": 220, 

      "attrs": { "value": "220" } 

    } 

  ], 

"connections": [ 

    ["uno:GND.1", "lcd:VSS", "black", ["v-51", "*", "h0", "v18"]], 

    ["uno:GND.1", "lcd:K", "black", ["v-51", "*", "h0", "v18"]], 

    ["uno:GND.1", "lcd:RW", "black", ["v-51", "*", "h0", "v18"]], 

    ["uno:5V", "lcd:VDD", "red", ["v16", "h-16"]], 

    ["uno:5V", "r1:2", "red", ["v16", "h-118", "v-244", "h50"]], 

    ["r1:1", "lcd:A", "pink", []], 

    ["uno:12", "lcd:RS", "blue", ["v-16", "*", "h0", "v20"]], 

    ["uno:11", "lcd:E", "purple", ["v-20", "*", "h0", "v20"]], 

    ["uno:10", "lcd:D4", "green", ["v-24", "*", "h0", "v20"]], 

    ["uno:9", "lcd:D5", "brown", ["v-28", "*", "h0", "v20"]], 

    ["uno:8", "lcd:D6", "gold", ["v-32", "*", "h0", "v20"]], 

    ["uno:7", "lcd:D7", "gray", ["v-36", "*", "h0", "v20"]], 

    ["uno:6", "servo:PWM", "orange", ["v-40", "*", "h0", "h-52"]], 

    ["uno:5V", "servo:V+", "red", ["v16", "h-118", "v-244", "*", "h-56"]], 

    ["uno:GND.1", "servo:GND", "black", ["v-46", "*", "v88", "h-60"]], 

    ["uno:A3", "keypad:C1", "brown", ["v116", "*", "h0", "v0"]], 

    ["uno:A2", "keypad:C2", "gray", ["v120", "*", "h0", "v0"]], 

    ["uno:A1", "keypad:C3", "orange", ["v124", "*", "h0", "v0"]], 

    ["uno:A0", "keypad:C4", "pink", ["v128", "*", "h0", "v0"]], 

    ["uno:5", "keypad:R1", "blue", ["v-34", "h96", "*", "v12"]], 

    ["uno:4", "keypad:R2", "green", ["v-30", "h80", "*", "v16"]], 

    ["uno:3", "keypad:R3", "purple", ["v-26", "h64", "*", "v20"]], 

    ["uno:2", "keypad:R4", "gold", ["v-22", "h48", "*", "v24"]] 

  ] 

} 

 

------------------------------------------------------------------------------ 

 

 

Conclusion 

Through the projects in this book, you’ve gained practical experience in building functional systems using Arduino. You’ve learned how to: 

  • Integrate input and output devices like sensors, servos, keypads, and displays 

  • Use external components like shift registers to expand I/O capabilities 

  • Write structured code to manage real-world interactions and decision-making 

  • Create automated, responsive systems that improve safety and convenience 

These foundational skills are transferable to countless other Arduino applications. Whether it's smart homes, security systems, automation, or IoT, the techniques explored here will serve as stepping stones for more advanced innovations. 

Keep experimenting, modifying, and learning. The world of embedded electronics is vast, and your next great idea could be just a few lines of code away. 

Happy tinkering! 

 

Post a Comment

0 Comments