Pages: [1]   Go Down
Author Topic: GP2D12 Sharp sensor on 2.56V  (Read 1026 times)
0 Members and 1 Guest are viewing this topic.
Friedberg, Germany
Offline Offline
Full Member
***
Karma: 0
Posts: 100
Arduino rocks   (it really does!)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 332
Posts: 16566
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: February 04, 2011, 07:48:35 pm by retrolefty » Logged

Friedberg, Germany
Offline Offline
Full Member
***
Karma: 0
Posts: 100
Arduino rocks   (it really does!)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
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 smiley-wink

Code:
        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 ^^
Logged

Pages: [1]   Go Up
Jump to: