This guide will help you create an IoT-Based Streetlight Controller System using Raspberry Pi. The system will control streetlights based on ambient light conditions and predefined schedules, optimizing energy usage and enhancing street lighting management.

Components Required

  • Raspberry Pi (Model 3 or later)
  • Ambient light sensor (e.g., LDR or BH1750)
  • Relay module (for controlling streetlight power)
  • Real-time clock (RTC) module (for time-based control)
  • Connecting wires and breadboard
  • Power supply (for Raspberry Pi and sensors)
  • Cloud service account (optional, for remote monitoring and control)
  • Optional: LCD display or LED indicators for local status

Setting Up the Hardware

Follow these steps to set up the hardware:

  1. Connect the Ambient Light Sensor

    Connect the ambient light sensor to the Raspberry Pi using GPIO pins. This sensor will measure the ambient light levels and help decide whether the streetlights need to be turned on or off.

  2. Integrate the Relay Module

    Connect the relay module to the Raspberry Pi. The relay will control the power supply to the streetlights based on the sensor readings and time-based controls.

  3. Add the RTC Module

    Connect the RTC module to the Raspberry Pi to keep track of the current time. This will be used for scheduling when streetlights should be turned on or off.

  4. Power the System

    Ensure the Raspberry Pi and other components are properly powered using the appropriate power supplies. Verify all connections are secure before powering on the system.

Programming the Raspberry Pi

Write the code to read data from the sensors and control the relay based on the ambient light levels and time schedule. Below is an example code using Python:


                import RPi.GPIO as GPIO
                import time
                from datetime import datetime
                from smbus2 import SMBus
                from bme280 import BME280

                # Configuration
                LIGHT_SENSOR_PIN = 17
                RELAY_PIN = 23
                RTC_ADDRESS = 0x68  # RTC I2C address
                BUS = SMBus(1)  # I2C bus

                # Setup
                GPIO.setmode(GPIO.BCM)
                GPIO.setup(LIGHT_SENSOR_PIN, GPIO.IN)
                GPIO.setup(RELAY_PIN, GPIO.OUT)

                # Initialize RTC
                bme280 = BME280(i2c_dev=BUS)

                def get_time():
                    return datetime.now().strftime("%H:%M")

                def control_streetlight():
                    current_time = get_time()
                    light_level = GPIO.input(LIGHT_SENSOR_PIN)
                    if light_level < 500 or (current_time > "18:00" and current_time < "06:00"):
                        GPIO.output(RELAY_PIN, GPIO.HIGH)
                        print("Streetlight ON")
                    else:
                        GPIO.output(RELAY_PIN, GPIO.LOW)
                        print("Streetlight OFF")

                try:
                    while True:
                        control_streetlight()
                        time.sleep(60)  # Check every minute

                except KeyboardInterrupt:
                    GPIO.cleanup()
            

This code reads the ambient light level and current time, then controls the streetlight based on these readings. The streetlight is turned on if the light level is low or if it's within the specified time range.

Setting Up Cloud Integration

To enable remote monitoring and control, integrate your system with a cloud service. Configure your cloud service to receive data from the Raspberry Pi and allow remote management of the streetlights through a web interface or mobile app.

Testing and Calibration

Test the system by simulating different light conditions and verifying that the streetlights turn on and off as expected. Adjust sensor sensitivity and time-based control parameters as needed to ensure reliable operation.

Conclusion

The IoT-Based Streetlight Controller System provides an efficient and automated solution for managing streetlights. By integrating ambient light sensors and real-time clock modules with Raspberry Pi and cloud services, this system enhances energy efficiency and simplifies streetlight management.