Using ESP-01 GPIO pins

I'm trying to build a cheap device to measure water level in a tank using HC-SR04 sensor and ESP-01 which send the data to MQTT topic. I used the same code with ESP-E12 which works just fine. As I'm trying to drive the cost down with ESP-01, I faced a problem with I/O pins. I searched the web and found some contradicting info about which pins could be used in this case. So here is the schematic of my setup:

Coming to the ESP-01, I used a USB adapter to program it and the code uploaded successfully. Here I'm just showing the Ultrasonic sensor part which I believe I have issues with.

#define echoPin 2 // Echo Pin
#define trigPin 0 // Trigger Pin
 
long duration, distance; // Duration used to calculate distance
 
void setup(){
  Serial.begin (115200);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);   
}
 
void loop(){
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration/58.2;
  Serial.println(distance);
  delay(200);
}

I read somewhere in the internet that GPIO2 can't be used and must be replaced with Rx = GPIO3. However, I tried that and it didn't work too.

So the question here, am I really using the right pins or is it really possible to do that with esp-01?

matrixall:
I read somewhere in the internet that GPIO2 can't be used and must be replaced with Rx = GPIO3. However, I tried that and it didn't work too.

Both GPIO0 and GPIO2 are required to be pulled high on boot.

Superficially, the HC-SR04 does this

But!

It is pulling these pins up to 5 V, not 3.3.

This is not appropriate. :astonished:

It is not a matter of "which" pins. You need to interface the correct logic levels - a 74HCT14 could be used - two gates in cascade - to drive the "ping" signal to the HC-SR04 and a diode in series with cathode to the HC-SR04 to convey the response to the ESP.