Automatic control of street lights is designed to turn on and off street lights automatically. This project checks the amount of light. If the light is 80 percent available, it automatically turns off street lights. But, if the amount of light is less than 80 percent, this project will automatically turn on street lights. One can also adjust it according to their requirements.
A light sensor detects the intensity of light. The PIC16F877A microcontroller interfaces with the light sensor to sense the amount of light available. After analyzing the amount of light, the PIC16F877A microcontroller generates a control signal. The control signal turns on the transistor, which energizes the relay coil and turns on the street light. Only one lamp is used in this project for demonstration purposes, but you can use as many street lights as you want to control through this automatic street light control system.
Automatic Street Lights Control with a Microcontroller is an innovative application of embedded systems technology aimed at enhancing energy efficiency and promoting sustainability in urban environments. This intelligent system utilizes a microcontroller, a compact and programmable integrated circuit, to autonomously manage the operation of street lights based on ambient light levels. The heart of the system lies in the utilization of a Light Dependent Resistor (LDR) to sense variations in natural light, allowing the microcontroller to dynamically control the illumination of street lights. This not only contributes to energy conservation by ensuring lights are active only when necessary but also offers the potential for significant cost savings and a reduced environmental footprint. This technological solution aligns with the growing emphasis on smart city initiatives, showcasing the application of embedded systems for more efficient and sustainable urban infrastructure.
Circuit Diagram Automatic Control of Street Light
The following are the main components of the automatic control of street lights:
The light sensor senses the amount of light. There are many light sensors available in the market, but the Light dependent resistor (LDR) is used as a light sensor because it is cheap in price, easily available in the market, and can be easily interfaced with a microcontroller to sense the intensity of light. The LDR has the property to change its resistance according to the intensity of light. If the light is high, the LDR will have low resistance, and if the light is low, the LDR will have high resistance. So, the microcontroller can easily read this resistance in the form of voltage, which can be back-converted into a proportional value of light using a formula available in the datasheet. I recommend you to look at the datasheet of the LDR.
Relay interfacing with microcontroller
As mentioned above, a microcontroller analyzes the intensity of light and generates a control signal, which in turn turns on or off the street light. We use an NPN transistor as a switch, and we use a resistor at the base of the transistor as a current-limiting resistor. We use a diode to avoid back EMF voltage, which can produce sparking across the relay.
The circuit diagram below illustrates the automatic control of street lights.
To check the working of this project and to understand the code, watch the following video:
The code for this project is written in the MIKROC compiler and 8Mhz crystal is used in this project. If you do not know how to use MikroC for Pic, you can refer to these tutorials:
- How to Use “MikroC PRO for PIC” to Program PIC Microcontrollers
- Pic microcontroller programming in c using Mikroc Pro for PIC
//*************** microcontrollerslab.com ******************
//************** email@example.com ***********
// Global variable to store light intensity
// Function to read LDR (Light Dependent Resistor)
unsigned int adc_value = 0;
// Read analog value from ADC channel 0
adc_value = ADC_Read(0);
// Calculate light intensity as a percentage
light = 100 - adc_value / 10.24;
// Switch off the light when light intensity is 80 percent or more
if (light >= 80)
PORTB.F1 = 0;
PORTB.F1 = 1;
// Main function
// Set PORTB as output
TRISB = 0X00;
// Initialize PORTB to 0
PORTB = 0X00;
// Initialize ADC
// Infinite loop
// Read LDR and control light accordingly
How Does Code Work?
This code is an implementation of an Automatic Street Lights Control system using a pic microcontroller. The program employs a global variable, ‘light,’ to store the calculated light intensity based on readings from a Light Dependent Resistor (LDR). The read_ldr() function is responsible for reading the analog value from ADC channel 0, converting it to a percentage to determine the light intensity, and subsequently controlling the street light. Specifically, if the light intensity surpasses 80 percent, the program switches off the street light by setting the corresponding bit (F1) in the PORTB register to 0; otherwise, it sets the bit to 1, keeping the light on. This conditional control ensures that the street lights operate efficiently, responding to the ambient light conditions.
In the main function, the code initializes the microcontroller by setting PORTB as an output for controlling the street lights, initializing PORTB to 0, and initializing the ADC module. The program then enters an infinite loop where it continuously reads the LDR values and adjusts the street lights accordingly. This implementation provides a basic yet functional example of an energy-efficient street lighting system that utilizes a microcontroller to intelligently respond to variations in ambient light levels.
This project has many applications. For example, you may be too lazy to manually turn on or off your street lights, and you may forget to do so daily. With this project, you can easily save electricity and, in turn, save money. In countries where load shedding is a big issue due to a shortfall in electricity and limited resources for its generation, this project can help to a certain extent. By automatically controlling street lights, we can save a maximum amount of energy, which is beneficial for your nation and also for you. It will reduce your electricity bill and, in turn, save you money.
You may also like to read:
- Digital DC Voltmeter using 7-Segment Display and Pic Microcontroller
- Alternating Current Measurement using Pic Microcontroller
- DC motor Speed control using pic microcontroller
- Rain Drop Sensor Module Interfacing with Pic Microcontroller– Rain Detector Circuit
- Infrared Flame Sensor Interfacing with Pic Microcontroller
- Automatic Temperature controller using pic microcontroller