Close

#buildinstructions: light-sensor

A project log for Elephant AI

a system to prevent human-elephant conflict by detecting elephants using machine vision, and warning humans and/or repelling elephants

neil-k-sheridanNeil K. Sheridan 10/20/2017 at 20:330 Comments

Let's get started with adding a light-sensor, so we can tell if it is daytime or night-time! We need a light-sensor with a digital output. Or we can build a circuit using a photo-resistor and a transistor instead!

PARTS REQUIRED

digital light sensor. Have used "kwmobile light sensor with digital output, photodetector, brightness sensor, light sensor for Arduino, Genuino and Raspberry Pi " which was £5.40

jumper wires (you can test with female to female, but will need female to male when we share the light sensor between dayPi and nightPi)

1.

Connect the jumper wires to the light-sensor:

2. Now we connect the jumper wires to the raspberry pi:

Connect digital output (DO/yellow) to GPIO PIN 7 [board numbering system]

Connect GND to GND

Connect 5v input to a 5v output PIN on Pi

3. Now that's all done! We can go ahead and test it using the following code:

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.IN)
try:
    while True:
           val = GPIO.input(7)
           if (val == True):
                print("IT IS DARK CONDITION")
           else:
                print("IT IS LIGHT CONDITION")
           time.sleep(3)
           GPIO.cleanup()
except KeyboardInterrupt:
     GPIO.cleanup()

 Here it is in action! You can see it has it's own LED that turns on/off depending on light condition.

4. Ok, we are all set for using the light-sensor now! I'll add the homemade circuit later!

Discussions