map command not working for max value

hello friends,

i m using two sensor 1) Air temperature(pt 1000) type
2) Humidity sensor

i have converted both sensor output to 0 to 1 volt accordingly

i.e. 1) air temp sensor range -40 dcel to + 60 dcel = 0 to 1 volt
2) humidity sensor range 0% to 99.9 % = 0 to 1 volt

both sensor output perfectly linear .

i gave that output to arduino uno board using map command.

temp = map(tempRaw, 0, 1023, -40, 60);
Humidity = map(HumidityRaw, 0, 1023, 0, 99);

i m facing issue with maximum values

i m getting both sensor output at zero voltage perfect means

air temp = 0 volt >> -40 dcel but at 1 volt i m getting maximum value of 52 to 53 dcel

Humidity = 0 volt >> 0% but at 1 volt i m getting maximum value of 91 to 93 %

analog voltage has no issue ..

help me for the same...

i am new for arduino so plz forgive me if i asked stupid question ,but answer my question ,waiting for reply

in this case, make a minimum sketch showing the problem:

/*
  by noiasca
  https://forum.arduino.cc/index.php?topic=666059
*/

void setup() {
  Serial.begin(115200);
  Serial.println(F("\nStart"));
  int tempRaw = 1023;
  int humidityRaw = 1023;
  int temp         = map(tempRaw, 0, 1023, -40, 60);
  int humidity     = map(humidityRaw, 0, 1023, 0, 99);

  Serial.println(temp);
  Serial.println(humidity);
}

void loop() {

}

Output:

Start
60
99

Conclusion: map is working correct in this case.
Assumption: You are not feeding the function with 1023.
Check what you really get als tempRaw.

Amangesh:
temp = map(tempRaw, 0, 1023, -40, 60);
Humidity = map(HumidityRaw, 0, 1023, 0, 99);

i m facing issue with maximum values

i m getting both sensor output at zero voltage perfect means

air temp = 0 volt >> -40 dcel but at 1 volt i m getting maximum value of 52 to 53 dcel

Humidity = 0 volt >> 0% but at 1 volt i m getting maximum value of 91 to 93 %

only gussing here since you DID NOT POST YOUR CODE but you probably changed the analog reference in your code to use 1.1V

if so, 1V would give you an analogRead of 930 not 1023.... hence you not getting the maximum value

hope that helps....

read again answer 2.
Then post a link what analogReference(INTERNAL); is doing really.

hello friends,

i m using two sensor 1) Air temperature(pt 1000) type
2) Humidity sensor

i have converted both sensor output to 0 to 1 volt accordingly

i.e. 1) air temp sensor range -40 dcel to + 60 dcel = 0 to 1 volt
2) humidity sensor range 0% to 99.9 % = 0 to 1 volt

both sensor output perfectly linear .

i gave that output to arduino uno board using map command.

analogReference(INTERNAL); //sensors are 1V max

temp = map(tempRaw, 0, 1023, -40, 60);
Humidity = map(HumidityRaw, 0, 1023, 0, 99);

i m facing issue with maximum values

i m getting both sensor output at zero voltage perfect means

air temp = 0 volt >> -40 dcel but at 1 volt i m getting maximum value of 52 to 53 dcel

Humidity = 0 volt >> 0% but at 1 volt i m getting maximum value of 91 to 93 %

analog voltage has no issue ..

help me for the same...

i am new for arduino so plz forgive me if i asked stupid question ,but answer my question ,waiting for reply

hey friends,

thank you for help,

its working with modifying by

temp = map(tempRaw, 0, 930, -40, 60);
Humidity = map(HumidityRaw, 0, 930, 0, 99);

but one thing is there...

my analog output is stable...but display values are fluctuating in high range

e.g. temp is fluctuating from 23 dcel to 26-27 dcel

Please show a full sketch. If possible, a very small sketch that shows the problem.
The type of 'temp', 'tempRaw', 'Humidity' and 'HumidityRaw' makes a big difference (are they 'int', 'float', 'unsigned long' ?).

Are you using an Arduino Uno ?
Its internal reference voltage is somewhere between 1.0 to 1.2 Volt. You have to determine the actual voltage for each individual board.
After setting "analogReference(INTERNAL)" you can measure the AREF pin and use that value in the sketch.

I prefer to calculate the voltage on the pin first, so you can verify that with a multimeter and measure the actual voltage on that pin.
After that, convert it to a temperature or percentage.
If you do it that way, then it is easier to use 'float' variables and calculate the result without the "map()" function.

Do you use the average of a number of samples ? Or do you use a software filter to reduce the noise ?

I've merged your cross-posts @Amangesh.

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.