Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Reading a photoresistor


  • Please log in to reply
4 replies to this topic

#1 James

James

    Advanced Member

  • Members
  • PipPipPip
  • 56 posts

Posted 28 November 2010 - 08:14 AM

I'm attempting to create a circuit that will read values from a photoresistor. The documentation on the resistor says it may vary from 1kOhm in full light exposure to 50kOhm in complete darkness. The wiring diagram provided with the sensor uses it in a voltage divider as follows:

Vdd (+5 volts) ---(Photo Resistor)--- InputPin ----- 2kOhm Resistor ---- Vss

Sorry for the crude schematic - is there a better way to input these? At any rate, the provided configuration is tuned to trigger the input at 1.4v which is appropriate for a BASIC stamp. I'd like to modify the circuit for use with the Netduino. I tried using the circuit verbatim with the Netduino analong input pins but it appears to output a static value. What's a good way to wire this up with Netduino?

Code used to read the analog pin:

AnalogInput photo = new AnalogInput(Pins.GPIO_PIN_A1);

while (true)
{
    Thread.Sleep(200);
    var light = photo.Read();
    Debug.Print(DateTime.Now + " " + light.ToString());
}

PS - The analog project tutorials would be very helpful for figuring out this sort of issue ;)

#2 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 28 November 2010 - 01:02 PM

Any way you can post a photo? Seems like it should work, although the analog inputs only support 3.3v, so maybe you're outside of that with the 5v connection. My other guess is that you're not feeding 3.3v to the aref pin. This link might be helpful: http://forums.netdui...ch__1#entry4703

#3 Eric Burdo

Eric Burdo

    Advanced Member

  • Members
  • PipPipPip
  • 130 posts

Posted 28 November 2010 - 01:04 PM

James... a quick check. Are you using the AREF pin? Have you connected that to your voltage output? I've found that if you don't connect the AREF, you get one of two results. A lot of bouncing for values... or a pretty stead MAX value (usually, 1024?)
~ Eric D. Burdo ~ http://brick-labs.com/

Today LED's, tomorrow, the world!!! Well, OK, maybe servos.

#4 hari

hari

    Advanced Member

  • Members
  • PipPipPip
  • 131 posts

Posted 28 November 2010 - 02:14 PM

As others mentioned, make sure you connect AREF.
Here's a blog posted when I discovered about the AREF pin.

#5 James

James

    Advanced Member

  • Members
  • PipPipPip
  • 56 posts

Posted 30 November 2010 - 05:43 AM

Thanks everyone - looks like tying AREF to 3.3v did the trick. Bill that tutorial on reading a potentiometer is excellent!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.