We'll start with a basic photocell. This is a resistor that changes resistance based on how bright the light is. You can read tons more about photocells in our tutorial but basically we'll be able to measure how bright or dark the room is using the photocell. Note that photocells are not precision measurement devices, and this technique is also not very precise so its only good for basic measurements. For precision sensing, you'd want a digital lux sensor like this one - we don't have a tutorial on connecting that to the Pi but we do have example code for Arduino.

Wiring is simple using the Adafruit Pi Cobbler. Connect the blue right rail to ground and the red left rail to 3.3V. Then connect one side of the photocell to 3.3V and the other side to Pi GPIO #18 (you can use any pin but our example code is for #18). Then connect a 1uF capacitor from #18 to ground. Make sure the negative side of the capacitor (marked with a - down the side if its electrolytic) goes to ground. The capacitor just needs to be rated for 5V or greater, its really unlikely you'll find a 1uF that has less than 16V rating.

Now on your Pi, make sure you've installed RPi.GPIO version 0.3.1a or later. Check here for instructions how

Now copy & paste the following code into a new file called RCtime.py and chmod +x it
```#!/usr/bin/env python

# Example for RC timing reading for Raspberry Pi
# Must be used with GPIO 0.3.1a or later - earlier verions
# are not fast enough!

import RPi.GPIO as GPIO, time, os

DEBUG = 1
GPIO.setmode(GPIO.BCM)

def RCtime (RCpin):
GPIO.setup(RCpin, GPIO.OUT)
GPIO.output(RCpin, GPIO.LOW)
time.sleep(0.1)

GPIO.setup(RCpin, GPIO.IN)
# This takes about 1 millisecond per loop cycle
while (GPIO.input(RCpin) == GPIO.LOW):