Floating point math Arduino Uno

Hi

I'm trying to convert an analog readout in the range [0-1023] to volt in a 5 volt range.

I'm using: voltCalc = 5/1024 * pinread;

But the calculations are not correct.

Upon debugging, i find that if a try: float factor = 5/1024;
and send this to the serial monitor, it yields zero.

Anyone who can help?

/Jon

Try
voltCalc = 5.0/1024 * pinread;
to ensure a float calculation is performed.

Upon debugging, i find that if a try: float factor = 5/1024;
and send this to the serial monitor, it yields zero.

That is the expected and correct result for integer division.

Can you use the Arduino map() function?

ty_ger07:
Can you use the Arduino map() function?

He could, but the direct calculation, while a might slower because of the floating point, is easier to understand. And you lose a lot of precision since you map 0-1023 into 0, 1, 2,3,4 or 5. (map is integer only)