LDR based street light control using Raspberry Pi

Call for Price

LDR based street light control using Raspberry Pi

SKU: LDR based street light control using Raspberry Pi Category:

Description

ABSTRACT

This project will give you the idea about smart street light control for Power consumption based on a Light Dependent Resistor. Power consumption is the very important factor for the society, as the initial stage by using LDR to detect the environment light. If there is any light in the environment street light should be off automatically. If there is no sunlight street light should on. Mainly for the Beginners, you can able to learn to read LDR value through ADC IC (MCP3008) for light detection and to make an autonomous system to switch ON/OFF the light from this Raspberry Pi project.

HARDWARE REQUIRED

  • Raspberry Pi
  • SD card
  • Power supply
  • VGA to HDMI converter (Optional)
  • MCP3008 (ADC IC)
  • LDR sensor
  • USB light as a prototype of Streetlight

SOFTWARE REQUIRED

  • Raspbian Stretch OS      
  • SD card Formatter
  • Win32DiskImager (or) Etcher

PYTHON LIBRARIES USED

  • RPi.GPIO as GPIO (To access the GPIO Pins of Raspberry Pi)
  • Time library (For Time delay)

 

CODE

import time

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

# read SPI data from MCP3008 chip, 8 possible adc's (0 thru 7)
def readadc(adcnum, clockpin, mosipin, misopin, cspin):
    if ((adcnum > 7) or (adcnum < 0)):
        return -1
    GPIO.output(cspin, True)

    GPIO.output(clockpin, False)  # start clock low
    GPIO.output(cspin, False)  # bring CS low

    commandout = adcnum
    commandout |= 0x18  # start bit + single-ended bit
    commandout <<= 3  # we only need to send 5 bits here
    for i in range(5):
        if (commandout & 0x80):
            GPIO.output(mosipin, True)
        else:
            GPIO.output(mosipin, False)
        commandout <<= 1
        GPIO.output(clockpin, True)
        GPIO.output(clockpin, False)

    adcout = 0
    # read in one empty bit, one null bit and 10 ADC bits
    for i in range(12):
        GPIO.output(clockpin, True)
        GPIO.output(clockpin, False)
        adcout <<= 1
        if (GPIO.input(misopin)):
            adcout |= 0x1

    GPIO.output(cspin, True)

    adcout >>= 1  # first bit is 'null' so drop it
    return adcout


# change these as desired - they're the pins connected from the
# SPI port on the ADC to the Cobbler
SPICLK = 18
SPIMISO = 23
SPIMOSI = 24
SPICS = 25
light=21
# set up the SPI interface pins
GPIO.setup(SPIMOSI, GPIO.OUT)
GPIO.setup(SPIMISO, GPIO.IN)
GPIO.setup(SPICLK, GPIO.OUT)
GPIO.setup(SPICS, GPIO.OUT)
GPIO.setup(light, GPIO.OUT)


while True:
    # read the analog pin
    LDR = readadc(0, SPICLK, SPIMOSI, SPIMISO, SPICS)
    #print("LDR_LEVEL:", PIR)       #uncomment to display pir value
    if(LDR<500):
        GPIO.output(light, True)
    else:
        GPIO.output(light, False)


Additional information

Weight 0.000000 kg

Reviews

There are no reviews yet.

Be the first to review “LDR based street light control using Raspberry Pi”

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.