I mean, a sensor can have a characteristics like Y=X^2 (X = the input, Y=the output). That is, I can easily find X if I know Y. Why is the linearity so important?
Yes, you could have a sensor that responds like that (Y=X^2) Your sensor must still reliably do that. In a typical sensor, Y=cX+d where c and d are ideally constants. Due to various factors, they usually aren't simple constants. How close c and d are to really being constants is what is referred to as linearity. In your example, you would probably have something like Y=(cX+d)^2 , which would cause all kinds of fun.
Linearity as in "linear response" isn't the problem. Linearity as in "the Y values closely fit the expected linear response" is what you want. In your example, you wouldn't be concerned with whether the a plot of Y and X is a straight line. You would want your plot to closely match the expected parabolic curve. It most likely won't perfectly match. For a sensor with a linear response, you would say that the linearity is poor. For one like your proposed sensor (Y=X^2) I don't know what you'd call it - maybe just "poor response."
Poor linearity in a typical sensor means that you have to do more work to get X if you know Y. With an ideal sensor with a linear response, you can calculate X eaisly if you know Y. With real sensor with good linearity, you can (with in reasonable limits) determine X from Y. With a real sensor with poor linearity, you have to go to greater lengths to determine X when you know Y. Maybe its response varies greatly with temperature, so you have to track temperatur as well and use it when determining X from Y. Maybe it just isn't very linear, and you have to use some funky curve to relate X and Y. In either case, your job as an engineer is much easier if the sensor closely approximates the expected straight line. Often times this works out to making a system simpler to calibrate and more reliable - but also more expensive since a better sensor usually means more expensive. Sometimes you'll want to go with a cheaper and less linear sensor, and compensate for its failings in software.
A lot of stuff still uses relatively low-powered or cheap microcontrollers, 8-bit micros haven't gone away.
The upshot is that:
- Maths is expensive (in CPU cycles)
- Floating-point and/or signed maths is even more expensive
- Doing maths introduces errors / adds to error bounds
- Type conversion can introduce coding errors
- Having to handle more bits than your CPU is natively capable of gets very expensive in maths terms.
- Having to do any of this means having to include maths libraries (more code, more space, more RAM, more storage)
If you look at the hoops a CPU has to jump through (in machine instructions executed to achieve one mathematical operation) to do signed floating-point maths, and the resulting output precision, you might decide that just using a linear sensor is a more attractive prospect.
Many monitoring circuits for sensors are purely analogue and therefore the complication of mapping a value measured via a square root law is really not trivial. If the measurement is digitized then using math inside the CPU is fairly trivial in comparison but, like I said, many circuits are purely analogue.
Linearity minimises the influence of imperfections later in the circuit. For instance, say there is a small constant level of noise introduced by a preamplifier. If you need to correct for the response of that Y2 sensor of yours, the effective noise level (SNR) is proportional to the inverse function's derivative, i.e.
∂X/∂Y = d/d X √Y = 1/2 √Y ∝ 1/X.
At low levels of X, this effective noise tends to infinity (equivalently, the SNR approaches zero). In reality, it's not quite as dramatic since the pertubations aren't infinitesimal, but the problem is real: where the output voltage is only weakly correlated to the measured value, the maximum attainable accuracy suffers.
You might now think to filter the noise somehow, but there comes another problem: frequency filtering is basically linear, and to work well it assumes the signal itself has come linear – to use the physics terminology, you'd like filtering to commute with measuring. That's not given with a nonlinear sensor, for instance if you have a high-frequency signal in your X quantity around some X0, and filter the resulting Y signal, you'll get a constant offset above the corresponding Y0 value, because the square-nonlinearity "bends the pertubation upwards".
Now if you say then let's first digitally correct the nonlinearity. Next problem: you can only take discrete samples. PCM-sampling is very well under control mathematically, but guess what: it assumes everything is linear! Nonlinearities cause aliasing artifacts.
To wrap up: yes, you can somehow correct it if sensors aren't linear. But each such correction brings new problems with it; if everything is linear in then first place you can be most confident to actually get the signal you want.