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.

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
Michel
  • 1,124
  • 4
  • 14
  • 21

5 Answers5

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!

Francis Dean
  • 196
  • 2
  • 5
  • 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 Mar 01 '13 at 00:57
  • The blog post is awesome! – Michel Mar 01 '13 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.

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
John La Rooy
  • 11,947
  • 9
  • 47
  • 75
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.

milancurcic
  • 616
  • 6
  • 9
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.

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
Richard Żak
  • 139
  • 3
-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

seggy
  • 9
  • 2
  • 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 May 31 '16 at 08:42