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
David