Introduction
Energy conservation is becoming increasingly important, and one practical way to achieve this in everyday life is through automation. An Automatic Room Light Controller is a system designed to automatically turn lights on or off based on the presence of individuals in a room. This project utilizes a PIC microcontroller to detect motion using sensors and control the lighting accordingly. In this article, we will walk through the design, implementation, and coding aspects of building an Automatic Room Light Controller using a PIC microcontroller.
Components Required
PIC Microcontroller (e.g., PIC16F877A)
PIR Motion Sensor (e.g., HC-SR501)
Relay Module
Light Bulb or LED
Power Supply (5V and 12V)
Crystal Oscillator (20 MHz)
Capacitors (22pF, 100µF)
Resistors (1kΩ, 10kΩ)
Transistor (e.g., 2N2222 or BC547)
Diode (e.g., 1N4007)
Connecting Wires
PCB or Breadboard for Prototyping
System Overview
The Automatic Room Light Controller system works by detecting human presence using a PIR (Passive Infrared) sensor. When the sensor detects motion, it sends a signal to the PIC microcontroller, which then triggers a relay to turn on the lights. The lights remain on as long as motion is detected, and they turn off automatically after a set period of inactivity.
Block Diagram
PIR Sensor: Detects motion and sends a signal to the microcontroller.
PIC Microcontroller: Processes the signal from the PIR sensor and controls the relay.
Relay Module: Acts as a switch to control the light bulb or LED.
Light Source: A bulb or LED that is controlled by the relay.
Circuit Diagram
[Insert a simplified circuit diagram here, showing connections between the PIC microcontroller, PIR sensor, relay module, and light source.]
Working Principle
PIR Sensor: The PIR sensor detects infrared radiation emitted by humans. When motion is detected within its range, it outputs a HIGH signal to indicate presence.
Signal Processing: The output from the PIR sensor is fed into one of the digital input pins of the PIC microcontroller. The microcontroller continuously monitors this input to determine if motion is detected.
Controlling the Relay: When the PIC microcontroller detects a HIGH signal from the PIR sensor, it sends a signal to the relay module to turn on the light. If no motion is detected for a specified duration, the microcontroller turns off the relay, and the light goes off.
Software Implementation
Initializing the Microcontroller:
Set up the I/O pins for the PIR sensor and relay.
Configure the timer to manage the delay before turning off the lights.
Motion Detection:
Continuously monitor the input pin connected to the PIR sensor.
When motion is detected, turn on the relay to power the light.
Automatic Turn Off:
If no motion is detected for a set period, turn off the relay to switch off the light.
Sample Code
#include <xc.h>
#define _XTAL_FREQ 20000000 // Define crystal frequency
// Configuration bits
#pragma config FOSC = HS // High-speed oscillator
#pragma config WDTE = OFF // Watchdog Timer Disable
#define PIR_SENSOR PORTBbits.RB0 // PIR sensor connected to RB0
#define RELAY_PIN PORTBbits.RB1 // Relay connected to RB1
void main(void) {
// Initialize PIR sensor and Relay pin
TRISBbits.TRISB0 = 1; // Set RB0 as input (PIR sensor)
TRISBbits.TRISB1 = 0; // Set RB1 as output (Relay)
RELAY_PIN = 0; // Initialize relay as off
while (1) {
if (PIR_SENSOR) { // If motion is detected
RELAY_PIN = 1; // Turn on the light
__delay_ms(5000); // Keep the light on for 5 seconds (example delay)
} else {
RELAY_PIN = 0; // Turn off the light if no motion
}
}
}
Explanation of the Code
PIR Sensor Input: The PIR sensor is connected to pin RB0, which is configured as an input. The microcontroller checks the status of this pin to determine if motion is detected.
Relay Control: The relay is connected to pin RB1, which is configured as an output. When the microcontroller detects motion (PIR sensor is HIGH), it sets RB1 HIGH to activate the relay and turn on the light.
Delay Functionality: The light remains on for a set period (5 seconds in this example) after detecting motion. The delay can be adjusted based on the application’s requirements.
Conclusion
An Automatic Room Light Controller using a PIC microcontroller is a simple yet effective project that demonstrates the power of automation in energy conservation. By utilizing a PIR sensor and a relay, the system can automatically control room lighting based on occupancy, providing both convenience and efficiency. This project offers a practical application of microcontroller programming and sensor integration, making it a great starting point for anyone interested in home automation.
Further Enhancements
Adjustable Delay: Implement a method to adjust the delay time dynamically using a potentiometer or buttons.
Daylight Sensing: Integrate a light sensor (LDR) to prevent the lights from turning on during daylight hours.
Multiple Sensors: Use multiple PIR sensors to cover larger rooms or areas with multiple entry points.
Remote Control: Add remote control functionality to manually override the automatic operation if needed.
This project not only illustrates the basic principles of microcontroller-based automation but also opens the door to more advanced home automation systems that can be tailored to specific needs.
Want us to guide you through your project or make the project for you ?
Create Various Projects
Check out our Free Arduino Projects Playlist - Arduino Projects
Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects
Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects
Check out our Free IoT Projects Playlist - IoT Projects
Check out our Free Home Automation Projects Playlist - Home Automation Projects
Check out our Free NodeMCu Projects Playlist - NodeMCu Projects
Comments