Light Monitor for the RPi without extra converter, etc.
Wanting to monitor the August 2017 eclipse, I googled a simple way to use a Raspberry Pi (RPi)
to measure a variable resistance, like a CdS photocell or a variable resistor (potentiometer).
The 'RC timing' method measures the time it takes to charge a capacitor through the variable resistance,
see Dr. Monk's page linked below.
Here's the RPi and the light monitor:
Here's the schematic of the circuit (slightly embellished over Dr. Monk's):
A closeup of the circuit board and some comments are in the first page of the handout (below.)
The handout also has a plot of the light intensity during the eclipse (green line):
sunny with clouds at first showing the expected light change (red curve).
But then a heavier cloud cover moved in for the rest of the eclipse.
The sun did come out again - about 1/2 hour after the eclipse ended.
Real time monitoring program:
The file light_liveplot_v2.txt linked below can be downloaded to the RPi,
changed to have a .py extension,
and run with the Python 3 IDE.
This will start a real time light monitor plot using the hardware; stop the plot by closing the plot window.
The plotting is done using the matplotlib module which can be added to the RPi using terminal command:
sudo apt-get install python3-matplotlib
Here's what the output of the real time plotting looks like:
Using the GPIO in Scratch2
This scheme can be implemented in Scratch using the GPIO blocks,
however, any kind of loop construct to do the timing took longer in
overhead than the max ~5 ms RC time of this setup.
Avoiding loops, it is possible to tell 'light' from 'dark' using this simple program:
Some useful links:
Adafruit pages about photocells and their "perma-proto" breadboards:
https://learn.adafruit.com/photocells/measuring-light
https://www.adafruit.com/category/466
Dr. Monk's page about the RC timing method to measure resistance:
http://www.doctormonk.com/2013/12/analog-sensors-without-analog-inputs-on.html
YouTube about using Animation to make a live plot in python: