Hi all,
I'm having some trouble with the calibration of my sharp sensors (GP2D120, http://www.sharpsma.com/webfm_send/1205). My code for testing the sensors is as follows:
#define ds_pin 0 // Pin to which the distance sensor is connected
int ds_value; // Integer to hold the sensor’s reading
float ds_scaledValue; // Distance sensor’s scaled value
void setup ()
{
Serial.begin (9600); // Initiates serial communication at 9600 baud
}
void loop ()
{
ds_value = analogRead (ds_pin); // Reads the distance sensor
ds_scaledValue = ((float)ds_value / 615) * 1024;
// Calculates the scaled value
//dist_value = (1 / ( m * ds_scaledValue +
Serial.println ((int)ds_scaledValue); // Screams out the scaled value as integer
delay (200); // Delay of 200ms
}
I have soldered a 100nF and 10uF capacitor onto the sensor following http://letsmakerobots.com/node/22781. When I plug the sensor into the usb port of my computer and test it gives me an extremely inconsistent, jumpy result (1st image below). I then tried to power it using 6xAA batteries through the board while keeping the usb plugged in and this gave me a graph that initially dropped but then flattened out nicely, however the value was almost identical for all distances I tried so I'm assuming there is an error there. Just wondering if the issue is purely powering through the computer and if it is how can I record the sensor values to work out my calibration without plugging it into the usb port?
Thanks in advance for any help!