NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Project Help and Ideas » Defence system project help
May 18, 2011 by Elementell |
Alright, I'm incredibly new to this, and this will be the first thing I do outside of the guide. Now, I've got a photo resistor, and I'm trying to read the voltage it puts off. I would use the temp sensor project code, but a photo resistor only has 2 leads, instead of 3 like the temp sensor does. Any help? I really don't understand what bits do what bits do what, but you don't have to explain all of that now. |
---|---|
May 18, 2011 by Ralphxyz |
The "photo resistor" is exactly what it says a resister. If you run a voltage through a resistor you will get a voltage drop. If you put 5 volts in you will get 4.5volts or some other lesser value out depending on the resistance. This is from WiKipedia:
So you connect one pole of the photo reistor to the red + rail and the other pin you plug into pin23 on the mcu. Then run the temp sensor code and the ADC value and "temperature" will fluctuate according to the amount of light striking the photo resister. The ADC value should get higher the brighter the light. As a preliminary step you could connect pin 23 to the blue rail (ground) and run the code, what ADC value do you get? Then connect pin 23 to the red rail (+) and run the code, what value do you get? This is a good first project, you should learn a lot. Once you have it running you should change the readout on the LCD to say:
The value of [last_sample] or [temp_avg] will determine the LCD readout. Ralph |
May 18, 2011 by Elementell |
But I already tried that, and although I did get a reading, it was using all 1024 steps, making it read 500 no matter what the light intensity is. I know the resistor isn't defective, I've tested the two that I've used. |
May 19, 2011 by Rick_S |
Do you know what the max resistance is of the photo resistor? If so also place a fixed resistor of the same value from pin23 to the - rail. This will create a voltage divider and you should get readings of 0 to approximately half scale. You could also put a smaller resistor to ground to get a larger swing if you prefer. Rick |
May 19, 2011 by Ralphxyz |
Elementell, do you have a multi-meter? You should check the resistance of the PR. Also did you test in a dark room? Possible your PR is really sensitive and the ambient light is enough to saturate the PR! Ralph |
May 19, 2011 by 6ofhalfdozen |
heya Ementell, Something sounds a bit off to me. Most standard photoresistors have high resistances(ie dark >100K, bright light ~500Ohm. I would expect a range of 0-50ADC counts. While it is possible you found some of the supersensative ones, I am wondering if you got a couple duds or something is wrong in the wiring. You mentioned that you tested them, so you did verify that the resistance is changing in response to light/dark? The ADC is decently sensative, so it should be showing resistance changes of 10's of ohms easily and the temp sensor program will show that nicely. Recently, I got some bigger (1/2" face) CdS photoresistors. In a pack of 10, two of them had some glitch with their glazing and so they were permanently shorted open (~35ohms all the time), while their siblings from the same batch were dark >150KOhm, bright light 500 ohm. I second Ralph's suggestion to break out the multimeter and do some more checking. This should be a nice simple project, a great starter project, but somehow there is a monkey wrench in the works. Though, it is usually stuff like this that really lets you learn more than you planned on, in a good albeit frustrating way. |
May 19, 2011 by OliverM |
Ralph wrote
I suspect there is some confusion about current and voltage. Movement of charged particles, in our case electrons, is current. Voltage is what makes the electrons move. It is the difference in electric potential between two points. When people say, that a point is at a cerain voltage, they mean that between this point and ground is a certain voltage difference. Current and voltage are two different things! Ohms Law connects voltage and current U = I * R ; voltage is current times resistance. If you have a voltage difference accross a resistor, then a current will flow; or if you have current flowing through the resistor, you will have a voltage difference between the two ends of the resistor. Measuring the voltage drop accross a resistor: When you want to measure the voltage drop, you connect the two probes of a voltmeter at each end of the resistor. In effect what you did there is put a second resistor, the multimeter, parallel to the resistor. To avoid the voltmeter influencing the measured value, voltmeters are designed to have a very high resistance. So only a very small current, idealy no current, flows through the voltmeter. The ADC of the MCU is a voltmeter, that measures the voltage differenc between the input pin and ground. If you connect the photoresistor like this
then no current will flow, because the ADC Pin acts as a voltmeter with a very high resistence. As no current flows, there is no voltage drop accross the resistor and both ends are at 5V. And this is what the ADC is measuring, 1024 counts. In this setup the photoresistor acts like a pull up resistor. I suggest that you use this setup:
With this setup you have a current flowing through the photoresistor and at point X the ADC can measure the voltage drop accross the Resistor. Oliver |
May 19, 2011 by Rick_S |
Pretty much what I said only with a lot more finesse :) Rick |
May 19, 2011 by Elementell |
The photoresistor works fine, I connected it to a 9v power supply with an LED, in normal light the LED slightly glows, when I put my finger over the resistor the LED doesn't light at all, and if I point a strong light at it the LED goes full power. The photo resistor is fine, and it still reads 1023/1024 ( I also tried the smallest one in the set, which doesn't light up the LED at all unless a heavy light is shined on it ) Also, something could be wrong with my kit but, the LCD reads 50 degrees when the temperature sensor isn't connected, and nothing is going to the 23rd pin |
May 19, 2011 by Rick_S |
Did you try wiring it as described above? Also when the pin is floating the readings will be erratic. Rick |
May 19, 2011 by Elementell |
I don't have a strong enough resistor, I tried a 10k resistor(the strongest I have) and it didn't change anything. The different photoresistors I have use different resistances though, the smallest resists the most. |
May 19, 2011 by Elementell |
Oh, I finally read what you meant about the photoresistor in this instance being used as a pull up resistor(not entire sure how that works but whatever), I connected it the way Oliver told me to and it works. Thanks guys, I'll post if I run into any more problems (which is inevitable) |
Please log in to post a reply.
Did you know that our USB NerdKit comes with everything you need to get started with microcontrollers? Learn more...
|