1

I am using two HG-C 1100 measurement sensor for measuring the width of the metal. In the top of the sensor I will be having the measurement value. The sensor is capable of measuring the dimensions from -35mm to 35mm. So I am using the formula:

int First_sample = analogRead(6);  
int Second_sample = analogRead(7);
float First_sensor = (map(First_sample, 1023, 0, -3500, 3500) / 100.0);     
float Second_sensor = (map(Second_sample, 0, 1023, -3500, 3500) / 100.0); 
Serial.print("First_sensor:");
Serial.println(First_sensor, 3);
Serial.print("Second_sensor:");
Serial.println(Second_sensor, 3);
Final_sensor = (First_sensor - Second_sensor);
Serial.println(Final_sensor, 4);

If I use this code, I will get the proper width of the metal. But when I place the metal in between the sensor, I am getting the exact width in the serial monitor. But at the top of the sensors the values are different. I don't why the analog values are different on the serial monitor and the top of the sensors. But the output of the sensor is perfect in the serial monitor. Can anyone help me with this?

3
  • I can't make much sense out the question as written except that the display doesn't show what you expected. The the sensor display seems to have modes for Standard, Inverted, and Offset. If it doesn't have anything to do with that, and actually has something to do with the Arduino, maybe clarify the question somewhat. – timemage May 21 at 10:12
  • 1
    But when I add the arduino code and see in the serial monitor, the values aren't as like the top of the sensor. if the first sensor is -17.5, it is taking as -17.78. if the second sensor is -21.5, it is taking as -21.12. I have to know why there is a difference. But the metal I place between the sensor gives me the proper output. Have you got my point? The serial monitor and the top of the sensor value is different. – user76575 May 22 at 9:19
  • "Have you got my point?" No, I haven't. Nor do I know what to ask you. Maybe someone else will. Failing that, you'll have to figure out how to clarify the question until someone understands it well enough. – timemage May 22 at 12:52
0

The HG-C1100 has a resolution of 70 μm (= 0.07 mm) over a measuring range of 70 mm. You quote errors of 0.28 and 0.38 mm, which is worse than can be expected (±0,07 mm). The resolution is 1‰ of the measuring range. Therefore the 10 bits range (1024) of the Arduino's Analog-Digital Converter (ADC) is sufficient.

You map the ADC output of 0-1023 to a range of -3500 to +3500 which results in a value in 0,01 mm. Then you divide by 100.0 resulting in a value in mm.

According to Arduino's Reference the function map() uses integer arithmetic, but the arguments are longs and the calculation order is such that maximal accuracy is maintained. This provides sufficient accuracy for this purpose. I am only not sure if you constants should be post fixed wit an "L".

So far everything looks all right.

The errors you mention correspond to about 5 counts of the ADC. I assume the solution lies in taking measures to prevent noise entering your signals (signal conditioning).

Addition:
When you read the same sensor repeatedly do you get stable readings? You could try to use an average over multiple readings. Did you look at the signal(s) with an oscilloscope?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.