orangutanAnalog libraries for reading voltages lower than 4V

Hello,
I was wonder if “OrangutanAnalog::readMillivolts(3);” can return a lower voltage then 5000millivolts?
The program I’m using is AVR studio 5.1.
the product that i’m using is Baby Orangutan-B328+Pololu usb Programmer combo.

I’m just trying to find out which is the best way to write my code to read the Vout on a Sharp 2Y0A21 F.https://www.pololu.com/file/0J85/gp2y0a21yk0f.pdf
this is what i have so far

#include <avr/io.h>
#include <pololu/orangutan.h>
#include <pololu/OrangutanDigital/OrangutanDigital.h>
#include <pololu/OrangutanAnalog/OrangutanAnalog.h>
const unsigned char Pin=IO_C3;
long millvolts=0;
long volts=3;

int main(void)
{	
    while(1)
    {
		
	        OrangutanDigital::setInput(Pin,HIGH_IMPEDANCE);
                OrangutanAnalog::startConversion(3);
		millvolts =OrangutanAnalog::readMillivolts(3);
		volts=millvolts*.001;        
    }
}

I’m also confuse on how to convert the voltage reading to distance, because i would like to get an accurate distance from 10cm to 80cm. Can someone direct me in the right direction on doing so? Please.
Thank you in advance.

Hi.

The function OrangutanAnalog::readMillivolts() returns a value between 0 and 5000, where 0 correspond to 0mV and 5000 corersponds to 5000mV, so a lower value than 5000 will be returned if the voltage is less than 5V. There were a few issues with the code you posted; below is a simple example of how to use the function.

#include <pololu/orangutan.h> 

int main(void)
{
  while(1)
  {
    unsigned int millivolts = OrangutanAnalog::readMillivolts(3);

    // now do something with the value ...
  }
}

Also, there is no simple conversion factor between the voltage and distance for that Sharp distance sensor because the voltage does not change linearly with the distance, but you can use the graphs on page 5 of the datasheet to determine an appropriate conversion.

-Claire

Edit: Sorry, Hovic; David has pointed out to me that you are, in fact, using C++ (as you have been in this discussion with him), so you can ignore the first part of what I originally wrote. My original post is quoted below for reference:

Please note that the last part should still be true; you should only need to use “#include <orangutan.h>” or "#include " for your program to work.

- Kevin

I got the program to work.
thank you Kevin, David,and Claire for helping me.