[SOLVED] Ultrasound sensor (SRF05) max cable length ?

I can't find anything to indicate that cable length is a factor when using SRF05 ultrasound sensors, but I can't see anything else that would cause what I'm seeing.

I have five SRF05 sensors connected to an arduino (tried Uno and Mega, same results).

With 15cm leads they all work, plugged in individually or all together.
With 500cm leads none of them work - they all report "Warning: no pulse from sensor" when I run the code below on any of them.

const unsigned int TRIG_PIN=10;
const unsigned int ECHO_PIN=9;
const unsigned int BAUD_RATE=9600;

void setup() {
        pinMode(TRIG_PIN, OUTPUT);
        pinMode(ECHO_PIN, INPUT);
        Serial.begin(BAUD_RATE);
}

void loop() {
        digitalWrite(TRIG_PIN, LOW);
        delayMicroseconds(2);
        digitalWrite(TRIG_PIN, HIGH);
        delayMicroseconds(10);
        digitalWrite(TRIG_PIN, LOW);

        const unsigned long duration=pulseIn(ECHO_PIN, HIGH);

        int distance= duration/29/2;
        if (duration==0)
                Serial.println("Warning: no pulse from sensor");
        else{
                        Serial.print("distance to nearest object:");
                        Serial.print(distance);
                        Serial.println(" cm");
        }
        delay(100);
}

I've tested all the cables for connectivity, all "bleep out" OK and there are no silly "wrong pin" mistakes. Varying the delays between 5 and 15ms makes no difference.

Somewhat oddly, disconnecting the sensor gives "distance to nearest object:157cm" ... ?

Any ideas very gratefully received as I'm all out of them :slight_smile:

David

So my problem appears to be environmental/cable based.

I was using normal ribbon cable to connect these up so first I tried chopping a cable in half and then got readings, though very erratic (e.g 72-150cm for an object about a metre away).

Having replaced the ribbon cable with twisted pair ethernet cable (one pair to Vcc/Gnd, one pair to TRIG/ECHO) I now get solid distances all the time.