Hello!
Brand new to Arduino and I've been going thru the built in examples in the tutorials to learn what its all about. In the wiring for the tone pitch follower, it calls for a resistor to ground on one end of the photo resistor and I don't understand why it is necessary. Why can't the photo resistor simply be put inline between the 5v and the analog input pin?
This is the description (taken from the eample in the Arduin IDE 1.6.6)
/*
Pitch follower
Plays a pitch that changes based on a changing analog input
circuit:
* 8-ohm speaker on digital pin 9
* photoresistor on analog 0 to 5V
* 4.7K resistor on analog 0 to ground
created 21 Jan 2010
modified 31 May 2012
by Tom Igoe, with suggestion from Michael Flynn
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Tone2
*/
Following that, the circuit looks like
Vcc --- photoresistor -+- resistor --------+--- GND
| |
+- input impedance -+
|
pin
You have made a voltage divider. The input impedance is always there (internally to the micro controller) and its value is quite high (lets say 100k Ohm).
If you don't use the resistor, the voltage on the pin is determined by the photo resistor and the input impedance. Because the resistance of the photoresistor is low compared to the input impedance, you will always read a high level on the input pin.
Because the 4k7 resistor has a relatively low value compared to the input impedance, the input impedance has a minor effect on the reading.
Formula to calculate the voltage on the pin
Vin = (resistor / (resistor + photoresistor)) x 5V
If there is light on the photoresistor, its resistance is low compared to the resistor and filling in the numbers
Vin = (4700 / (4700 + 0)) x 5V = 5V
If there is no light on the photoresistor
Vin = (4700 / (4700 + 47000)) x 5V = 0.5V
Notes:
light and dark might have been swapped arouund
the photoresistor value is a fictive number in the above; if you have a multimeter, you can measure it.
The input impedance for CMOS chips is effectively infinite, certainly in the 10^9 to 10^11 ohms
range, so with just a photo-resistor to Vcc analogRead() would return 1023 all the time.
Try it.
Analog pins sense voltage, they take (almost) no current. So you always have to make your
signal a voltage signal.
For a resistor the simplest way to get a voltage from it is to pass a current through it, so you can
use a current source, but a resistor is a cheaper alternative. (Current sources are active bits of
circuit that maintain a fixed current using feedback).
AWOL:
Because you need to make a voltage divider
sterretje:
You have made a voltage divider.
Fantastic! Thank you guys so much! I took a class the other night and the explanation I got from the instructor was "because you need it there" Giving a name to the circuit gave me everything i needed to spend some more time on the university of google and understand what's happening!!
Thanks again!
Actually, it makes more sense to connect the photoresistor from the input pin to ground. If you use INPUT_PULLUP for your pinMode (instead of INPUT, do not use INPUT at any point), you can use the internal pull-up instead of adding one to Vcc.
Try it out!