Go Down

Topic: GP2D12 Sharp sensor on 2.56V (Read 1 time) previous topic - next topic

Gonras

Hey,
I am working on a robot and I got the Sharp GP2D12 range sensor and some other sensors. For unity and more presize reading I need to put the analogReference to "INTERNAL2V56"
That works perfect for the other sensors because the calculation was linear.
I got the range calculation for the GP2D12 from the Playground: http://arduino.cc/playground/Main/ReadGp2d12Range
The problem there is I have totally no clue how to change that for 2.56Volts.
Could someone help me there please.

This is the calculation but I don't understand what she/he did there.

(6787.0 /((float)tmp - 3.0)) - 4.0;

Would somebody be so kind and explain it to me or even show me how to change it for 2.56V?

Thank you very much,
Florian

retrolefty

#1
Feb 05, 2011, 01:39 am Last Edit: Feb 05, 2011, 01:48 am by retrolefty Reason: 1
Quote
The problem there is I have totally no clue how to change that for 2.56Volts.
Could someone help me there please.

This is the calculation but I don't understand what she/he did there.

(6787.0 /((float)tmp - 3.0)) - 4.0;


That is a calculation to correct for the non-linear relationship of distance Vs output voltage of that sensor.

A simple way to cheat is to just divide the analog counts read into raw by 2, then just use the same formula. Otherwise some math wizard around here will have to show you how to change the formula to reflect your change of reference from 5.0 volts (Avcc voltage ref) to your internal 2.56 volt reference.

So:

temp = temp/2;
(6787.0 /((float)tmp - 3.0)) - 4.0;[/quote]

Finally you can also just change the arduino A/D reference back to DEFAULT, read the IR signal and then change it back to INTERNAL2V56. However after changing reference one needs to make a dummy read before you get a good conversion value.

Lefty

Gonras

Hey thank you Lefty!
I tried the simple way allready by dividing the solution of the calculation by 5 and multiplied it by 2.56 and it didn't work at all...
Now It works fine :)
It seems that the default reference is not 5 volts I measured to voltage and it is 4.9 volts that makes quite a big difference.
here is the converted part for people who wanna know how it looks ;)

Code: [Select]
        float tmp;

tmp = analogRead(pin)/4.9*2.56;
// Serial.println(tmp);
        if (tmp < 3) { tmp = 0; }

        GP2D12 = int(6787 /((int)tmp - 3)) - 4;


Thanks again ^^

Go Up