 # Display reading with fixed resolution like 2, 5 or 10

Hi there.
I'm not expert in Arduino programming.
I'm making a weighing scale by reading the digital value from the ADC.
All is working fine but I'm stuck at one thing. There is display resolution in weighing scales. For example, if the resolution is set to 5, then the weight on the display should be incremented in multiples of 5 only. like 0.005, 0.010, 0.015, 1.000, 1.005 etc.

Now what I'm getting is a float weight incrementing by multiples on 1 only. I'm clueless how to implement the resolution here.
Kindly guide me...

Start by posting your current code

It sounds like you need to detect when the weight changes from one weight band to another and only then display the new weight

are you saying you want to round the number to the closest multiple of the resolution?

I have no code to post as I'm clueless about how to go about it.
Sorry, it is not like weight band from one to another. See, weighing scale have display resolution. It is all about the display resolution. When the resolution is set to 5, then the display should show the weight in multiples of 5 only.
The way I'm calculating the weight is, Zerocounts - Loadcounts = Net_counts. Net_counts / Weight_on_scale= Factor. Weight = net_counts / factor. printing the weight with 3 decimal values. Now this is always in multiples of 1 only.

Yes. Exactly.

Post your code attempt - whatever it is

I have not attempted as I'm clueless to go about it.

I cannot reconcile those 2 statements. You obviously have code

Weighing_with_callibratinn_from_counts.ino (11.2 KB)
The code is attached here.
But there is no code about the problem I'm discussing here.

The code is given below...

give that a try with the serial monitor set at 115200 bauds

``````double rounding(double x, double resolution) {
Serial.print("Rounding: "); Serial.print(x, 3);
Serial.print(" with resolution: "); Serial.print(resolution, 3);
double result = round(x / resolution) * resolution;
Serial.print(" = "); Serial.println(result, 3);
return result;
}

void setup() {
Serial.begin(115200);
Serial.println();
rounding(42.49, 1);
rounding(42.50, 1);
rounding(42.51, 1);
rounding(42.35, 0.5);
rounding(42.35, 0.25);
rounding(42.35, 0.2);
rounding(42.35, 0.1);

}

void loop() {}
``````
1 Like

I changed the code for testing and I got result as I wanted.
Thanks a lot for your help.

``````double rounding(double x, double resolution) {
Serial.print("Rounding: "); Serial.print(x, 4);
Serial.print(" with resolution: "); Serial.print(resolution, 3);
double result = round(x / resolution) * resolution;
Serial.print(" = "); Serial.println(result, 3);
return result;
}

void setup() {
Serial.begin(115200);
Serial.println();
rounding(42.49, 1);
rounding(42.50, 1);
rounding(42.51, 1);
rounding(42.35, 0.5);
rounding(42.35, 0.25);
rounding(42.35, 0.2);
rounding(42.3552, 0.002);
rounding(42.3532, 0.002);
rounding(42.3519, 0.002);

}

void loop() {}
``````

good - have fun!

1 Like