Arithmetic Question

Hello,

I have a simple arithmetic question I can't seem to figure out. I am reading data from a sensor (OPT101) that is connected to A0, and I would like to take that value and enter it into my equation ( (391/880)x + (1/880) ). However, no matter what the input is, the output is always coming out to zero.

This is the code:

  int pinRead0 = analogRead(inPin0);
  float pVolt0 = pinRead0 / 1023.0 * 5.0;
  Serial.print(pVolt0, 4);
  float lightintensity = pVolt0 * (391/880) + (1/880); 
  Serial.print(lightintensity,4);

What did I do wrong?

Thank you in advance

Integer math. you have to learn to think like a computer.

391 / 880 == 0 1 / 880 == 0

So you have pVolt0 * 0 + 0 and that will be 0 all day long.

1 / 880.0 = 0.0011363636...

Make the 880 a float (by writing 880.0) and it will evaluate as a float.

Try:

  float lightintensity = pVolt0 * (391.0/880.0) + (1.0/880.0);

That's definitely good to know. It worked. Thank you so much for your help!

(391/880) + (1/880) = 392/880 = 196/440 = 98/220 = 49/110