05 Photo Resistors
So you’ve already played with a potentiometer, which varies resistance based on the twisting of a knob. In this circuit, you’ll be using a photo resistor, which changes resistance based on how much light the sensor receives.
MicroView Arduino Code
What you should seeYou should see the potentiometer value being displayed on the MicroView's display.
Code to Note
A “variable” is a stored value you’ve given a name to. You must introduce, or "declare" variables before you use them; here we're declaring a variable called sensorValue, of type "int" (integer). Don't forget that variable names are case-sensitive!
We use the analogRead() function to read the value on an analog pin. analogRead() takes one parameter, the analog pin you want to use ("sensorPin"), and returns a number ("sensorValue") between 0 (0 volts) and 1023 (5 volts).
sensorValue = analogRead(sensorPin);
This is most likely due to a slightly dodgy connection with the photoresistor's pins. This can usually be conquered by pushing the photoresistor down into the breadboard.
Still No Success?
A broken circuit is no fun, send us an e-mail and we will get back to you as soon as we can: firstname.lastname@example.org
Pull Up Resistors
Many of the sensors you'll use (potentiometers, photoresistors, etc.) are resistors in disguise. Their resistance changes in proportion to whatever they're sensing (light level, temperature, sound, etc.).
The MicroView's analog input pins measure voltage, not resistance. But we can easily read voltage by using the MicroView's internal pull up resistors.