Detecting whether a sensor is plugged in, cable length is 5m

Hi all,

Im trying to use a TTN Uno (based on the Arduino Leonardo) in conjunction with an ultrasonic sensor (Parallax Inc 28015) to count objects going past.

Im using the internal pull up resistor (which I believe to be 20k ohms) to set the input pin to high when nothing is connected and when the sensor is connected, the pin is pulled low. This currently works with a small 3ft cable however when I use a 5m cable, the pin state doesn’t change from high to low and I’m unsure why that would be, thanks in advance

I’ve attached a diagram of my set up, apologies in advance for the lack of a proper circuit diagram, that’s as much as I’ve got so far.

Thanks in advance

const int pingPin = 7;// this constant won't change. It's the pin number of the sensor's output:

int Pin_7_State;

void setup() {

  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(7, INPUT_PULLUP);           //Sets the pin as an input

  Serial.begin(9600);
}

void loop() {

  Pin_7_State = digitalRead(7);
  
  Serial.print("Pin 7 State: ");
  Serial.println(Pin_7_State);
  Serial.println(" ");

}

Untitled Diagram (1).jpg

TTN Uno (based on the Arduino Leonardo)

Quite brain-damaged to name a board UNO while it's based on a Leonardo.

Im using the internal pull up resistor (which I believe to be 20k ohms) to set the input pin to high when nothing is connected and when the sensor is connected, the pin is pulled low.

This behavior is not guaranteed by the product. I guess that the sensor is detecting the pull-up as the trigger signal and therefor activates it's output stage to pull the line down until the reply is sent. But the datasheet doesn't say anything about the idle state of that pin by the sensor part.

This currently works with a small 3ft cable however when I use a 5m cable, the pin state doesn't change from high to low and I'm unsure why that would be, thanks in advance

As the longer cable builds a bigger capacitance the signal might not reach a trigger pulse for the sensor the it doesn't activate it's output stage.
That's just a guess as your usage is not the way the product should be used.

Built-in pullups are usually too weak for long cables, just add a 4k7 external pullup to bolster it.

The internal pullups are not strictly resistors, BTW, and the specification of 20k–50k is a coded way of
saying there’s a pullup FET (whose approximate resistance depends on the supply voltage).

In general the sort of impedance you need to avoid being affected by a long cable is in the hundreds of
ohms to several kohms range, whereas an on-board pullup of 100k is usually enough. Large boards with
lots of crosstalk, or RF transmitters, might need stronger pullups.

Firstly, thanks for your responses, in regards to adding a 4k7 ohm pull up resistor , I attempted that but the pin still didnt come low when the sensor was connected. was I supposed to wire up the 4k7 pull up as well as use the internal pull up?

I have noticed that when no pull up is used (no internal and no external) and the sensor is connected via the 5m cable, the pin is successfully pulled low but stays low which isnt ideal as I need it to go high when the sensor is unplugged again