I'm currently working on a project and need to read a pressure sensor using an Arduino Uno R3. The sensor requires a supply voltage of 5V, measures in a range from -900 to 2000 mbar, and outputs analog voltages between 0.5V and 4.5V.
I've successfully read and calibrated the sensor. However, the sensor still provides inaccurate readings. Since the negative range of the sensor is not relevant for the project, I thought about neglecting this range. This way, I can map my 10-bit values to a smaller range. At 0 mbar, I get a voltage of 1.76V, so I wanted to focus on this range, specifically 1.76V to 4.5V. I tried to implement this using the map function, but it didn't work as expected.
I would be very grateful if someone could help me. Is the approach with the map function correct?
Can you show a schematic (or draw on paper how it is connected) and show a photo ?
The sensor is probably ratiometric, you should power it with the 5V pin of the Arduino Uno. The GND wire to the sensor should not be used for something else.
Use the range of 0.5 to 4.5V, and don't try to improve that. Everything you do will make it worse. A lot worse. You have to keep the ratiometric principle working.
With averaging, the resolution can be increased beyond the 10-bit. The overall accuracy will not increase, but sometimes it is nice to see a slowly rising or falling value.
I strongly prefer to use floating point for the calculations, that is the best way for averaging and to increase the resolution beyond the 10-bit.
UPDATE:
I had a discussion on this forum about "averaging", "oversampling", and "decimating". I used the term "averaging" here, but others might call it "oversampling". To goal is to use all the information that those samples have. Simply take a number of samples, then calculate the average with a floating point calculation. That's all. There is no need to remove bits that are noise, because that is purely theoretical.
1.76 Volt is an analogRead of 360 (scale 0..1023)
4.5 Volt is an analogRead of 920
so
int raw = analogRead(A0);
pressure = map(raw, 360, 920, 0, 2000);
Note that the analogRead() in the range has only 920- 360 = 560 steps for 2000 mbar.
So the pressure will be reported in ~4 mbar steps.
Furthermore noise might add an inaccuracy, resulting in maybe 12 mbar accuracy
Without mapping the accuracy was 3.55 mbar. I already tried it like you said and the accuracy became worse. Thats why I thought i did something wrong in the function.
You can increase the sensor resolution and precision by oversampling and averaging, e.g. add up 16 measurements and divide by 4 to increase the resolution from 10 bits to 12 bits.
And loose ratiometric behaviour. The ADS is an absolute A/D, without access to it's reference.
These sensors don't output a voltage, they output a ratio of their supply.
0.5 to 4.5volt is only true if the supply is 5.0volt.
If the supply is 5.2 volt, that range becomes 0.52 to 4.68volt.
Better to say that the sensor has a range of 10% to 90% of it's supply. Or that the A/D returns 10-90%. Work with A/D values, not voltages.
Leo..