Society of Robots - Robot Forum

General Misc => Misc => Topic started by: dannytemmerman on February 22, 2009, 10:06:39 AM

Title: Variables
Post by: dannytemmerman on February 22, 2009, 10:06:39 AM
I am wondering how the value of a sensor is known. Does the IC check the voltage and than say a value to this voltage or what? I don't understand how this goes. Would somebody please explain it to me?


Title: Re: Variables
Post by: Razor Concepts on February 22, 2009, 10:42:01 AM
The 5v supply of the microcontroller is connected to the VREF pin. (Voltage reference). So if your sensor reading is outputting 2.5 volts, the microcontroller will divide 5 by 2.5 to get one-half, and then multiply it by 255 (for 8 bit ADC). I doubt the microcontroller actually goes through multiplying and dividing (there should be a more accurate way), but thats basically how it's done.
Title: Re: Variables
Post by: ArcMan on February 22, 2009, 01:09:09 PM
I am wondering how the value of a sensor is known. Does the IC check the voltage and than say a value to this voltage or what? I don't understand how this goes. Would somebody please explain it to me?

I'm assuming you're talking about the value of an analog sensor.  Many microcontrollers come equipped with what's called an analog-to-digital converter (A/D converter).  This converter translates an analog voltage to a digital value used by your microcontroller code.  For example, a 10-bit A/D converter could convert a 0V - 5V analog input signal into a digital value with a range of 0 - 1023.