# 21. Photoresistors, trimming, and ADC¶

You have learned some of the basics of building prototypes of electronic circuits. In this lesson, you will get considerably less guidance on the do-it-yourself exercise, and will have to rely on what you have learned so far and online tutorials and data sheets.

## Photoresistors¶

Optoelectronic devices are devices that can detect and control light. Our primary interest is detection, since we will be building a spectrophotometer. There are many optoelectronic detectors, including photodiodes, phototransistors, and photoresistors. A photoresistor (pictured below) is a resistor whose resistance is dependent on the intensity of light incident on its surface. The more light, the lower the resistance.

Image by Nevit Dilman,CC-BY-SA 3.0 licened.

By measuring the voltage across a photoresistor, we can get a measure of the amount of incident light. In the exercise below, you will measure exactly that (which you will also do when you build your spectrophotometer).

## Trimming resistances¶

In the exercise below, you will likely set up voltage dividers. It helps to have good control over the resistances in the dividers. You have many different resistors in your kits, but what if you want to obtain a resistance you do not have? You can use a couple simple principles to do that.

1. Resistances in series result in resistance $$R = R_1 + R_2 + R_3 + \cdots$$.

2. Resistance in parallel result in resistance $$R = \left(R_1^{-1} + R_2^{-1} + R_3^{-1} + \cdots\right)^{-1}$$.

Point (2) means that resistors in parallel always have a lower resistance than the largest individual resistor.

Say you have an available resistor just below the value you want. You can trim the resistance up by adding small resistor or resistors in series to make up the difference.

Now say you have an available resistor just above the value you want. You can trim the resistance down by adding a small resistor or resistors in parallel to bring the total resistance down.

## Do-it-yourself exercise 9: Photoresistors with ADC¶

2. Given that you can get negative numbers coming into Python from Arduino, you need to allow for that. If you are screening the input data using regular expressions in your parser (as I did in the lessons), you have to include the minus sign in your pattern, for example like this: re.compile(b"\d+|,|-").