0

I'm trying to detect an LED light using a phototransistor and Pi3. I don't know how and where to start with the code for the RaspPi to detect light using phototransistor. may you please help, this is for my final year project. Thanks in advance

  • The first part might be of interest for you: raspberrypi.stackexchange.com/a/72862/19949 – Ghanima Sep 28 '17 at 19:15
  • I'm confused, the first part does not contain the an answer sir. The circuit isn't my problem the python code is. I have been struggling to writ a code to detect light using a phototransistor – Kayvee Sep 28 '17 at 20:35
  • Depending on the hardware used you may have a problem before you write a single line of code. If the phototransistor is designed for IR it may not detect the LED. You could wire up a basic dark detecting LED (a google search will turn up several variations) to test the hardware configuration first. – Steve Robillard Sep 28 '17 at 20:51
1

I also want to use a photo transistor to detect the leds on my google home when it speaks. I have chosen to buy a ready made detector circuit for a few pounds off ebay (amazon also do them) This connects to GPIO pins and has a digital output if the light gets to a level which is adjustable on the detector. I already have a very similar device with a microphone on instead of the photo transistor and that works really well so I am hopefull the light sensor one will. There are 2 versions, one with a photo transistor and one with a light sensitive resistor. You might want to consider it.

My sound circuit is connected to the 2nd pin of the GPIO There are 2 bits of code.

# setup Pi's GPIO (define pin #2 as input pin)
GPIO.setmode(GPIO.BCM) # use board pin numbers
pin = 2
GPIO.setup(pin, GPIO.IN) 

#create a loop to catch a change in the digital output
while GPIO.input(pin)==0:
    a=0   #do nothing
#start do something code here e.g.
print("the light is there")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.