Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
19 views15 pages

Embedded C Programming Submission 1

The project titled 'PIR Based Automatic Gate System' utilizes a PIR sensor, stepper motor, LCD display, and 8051 microcontroller to automate gate operations based on motion detection. The system counts the number of vehicles or people passing through the gate and displays this count on the LCD. Challenges faced include sensor stability, timing delays, LCD flickering, and stepper motor phase issues.

Uploaded by

dakshmanchanda30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views15 pages

Embedded C Programming Submission 1

The project titled 'PIR Based Automatic Gate System' utilizes a PIR sensor, stepper motor, LCD display, and 8051 microcontroller to automate gate operations based on motion detection. The system counts the number of vehicles or people passing through the gate and displays this count on the LCD. Challenges faced include sensor stability, timing delays, LCD flickering, and stepper motor phase issues.

Uploaded by

dakshmanchanda30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

BECE320E: Embedded C Programming

Course Project

Register No: 22BEC0421

Slot: C1

Title: PIR Based Automatic Gate System

Abstract: This project uses a PIR sensor, a stepper


motor, a LCD display and a 8051 microcontroller. The
PIR sensor feeds high to the microcontroller on detecting
any motion. The Stepper then goes through a phase shift
of 90 degrees to open the gate. The LCD then displays
the count of vehicles or people entering through the gate.

Methodology:
(i) Block Diagram(Hardware)
(ii) Flowchart(software)
Program with comments:
#include <reg51.h>

// Pin Definitions
sbit PIR = P0^0; // PIR sensor input
sbit RS = P2^0; // LCD RS pin
sbit RW = P2^1; // LCD RW pin
sbit EN = P2^2; // LCD Enable pin

// Global variable
unsigned char count = 0;

// Function Declarations
void Delay1(); // Delay for PIR
void Delay2(); // Delay for stepper
void Delay3(); // Delay for LCD
void Stepper(); // Stepper motor control
void LCD(); // Update LCD with count
void LCD_Cmd(unsigned char); // Send command to LCD
void LCD_Data(unsigned char); // Send data to LCD

// Main Function
void main() {
// Timer initialization
TMOD = 0x12; // Timer0 Mode1, Timer1 Mode2
TH0 = 0xA4;

// PIR sensor input


PIR = 1;

// Stepper motor port


P3 = 0xFF;

while (1) {
while (PIR == 0); // Wait until PIR detects motion
Delay1();
Stepper();
count++;
LCD();
}
}

// Stepper Motor Control


void Stepper() {
P3 = 0x0C;
Delay2();
P3 = 0x09;
Delay2();
}

// LCD Update Function


void LCD() {
LCD_Cmd(0x01); // Clear Display
Delay3();
LCD_Cmd(0x38); // 2 lines, 8-bit mode
Delay3();
LCD_Cmd(0x0E); // Display ON, Cursor blinking
Delay3();
LCD_Cmd(0x80); // Cursor at beginning
Delay3();

LCD_Data((count % 10) + 0x30); // Display units digit


Delay3();
}

// Send Command to LCD


void LCD_Cmd(unsigned char cmd) {
P1 = cmd;
RS = 0;
RW = 0;
EN = 1;
Delay3();
EN = 0;
}

// Send Data to LCD


void LCD_Data(unsigned char data) {
P1 = data;
RS = 1;
RW = 0;
EN = 1;
Delay3();
EN = 0;
}

// PIR Stability Delay (Timer 0)


void Delay1() {
TR0 = 1;
while (TF0 == 0);
TR0 = 0;
TF0 = 0;
}

// Stepper Motor Delay (Timer 1)


void Delay2() {
TH1 = 0xFF;
TL1 = 0xFF;
TR1 = 1;
while (TF1 == 0);
TR1 = 0;
TF1 = 0;
}

// LCD Operation Delay (Nested Loops)


void Delay3() {
unsigned int i, j;
for (i = 0; i < 0x20; i++)
for (j = 0; j < 0xF4; j++);
}

Results:
Screenshot showing program with zero syntax
error(KEIL)
Screenshot of the result(KEIL)
Screenshot of Proteus simulation
From the above simulation results, we can see that the phase of the
stepper motor changes in order to open and close the gate,
meanwhile the LCD displays the number of people that have
passed through the gate.

Comparison with other Systems:-


Challenges Faced:-
 Sensor Stability: PIR sensors can give false triggers due
to environmental factors like heat or vibrations, which may
cause the gate to open unnecessarily.
 Timing Delays: Synchronizing delays between the PIR
sensor detection and the stepper motor control was tricky.
Improper delays might cause misbehavior of the gate.
 LCD Flickering: Without proper delay and initialization,
the LCD may not display the count reliably.
 Stepper Motor Phase Issues: Incorrect stepping
sequences or delays might lead to incomplete or jittery gate
movement.
References and Research Papers:-
1) Mazidi, M. A., & Mazidi, J. G. (2006). The 8051
Microcontroller and Embedded Systems. Pearson
Education.
2) Bhupinder Singh. Advanced Microcontroller and
Embedded Systems. Tech Knowledge Publications.
3) KEIL µVision IDE: https://www.keil.com/uv2/
4) Proteus Design Suite for simulation:
https://www.labcenter.com/
5) Datasheet of HC-SR501 PIR Sensor:
https://www.mpja.com/download/31227sc.pdf
6) Stepper Motor Fundamentals – Texas Instruments
Application Note.
7) Automatic Door Opening Using PIR Sensor
https://ciitresearch.org/dl/index.php/aiml/article/view/A
IML012021001
8) Design and Construction of a Motion-Based Automatic
Door Opener with Metal Detector
https://publisher.resbee.org/mr/archive/v7i3/a1.html
9) Automatic Lighting and Security System Design Using
PIR Motion Sensor
https://www.researchgate.net/publication/303314563

Presented by:-

Daksh Manchanda(22BEC0421)

You might also like