In this example we connect an LDR to analog 0 and depending on the value read in we then vary the brightness of an LED connected to Pin 9 using PWM.

The input read from the analog pins will be in the range 0 to 1023. But the PWM function has a the width parameter ranging from 0 to 25 so in this case we use the map() function to convert the values ranging from 0-1023 to 0-255.

In this example we connect a photoresistor to an Arduino, the value read from the photoresistor corresponds to the amount of light present. The photoresistor is connected to analog pin 0 in this example.

A photoresistor (or light-dependent resistor, LDR, or photo-conductive cell) is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector circuits, and light-activated and dark-activated switching circuits.

A photoresistor is made of a high resistance semiconductor. In the dark, a photoresistor can have a resistance as high as several megohms (MΩ), while in the light, a photoresistor can have a resistance as low as a few hundred ohms. If incident light on a photoresistor exceeds a certain frequency, photons absorbed by the semiconductor give bound electrons enough energy to jump into the conduction band. The resulting free electrons (and their hole partners) conduct electricity, thereby lowering resistance. The resistance range and sensitivity of a photoresistor can substantially differ among dissimilar devices. Moreover, unique photoresistors may react substantially differently to photons within certain wavelength bands.

A photoelectric device can be either intrinsic or extrinsic. An intrinsic semiconductor has its own charge carriers and is not an efficient semiconductor, for example, silicon. In intrinsic devices the only available electrons are in the valence band, and hence the photon must have enough energy to excite the electron across the entire bandgap. Extrinsic devices have impurities, also called dopants, added whose ground state energy is closer to the conduction band; since the electrons do not have as far to jump, lower energy photons (that is, longer wavelengths and lower frequencies) are sufficient to trigger the device. If a sample of silicon has some of its atoms replaced by phosphorus atoms (impurities), there will be extra electrons available for conduction. This is an example of an extrinsic semiconductor

A practical example could be a dark room sensor for photography, if the reading approached a critical level an alarm could be activated or even a night light

Here is our sensor, it was part of a 37 in 1 sensor kit, links at the bottom

LDR sensor

Schematic

arduino and ldr schematic

Code

In this example we simply output the reading via the serial port. You can monitor this in the Serial Port Monitor