Hello guys,
I have used the map function in the arduino code. ``` float val = (float)(map(samplse,0,1023,-3500,3500)/100.0);
`0 -35
2.61 0
5 35
`
Here I have taken calibration values from the sensor and plotted a graph. First when I use the power graph, I got **NAN x^NAN**. But when I use the calibration values with linear graph, I got **13.9909711599448x - 35.4904301757266**.
My question is why in power graph, I am getting NAN. Then If I want to add the calibration values of linear graph in the arduino, how will I implement?
Here I have taken calibration values from the sensor and plotted a graph. First when I use the power graph, I got NAN x^NAN. But when I use the calibration values with linear graph, I got 13.9909711599448x - 35.4904301757266.
My question is why in power graph, I am getting NAN. Then If I want to add the calibration values of linear graph in the arduino, how will I implement?
not clear what you mean by power vs linear graph?
is the issue with your graphing tool or the arduino code?
when i do your mapping , i get the following values which look correct
Hi friends, I am using HG-C 1100 sensor and this sensor measures the range from -35mm to 35mm. I have doubt in using the formula float val = (float)(map(samplse,0,1023,-3500,3500)/100.0);. I have to take the readings from the sensor and should display it in the serial monitor. The values also should be accurate as in the sensor. Can anyone explain me how to take the formula and calibrate the same?
Thanks in advance.HG-C_Series.pdf (3.0 MB)
How are you reading the value from the HG-C device?
Can you post a circuit of your project?
Can you post the code you are using?
What model Arduino are you using?
both Tom and I have shown that the map equation works. it translates values in the range from 0-1023 to proportional values in the range from -35 to 35 (yes I scaled by 10 instead of 100)
int samplse=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // initialize serial communication at 9600 bits per second
}
void loop() {
// put your main code here, to run repeatedly:
int samplse = analogRead(0); // read the input on analog pin 0
float val = (float)(map(samplse,0,1023,-35000,35000)/1000.0); // Map an analog value to 10 bits(0 to 1023) and the target range
//val = constrain(val, 0, 1023);
Serial.print("digital value = ");
Serial.println(val); // print digital value on serial monitor
float voltage = (float)((samplse*5.0)/1023);
Serial.print("Voltage:");
Serial.println(voltage);
delay(3000); // delay in between reads for stability
}```
The values I am getting from the sensor should reflect in the code with more accuracy.
Accuracy in sensor when I use this map function float val = (float)(map(samplse,0,1023,-35000,35000)/1000.0); Serial.println(val); , I am getting the the value for example 31.56 in the sensor but in the serial monitor I am getting as 33.90. There is a lot more difference in the values. What can I do to get the accurate sensor values in the serial monitor?
How will I calibrate?