problem with analog distancesensor and long cable

Hope someone can help me with my dilemma. Im pretty green in the art of electronics so I need very detailed help..

Im trying to build a little controlingdevice for a small waterpowerplant and one of the critical parts is an optical sensor which will tell arduio how open the powerplant is.
Everything is programmed and works... under the condition that I have connected the sensor with a very short cable. When I try to connect it with the planned one - a 15 meter CAT6 cable I get problems directly. Seems that it is the 5v from the arduino which isn´t able to coupe with this cable/lenght. Have tried with various sizes of capacitors at the sensor end from 1uf and up - which helps but causes the signal to become a bit dodgy.
How can I work around this problem? Is there a cable that would work? Could I build something small and smart which overcomes the issue? I have concidered hitting my head with a sledgehammer, but have determined that this will cause alot of pain and not help one bit, so I havn´t resolved to that yet...
The sensor Im using is a SHARP GP2D120X100F

Hope someone can help.. frustration is growing..

You're likely going to need some extra circuitry on each end; 15 meters is quite a distance for a low voltage, low current analog signal to travel. Probably the easiest (and maybe cheapest - in relative terms) would be to hook an audio VCO (voltage controlled oscillator) circuit to the output of the sensor, amplify the frequency produced by the oscillator, send that down the line, and at the other end use a demodulator to recover the voltage, then level match it to 0-5 VDC. Essentially you would be constructing a simplified one-way modem. You could do this using discrete components, or using a couple of microcontrollers (ATTiny84 might be a good choice) and other parts.

What's your budget? It might be simplest to add another Arduino at the sensor end and then communicate via RS485 or similar.

Well, budget is quite low - preferably not much more than $ 30 or so, but regardless, it shall be done one way or the other. Adding another arduino at the place of the sensor sounds like a simple and fairly affordable idea. Wish there was an even simpler solution tho..
Building a VCO seems a bit advanced for me at the moment.. unless someone happen to have a suitable scematic in their pocket ofcourse :wink:

some google-fu brought up this

Ill try to specify the problem;
To make sure that capacitor is correct, I made sure that a 10uf is in place. Signal still dodgy.. By dodgy, I mean that I have a smoothing filter on the sensorvalue, and the sensorvalue flickers up and down by a reading equal to about +/- 4 cm (sensor measures 4 - 30 cm). About once every 10 to 15 seconds, smoothed sensorvalue drops from 30 cm to about 10 cm - to then climb again up to the 30 which the sensor should give.
If I shorten the 5v and GND to the sensor - making them about 5cm, the problem seems to be gone, so I would say that the analogue signal itself actually manages the 15 m cable, but when power and ground cables aswell are 15m long, I get this problem..
I can also mention that both power and ground have a pair of wires each from the cat6 cable. Power is taken directy from 5v on the Duemilanove and the Arduino unit is powered by a 9v 500mA powersupply.
The current over the power in on the sensor measures 4,97v with "long cables".
Does this provide any clues?

I can also mention that I am measuring the distance between sensor and a white painted wood board - sized to there is no way the IR will miss it. Environmnent is quite dark, indoor (basement to be exact) with no sunlight comming in. At a distance of 10 cm, there are some 220v, 50hz cables but the big "drops" in sensorvalue seems so random so I doubt they are the cause.

Just to make sure, I have removed power from all other cables in the vicinity to make sure I don´t have any inteference. The problem remains. I get random drops in voltage on the sensor out causing my output measurment to be drastically reduced for a moment. Problem comes and goes.. sometimes frequent (more often than once every 5 sec) ans sometime more rarely.. (up to 20 sec. between dips). A small variation is always there causing the measurment - which should be stable - to vary up and down by +/- 5%

The filter is this one from the arduino page:
const int numReadings = 10;

int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average

int inputPin = 0;

void setup()
{
// initialize serial communication with computer:
Serial.begin(9600);
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;
}

void loop() {
// subtract the last reading:
total= total - readings[index];
// read from the sensor:
readings[index] = analogRead(inputPin);
// add the reading to the total:
total= total + readings[index];
// advance to the next position in the array:
index = index + 1;

// if we're at the end of the array...
if (index >= numReadings)
// ...wrap around to the beginning:
index = 0;

// calculate the average:
average = total / numReadings;
// send it to the computer (as ASCII digits)
Serial.println(average, DEC);
}
I will get to testing without tomorrow and document the readings. Still tho.. it does seem to work with shorter cables.. can cable lenght affect in this way?

Ok.. I have taken everything back to the lab environment. Have written a code to just take readings from the analogue sensor and write to serial every 50 ms.
I have tested measuring 2 distances with long cables and then repeated the procedure with the same distances and ground/power cables being short (app 20 cm in total)
The results are the following:
LONG CABLES:
measuring distance, app. 7 cm... readings showing 440 +/- 1 with occational jumps to 480 - 490 every 3 - 4 sec.
measuring distance, app 29 cm... readings showing between 95 and 97 with jumps to between 100 and 150 app once per second
SHORT CABLES:
measuring distance app. 7 cm.. readings showing 483 +/-1 stable
measuring distance app. 28 cm.. readings showing 93 - 97 - occational and drandom jumps to 100 - 110
SHORT CABLES - ALSO SIGNAL CABLE
mesruring distance app 7 cm.. readings show 483 - 487 - 1 jump to 495 registered in 1 minute - otherwise within range
measuring distance app 29 cm readings show 94 - 96 with occational jumps to 105
LAST TEST - SHORT CABLES, NO CONDENSATOR
same result as just short cables

Seems like 15m 5v & gnd are the largest problem but signal cable also affects reading though somewhat less...

I should probably also mention that with the long cables, the "dips" in sensor-readings come with a series of high readings.. often between 5 and 10 high readings in a row of variable values in high range while with short cables, the few readings which are way out of range seem to be solo... one high reading followed by atleast 10 normal.

Unfortinatly, I don´t have access to a oscilloscope so that type of precise measuring is not an option. I think I will start by trying to get a hold of another sensor. These jumps in readings are present even on short distance readings with short cables (tho less nioticable) - and after thinking about it a bit - I doubt that this would be a "normal state" for this type of sensor. So I will start with getting a new sensor and check the results. External environment should be well within limits so I do not believe the problem stands to be found there.
After testing I will report a conclution back, but this will take some time since there is a few weeks deliverytime on it. Meanwhile, tho, I thank you very much for your pedagogial approach, patience and excellent advice!

Other sensors... yes, I have been concidering ultrasound, but for measuring up to the 30 cm needed in this case, I need a very narrow beam and I havn´t been able to find an ultrasound with this property which is affordable and relyable. I have one which I have tested and it will be perfect to measure waterlevel in powerplant dam when I get that far in the project but first of all it is dealiing with manually being able to control the opening level from the main floor of the house... powerplant(s) are under the basement.. sounds funny, but that´s the case. I guess there is also the possibility of some sort of optical wheel solution like on a computermouse or similar but it seems to me that that type would require calibrations every so often - of a very sofisticated programming concidering that power to the system will be cut off quite often.