First of all I have to say I don't know much about electronics and arduino boards so this forum seemed to me a good way to post my questions.I'm trying to build a measuring device to measure a distance. The sensor I'm using is a inductive sensor with a linear range (see image) between voltage and distance. I would like the arduino to "translate" the voltage into distance and sent this data to my computer. The first problem I had is that the sensor has a maximum voltage of 10V and arduino can only take 5V. So I placed a voltage divider between the arduino and the sensor but I think I'm loosing some accuracy with this setup. How can I know how much I am loosing? I never learned this in school so I don't know what the right solution is for this problem.
gif image hosting
The non linearity of the sensor is 45µm max.
The repeat accuracy of the sensor is 10µm.
My measuring device should have an accuracy of 0,05mm.
I also read that the arduino can take 100.000 samples per second but is this also true for my device?
The second question I had is whether my accuracy depends on the program I wrote. I wrote this program but I can imagine that this program can be improved. Is there any way to improve accuracy by programming?
int sensePin =0;
void setup() {
analogReference(DEFAULT);
Serial.begin(9600);
}
void loop(){
int val = analogRead(sensePin);
int mmWaarde = map (val, 0, 1024, 0, 2000);
Serial.println(mmWaarde);
delay(500);
}
Well the first thing I would try and determine is if your sensor unit's 10vdc max measurement voltage is designed to be able to drive a 2k ohm load that your voltage divider presents to it. I would take a multimeter (you need to own one if you don't already, that's not optional) and take a voltage reading at the sensor output both before and after you attach it to the voltage divider. If it drops with the load of the divider you need to change something, either using a op-amp type buffer or going with larger ohm size resistors, etc.
As far as your code goes, looks ok at first glance, but many/most users on analog measurements using arduinos take multiple readings add them and then divide by the number of reads. While this slows the program down a little it acts like a low pass filter helping with noise and spikes that might come out of the sensor or sensor wiring.
higher baudrate gives more time to sample / process data (not needed now but maybe in the future)
the map formula does not work so nice for increasing ranges. Replaced it with a floating point variant which is printed with one decimal.
Give it a try.
void setup()
{
analogReference(DEFAULT);
Serial.begin(115200); // why not fast IO gives more time to sample !!
}
void loop()
{
int val = analogRead(sensePin);
float mmWaarde = 2000.0 * val / 1023;
Serial.println(mmWaarde, 1);
delay(500);
}
wrt the voltage divider, measure the max voltage accurately (or measure the resistors and do the math) and use it to calibrate the value 2000 in your sketch.
Succes!
Adding the low-pass filter as retrolefty suggested is left as an exercise
Hint: If you do multiple readings you can use the sum in the final formula. Keeping the number of operators minimal prevents loosing precision.
What is the range of the sensor, in other words, at what distance does it output 10v? Assuming that it outputs a voltage proportional to distance, your resolution (and hence an upper limit on your accuracy) is 1/1024 of that range, because the Arduino has only a 10-bit ADC. If you need a greater resolution than that, you will have to use an external ADC.
If the sensor isn't designed to drive a 2K load, you can increase the two resistors to 22K each without a significant effect on the eading.
@lefty:
I don't understand why the sensor wouldn't be designed for a 2K load. Is this because the sensor can lose accuracy(or brake down) if it has a current which is too high or why is it?
The datasheet tells me that the sensor has a "no-load supply current Io at Ie" of 15mA. So 10V and 2k equals a current of 5mA. Does this mean that I am allowed to use (2k/3=666ohm)?
I will check the votages like you told me but I also want to understand what I'm doing
@dc42:
The datasheet of my sensors also tells me that it has a lineair range between 0,5mm and 2mm. The 2mm would give exactly 10V but I will check if this is really true. The total lineair range would be 2-0,5=1,5mm and this would mean a resolution of 1,46µm with a 10bit adc (I think). This is enough for me because the sensor isn't this accurate. My total accuracy would have to be about 50µm.
I also read somewhere you can't take the resistors of the divider too high because if the sensorvoltage would variate at a certain speed, the speed of variation after the divider wouldn't be the same. If I add an opamp to the divider, would this slow down the varition-speed?
JohnTampon: @lefty:
I don't understand why the sensor wouldn't be designed for a 2K load. Is this because the sensor can lose accuracy(or brake down) if it has a current which is too high or why is it?
The datasheet tells me that the sensor has a "no-load supply current Io at Ie" of 15mA. So 10V and 2k equals a current of 5mA. Does this mean that I am allowed to use (2k/3=666ohm)?
I will check the votages like you told me but I also want to understand what I'm doing
The sensor has an output device that is driving (supplying) that 0-10vdc measurement voltage. That device may be a transistor or an op-amp, but whatever it is using it has a built in output impedance limit of some value, it's just physics. You wouldn't expect that signal to be able to supply 100 amps of current output, of course not. This has little or nothing to do with how much DC supply current the sensor requires to operate. Testing if the output can properly drive a 2k ohm voltage divider load is not difficult as I already stated. Just remove the wire from the sensor output terminal going to the voltage divider and measure whatever measurement value it is outputting, it would be better if you could 'force it' to have a full 10vdc output, then replace the wire going to the divider and measure the same point again. If the measurement went down then you have an output impedance problem to deal with, if not then you don't have to change a thing.
You're not going to lose any speed by increasing the resistors to around 22K each. The Arduino ADC has a maximum sampling rate of 9kHz anyway @ 16MHz clock if you want the full 10-bit resolution. I will be surprised if the sensor can't drive a load of 44k, but check the datasheet for the recommended minimum load resistance.
Unfortunately, the datasheet doesn't give the output resistance of the sensor, nor does it specify the accuracy (it specifies repeat accuracy but not absolute accuracy). So IMO the datasheet is inadequate but not actually incorrect.