# MATHS PROBLEM!!!

Hi everyone, I really need your help okay, I've stumble for this code for very long and yet I can't come about a possible equation or solution with the Arduino program.
okay here's the problem in code:

``````  float NewIrms = Irms - 2.20;

Serial.print("New RMS current:'");
Serial.print(NewIrms);
Serial.print("'");
``````

So As you can see Irms is a value I read off from a device and it's supplying abnormal value so I've to calibrate and off set this value. It usually will fluctuate values example :
2.14
2.16
2.15
2.10
2.17

Thus, I wrote a line to use a larger value to minus it .However, it will provide us with a negative answer if the value of Irms is less than 2.20(the value I used) . Thus, is there a possible solution where I can implement that would give me a reference value 0?

Oh ya i left out one most important thing is that I want to keep the decimal value.
I know unsigned char or unsigned int would solve the problem. Sorry I left out this point pardon me is there a possible solution where I can implement that would give me a reference value 0?

Sorry: a solution for what?

Regards.

``````  float NewIrms = Irms - 2.20;
if (NewIrms < 0.0)
NewIrms = 0.0 ;
``````

And its a coding problem, not a maths problem, strictly.

As you can see Irms is a value I read off from a device

luckystar94:
Oh ya i left out one most important thing is that I want to keep the decimal value.

If I understand then you want to use the map() command http://arduino.cc/en/Reference/Map

I’m only guessing what you want to achieve because you haven’t explained it very clearly.

I think you want to work out the value of an incoming signal that represents zero. You can calibrate your system to estimate what value represents zero, but if the calibration is inaccurate then the result might occasionally go negative, which would not make sense for a RMS value.

One way to tackle this would be to do your calibration as currently, but recalibrate if you get a negative result. For example:

``````if(rawValue < referenceZero)
{
referenceZero = rawValue;
}
``````

Then you can go ahead and offset/scale the raw value using the referenceZero to get your corrected value.

Are you saying that
Irms is the value read from the sensor ?
You want to "zero" this sensor ?
You think this "zero" is about 2.2 ?
However at "zero" you sometimes get values close to 2.2 but not exactly 2.2 ?

How accurate is the sensor really?
A lot of people often think that because a sensor returns 6 significant digits (float) that it is accurate to 6 significant digits.

Does the "zero" value change over time? Temperature? Humidity? Barometric pressure (weather or altitude)?

How accurate do you need it to be? As accurate as the sensor? Less accurate? More accurate (how)?

I'll tell you what I did with sonar and ifr distance sensors

I know that I want to know when it's closer than about X or Y or Z distances, because I do different things at those distances
I "map" the result of the sensor erasing to a range of 0 to 15
Then if less than 4 do A, if less than 7 do B, if less than 10, do C else do D

But it all depends on how much accuracy you need and how accurate the sensor is.