0% found this document useful (0 votes)
32 views2 pages

Buzzer Indication On Detection of Motion Sensor Code Using Pic18 MC

The document outlines a C program for an anti-theft system using a PIC microcontroller and a PIR motion sensor, which activates a buzzer upon detecting motion. It includes pin connections for the PIR sensor and buzzer to the PIC18F4520, as well as the C code to implement the functionality. Optional enhancements such as adding an LCD display and GSM module for alerts are also suggested.

Uploaded by

413 YASH MANE
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)
32 views2 pages

Buzzer Indication On Detection of Motion Sensor Code Using Pic18 MC

The document outlines a C program for an anti-theft system using a PIC microcontroller and a PIR motion sensor, which activates a buzzer upon detecting motion. It includes pin connections for the PIR sensor and buzzer to the PIC18F4520, as well as the C code to implement the functionality. Optional enhancements such as adding an LCD display and GSM module for alerts are also suggested.

Uploaded by

413 YASH MANE
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/ 2

Q1) Write a C program to implement antitheft system using PIC microcontroller and

motion sensor. System must give buzzer indication on detection of thief in the detection
zone of motion sensor. Also draw connection diagram.
ANS 

✅ System Overview
 PIR Motion Sensor: Detects movement (thief) in its range.
 PIC18F4520: Reads motion status via digital input.
 Buzzer: Activated when motion is detected.

✅ Pin Connections
Component PIC18F4520 Pin Direction
PIR Sensor OUT RB0 (PIN 33) Input
Buzzer RC0 (PIN 15) Output

✅ C Program (XC8, MPLAB X)


#include <xc.h>
#define _XTAL_FREQ 4000000

// CONFIGURATION BITS

#define PIR PORTBbits.RB0 // Motion sensor input


#define BUZZER LATCbits.LATC0 // Buzzer output

void main(void)
{
OSCCON = 0xEF; // Internal oscillator 4 MHz
ADCON1 = 0x0F; // All digital I/O
TRISBbits.TRISB0 = 1; // RB0 as input (PIR sensor)
TRISCbits.TRISC0 = 0; // RC0 as output (Buzzer)
LATCbits.LATC0 = 0; // Buzzer OFF initially

while(1)
{
if (PIR == 1) // Motion detected
{
BUZZER = 1; // Buzzer ON
__delay_ms(2000); // Alert duration
BUZZER = 0; // Buzzer OFF
}
else
{
BUZZER = 0; // No motion, buzzer OFF
}
}
}
✅ Connection Diagram (Textual Description)
[PIR Sensor]
Vcc —> +5V
GND —> GND
OUT —> RB0 (Pin 33)

[Buzzer]
+ Terminal —> RC0 (Pin 15) through NPN transistor base (e.g., BC547)
- Terminal —> GND
Emitter —> GND
Collector —> Buzzer -
Flyback diode (1N4007) across buzzer terminals

➡️ You can drive the buzzer directly via a transistor or use a driver like ULN2003.

✅ Optional Enhancements
 Add LCD to display “Motion Detected”.
 Use EEPROM to log event.
 Activate GSM module for SMS alert.

You might also like