Go Down

Topic: reading analog input + linearization (Read 641 times) previous topic - next topic



i am using arduino due R3 and i want to read analog input (range changes between 4-20mA)

and i want to sample the reading analog values so i want to linearize them

how i can do this/which c code i should implement to arduino  ?


For measuring currents you need an resistor, connected e.g. between an anlog input and GND on the Arduino, then connect the sensor outputs to that resistor. The voltage on the resistor equals U=R*I, where I is 4-20mA, and U should be in the range of the analog input of the Arduino, typically max. 5V (for AREF=5V). When R is 220 Ohm, you'll get Umin = 0.88V for 4mA and Umax = 4.4V for 20mA. The exact values depend on the exact resistance of R, so you should measure this value yourself. On the analog input, AREF (5V) equals 1024, the high and low analog input values are Amin=1024*Umin/AREF and Amax=1024*Umax/AREF.

The linearization depends on the characteristic of the sensor. When it is linear, you only have to match Umin with the lowest physical value (Pmin), and Umax with the highest value (Pmax). With above constants the physical value can be calculated by e.g.
PhysicalValue = map(analogRead(ANALOG_PIN), Amin, Amax, Pmin, Pmax);

When the physical values are low, e.g. your sensor measures 0-1 Bar, you can multiply Pmin and Pmax by 1000 to get the physical values within 0-1000 mBar, to avoid time consuming floating point calculations and truncations in map(). Similarly you should round Amin and Amax to the nearest integer values.

When the sensor characteristic is not linear, e.g. quadratic or exponential, the calculation becomes more complicated, of course.


I'll bet you wish you remembered what you learned in math class in high school...   ;)

Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - tinyurl.com/q7uqnvn
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

Go Up