Detect circuit interruption on ESP32

Hello, I have an ESP32 HUZZAH feather from Adafruit and I want to use it to hook up a very simple circuit.

Basically I have an input reading and the circuit passes on a fabric with conductive wire that then goes back, through a 1k resistance, to the microcontroller's GND. The purpose of the piece of wire is to detect when a collision breaks the circuit, so what I really want to check if the circuit is open or closed.

This doesn't work though. The ESP only reads 0 all the time. I've also tried simply connecting on the breadboard a wire from the A2 input to the GND with either a 220 ohm and 1k ohm reistor but pulling the wire away doesn't make any change in what the serial reads. Hooking up a potmeter works fine though, it reads the values correctly.

I'm wondering if this thing I'm doing is actually possible to do or if I should look for another approach.
Thanks in advance!

I would suggest an approach that includes showing us a schematic and your code. Please consult the forum guide to find out how to do those things.

This is the schematic, I want to detect when the conductive yarn (or the whole fabric piece) is ripped or cut, and therefore to detect when the circuit is closed and when it's open.

As of now I'm testing directly without the patch in the middle (since it's only wire basically, I can also omit it), so I have a wire going from A2 (tried A0,A1,A3 as well) to a resistor (tried 1k and 220) and to the GND.

The way I am testing it is (of course) not by cutting it but by simply pulling out one of the wires ends from the breadboard. Whether it is connected or not, the serial constantly returns 0 from the analogRead.

code:

void setup() 
{
  pinMode(led, INPUT);
  Serial.begin(115200);
}

void loop() 
{
  
  Serial.println(analogRead(led));
  delay(200);
}

shier:

This is the schematic, I want to detect when the conductive yarn (or the whole fabric piece) is ripped or cut, and therefore to detect when the circuit is closed and when it’s open.

You didn’t post it…?

But general idea is simple… I’d connect one side to ground, other side to pin set INPUT_PULLUP (make sure it’s not a pin used as a strapping pin), and when the pin goes high, that means it’s not connected.

Fixed the image problem!

Thanks for your reply, so you're saying that if I use the integrated pull-up instead of a pull-down it works? Why doesn't it work with a pull-down? And does A2 have a pull-up? (Or any of the ADC#1 pins), the documentation on the Adafruit website doesn't clarify.

Ok I have an update,

Apparently the reading doesn’t work only for the ADC1 sensors Pinouts | Adafruit HUZZAH32 - ESP32 Feather | Adafruit Learning System, but I need to use those because I need to send the data via wi-fi, which is only possible with ADC1 sensors.

Does anyone have suggestions?

shier:
so you're saying that if I use the integrated pull-up instead of a pull-down it works?

You said in the OP that the pin only ever reads zero. That's because it is only ever connected to 0V. It is never connected to 3.3V, and so it never reads 1. With INPUT_PULLUP, if the connection to 0V is broken and the pin is no longer connected to ground, it is pulled up to 3.3V and so will read 1. The external resistor is not needed.

shier:
Apparently the reading doesn't work only for the ADC1 sensors

A red herring.

EDIT: apparently certain pins on ESP32 have limited features, they can be used as analog or digital inputs, but cannot be used as outputs, and more importantly they do not have internal pull-ups. So check you are not using one of those, or use an external pull-up resistor.

Idahowalker:
Also, you would want to learn the difference between GPIO 0-31 and GPIO 32->. The ESP32 has 2 32 bit GPIO ports, A and B. Port B's GPIO matrix is different then Port A's. One thing is that Port B is input only. All this and more is explained in the documentation of the ESP32, https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/index.html.