I ordered 2 of these a couple weeks ago along with the capacitors listed at Adafruit plus heat shrink tubes and extra breadboard wires. Anyway, these things are so tiny I thought they'd been left off the order. But before complaining, I went through my Pi stuff again and found them.
I had a couple problems getting this device to work:
1. I wired it up like the Adafruit lesson shows (1 mF capacitor and GPIO on the ground side), straight to 3.3V pin on the other side. That didn't work. Looking around some more, I found--
Their example added a resistor on the ground side of the circuit. This eventually worked.
2. My batch of assorted resistors from Radio Shack comes with a list of how many of each kind in the package but the taped-together strips are not labeled. The "pi-spy" interface to the photo sensor added for a 2.2k resistor on the 3.3V side of the circuit. I did a google for "resistor 2.2k" but the color coding shown didn't match anything from my Shack assortment (after a non-trivial search using a magnifying glass). The on-line color-band "calculators" seem difficult, but then I found a "resistor widget" app for my Mac.
Here's my Python test program ("adapted" from various sources):
import RPi.GPIO as GPIO, time, os
PHOTO_pin = 22
def PStime (pin):
reading = 0
# Takes about 1 millisecond per loop cycle
while (GPIO.input(pin) == GPIO.LOW):
reading += 1
if reading > 1000: # don't loop forever!
for x in range(20):
What am I going to use this for? I want my Pi to send a warning if the main 110V power fails. So I'll set it up as follows:
a. UPS backup battery plugged into 110V.
b. Pi and Internet modem plugged into UPS.
c. Photosensor (above) pointed at an LED that's plugged into non-UPS 110V.
d. When external power fails a little Python program (which runs once per minute) notes the sensor change and sends out a text message and an e-mail before shutting itself down.
BTW: Are you familiar with the Linux (and UNIX before it) scheduling service "crontab"? If not, you should learn about it.