Here are handy analog sensor tips from Dr Simon Monk’s Raspberry Pi Cookbook. You can learn more about these concepts in “Basic Resistor Sensor Reading on Raspberry Pi” Learning System tutorials and other resources at Adafruit by Dr. Monk, Ladyada, and others!
The Raspberry Pi does not have any analog inputs, but that does not mean that you can’t use some types of analog sensors. Using a couple of resistors and a capacitor, you can use a “step response” method to measure resistance. Which is just great if you are using a pot, photoresistor or thermistor.
…Open an editor (nano or IDLE) and paste in the following code. As with all the program examples in this book, you can also download the program from the Code section of the Raspberry Pi Cookbook website, where it is called pot_step.py….