12

I'm not sure how to say it, but I would like to read the 'amount of light' with my Raspberry Pi. By the 'amount of light' I mean a number between 0 and 100 (for instance) where 0 is no light/dark and 100 is lots of light (which is, as I understand, some arbitrary number, 'lots of light').

The problem is: I've read that the Raspberry Pi only has digital input/output ports, not analogue inputs. Is there still a way to read analogue inputs, and if so, what hardware do I need?

To set the level of knowledge: I did manage to output control LEDs via the RPI.GPIO library. I did not READ any input yet.

1
  • That's a photoresistor element.
    – okertanov
    Commented Feb 28, 2013 at 15:57

5 Answers 5

8

The component you are looking for to read the level of light is a light dependent resistor.

As you rightly stated in the question; the Raspberry Pi only has digital input. Therefore you can create an RC Charging Circuit. I advise reading this tutorial regarding RC charging circuits.

This blog post explains in detail how you can check light level using an RC circuit better than I ever could

Would recommend playing around with the GPIO pins a bit more (using a component like a mini push button switch) before jumping straight into this though!

2
  • 1
    +1 for the RC charging idea. That's how old analogue PC joysticks used to work. Another way would be to connect an analog-to-digital converter (AD) to the GPIO. More complicated, but almost certainly more accurate. For the sensor, a photo diode or a photo transistor are also options.
    – Frepa
    Commented Mar 1, 2013 at 0:57
  • The blog post is awesome!
    – Michel
    Commented Mar 1, 2013 at 21:36
3

There are inexpensive I²C modules (for Arduino) you can use for this.

Look for "BH1750FVI Digital Light Intensity Sensor Module", etc.

3

Besides the approaches suggested in other answers, you could also achieve this using a USB webcam. A list of Raspberry Pi supported webcams can be found in RPi VerifiedPeripherals: USB Webcam.

There was a Stack Overflow question about accessing webcam stream from Python, Python API to access webcam stream?.

Similarly, there was an Raspberry Pi-specific tutorial on webcam image processing in Python, Physical computing with Raspberry Pi: Basic Image Processing.

The advantages in using a webcam for your project is that you could define on the software side what the "amount of light" is for your purpose, and that you could obtain much more information (for example, a 2-D array of RGB values). A possible disadvantage of the webcam approach is a smaller angle of view compared to a typical photoresistor.

1
  • Very nice, i think i'll use my lunch break to buy one ;-)
    – Michel
    Commented Mar 4, 2013 at 11:02
2

Here's an US$8 board from Adafruit which allows you to determine the amount of light using the Raspberry Pi's I²C interface: Adafruit TSL2561 Digital Luminosity/Lux/Light Sensor Breakout. The product website also has links to tutorials and sample code.

-1

This module here provides 8 analogue inputs for the Raspberry Pi and uses the SPI interface http://www.sf-innovations.co.uk/custard-pi-3.html

1
  • Please add some more detail to your answer, link only answers are not appropriate for StackExchange sites. Also blindly recommending a product does not help the OP who has little experience with the GPIO.
    – Darth Vader
    Commented May 31, 2016 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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