Buzzer Indication On Detection of Motion Sensor Code Using Pic18 MC
Buzzer Indication On Detection of Motion Sensor Code Using Pic18 MC
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
// CONFIGURATION BITS
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.