Arduino Uno assembled in US now available in the Store @arduino & Adafruit #TeamArduinoCC

Analog signal processing

I am taking analog measurements and can't figure out how display decimal fraction numbers. I'll elaborate, I know that the arduino uses a 0-1023 to a 0-5 Vdc conversion. When I apply 1.37 Vdc I don' get it displayed, I only get one volt increments and need evrything in between. Do you know where I could get some sample code to do this? or is it even possible to have that resolution?
TESBill

Posts: 5
Joined: Thu Aug 02, 2012 11:38 pm

Re: Analog signal processing

Something like this: (substitute appropriate pin numbers for your project)
Code: Select all | TOGGLE FULL SIZE
`int raw = analogRead(analogPin);  // get the raw readingfloat volts = (raw * 5.0)/1024; // scale raw reading to volts`

Posts: 38666
Joined: Sat Feb 07, 2009 10:11 am

Re: Analog signal processing

The math is good but I still only have 1vdc increments. Are there any limitations I am unaware of?
int sensorPin = A0;
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
Serial.begin(9600);
}

void loop() {
// read the value from the sensor:

float mAval = (raw1*20)/1024;
delay(2000);

Serial.println(mAval,2);
}
TESBill

Posts: 5
Joined: Thu Aug 02, 2012 11:38 pm

Re: Analog signal processing

Code: Select all | TOGGLE FULL SIZE
`float mAval = (raw1*20)/1024;`

All the terms in your expression are integers. Try making the multiplier a floating point number as in the example I provided.

What's happening is that all the arithmetic on the right side of the '=' is being done as integer arithmetic, so you're losing the fractional part. The conversion to floating point is done after the calculation is completed. By using 20.0 for your multiplier, you are forcing the compiler to convert raw1 to floating point before the multiply and divide operations are executed.