Map Function sensor with 4.2V max output

Hi,

I have a question concerning the usage of the map function.

I have an Arduino Uno Board that is connected to a soil moisture sensor. The sensor has a max output voltage of 4.2V.

I would like to use the map function to set the readings between 0 - 100.

I know that the reading can be between 0 - 1023 however since the max ouput voltage of the sensor is 4.2v I am not sure if the max reading is 1023 or that the max reading is (1023 / 5) *4.2 = 859.32.

I hope that you can help me out with this.

Regards.

What is the analog reference set to? What is the measured value of Vcc?

The default analog reference is Vcc, so if Vcc is 5.00V, then, yes, 4.3V would be 859.

1023 vs 1024, anyone?

You did not show us your wiring so it is impossible to answer your question, but (and the reference documentation points this out at least twice) the map(...) function only works with integers. The reference documentation shows the function. You may need a similar function with every use of "long" replaced by "double". The name of the function should be something new as well, perhaps "mapDouble".

groundFungus:
1023 vs 1024, anyone?

Does not matter that much! :wink: