Posts: 1
Joined: Fri Jun 14, 2019 9:03 am

Light sensor not working

Fri Jun 14, 2019 9:13 am

Hello all,

A few days ago i bought some light sensors and lasers for my raspberry pi. They all arived by now, the laser is working, but my lightsensor just isn't.. Everytime i plug it in and point my laser at it it just doesn't give any feedback and as soon as i unplug my Analog Out or Digital out it starts giving output...

The code i use:

Code: Select all

from datetime import datetime
import RPi.GPIO as GPIO
import os, time

SensorGPIO = 23
LaserGPIO = 17

def callback_func(channel):
    if GPIO.input(channel):
        print("Laser onderbroken -> "+str(datetime.now()))

if __name__ == '__main__':


    # activeer laser

    GPIO.setup(LaserGPIO, GPIO.OUT)
    GPIO.output(LaserGPIO, GPIO.HIGH)

    #setup de lichtsensor
    GPIO.setup(SensorGPIO, GPIO.IN)
    GPIO.add_event_detect(SensorGPIO, GPIO.RISING, callback=callback_func, bouncetime=200)

        while True:
        GPIO.output(LaserGPIO, GPIO.LOW)
The setup:
Raspberry Pi 1 B+
Light sensor: DOut / AOut

Posts: 5913
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Light sensor not working

Fri Jun 14, 2019 12:13 pm


Can you post a link to the sensor your have so we can see how it works, especially as you say it has digital and analogue outputs.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
Posts: 5868
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Light sensor not working

Fri Jun 14, 2019 6:23 pm

Is it by any chance KY-018?

Details are sparse, but it appears to have a 10k pull-up resistor, with the photo sensor pulling it down.
If you mean it "starts working" when you unplug the sensor board from the Pi, what's actually happening is the Pi's input is floating and and stray electric fields are triggering the call-back.

Return to “Troubleshooting”