connect arduino uno to esp8266-01 and ultrasonic sensor

i want to connect arduino uno to esp-01 and multiple ultrasonic sensor
my Connections


this connection not work for me but when i directly connect TX to TX and RX to RX and GPIO0(when upload code) it’s work but when connect ultrasonic sensor i doesn’t work

My Code

#include <ESP8266WiFi.h> 

const char* ssid     = "AYMAN";
const char* password = "01111000";
int Distance;
const int trig=2;
const int echo=3;

void setup() {
  Serial.begin(115200);
  Serial.print("Connecting to ");
  Serial.print(ssid);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  pinMode(echo, INPUT); 
  pinMode(trig, OUTPUT);
}

void loop() {
   digitalWrite(trig, LOW);
   delayMicroseconds(3);
   digitalWrite(trig, HIGH);
   delayMicroseconds(10);
   digitalWrite(trig, LOW);
   
   Distance = pulseIn(echo, HIGH) / 29 / 2;
    Serial.print("Distance : ");
    Serial.print(Distance);
    Serial.print(" CM");
    Serial.println("");  
   delay(1000);
}

You need to understand what you’re doing here. You are using the Uno only as a USB to TTL serial adapter to upload sketches to the ESP8266. In that usage, you can’t connect sensors to the Uno and expect the code you are running on the ESP8266 to magically control a sensor connected to the Uno. If you want to use your current configuration, then you need to attach the ultrasonic sensor to the ESP8266 and modify the code for the sensor accordingly.

You also have the option of uploading one sketch to the ESP8266 that handles the WiFi communication stuff and another sketch to the Uno that handles the sensor stuff and also have some code that allows the Uno and the ESP8266 to communicate. However, you will need to change the wiring between the Uno and the ESP8266 because your current system only allows communication directly between your computer and the ESP8266. It doesn’t allow any communication between the Uno’s microcontroller and the ESP8266. For that, you need to make your connections RX-TX, TX-RX. You might prefer to use the SoftwareSerial library to create a serial port on some pins of the Uno other than 0 and 1 and connect the ESP8266 to those pins. If you leave the ESP8266 connected to pins 0 and 1, it will interfere with communication between the Uno and your computer (uploading sketches to the Uno and printing things to Serial Monitor):
https://www.arduino.cc/en/Reference/SoftwareSerial

hunterx01: i want to connect arduino uno to esp-01 and multiple ultrasonic sensor

That wire mess shows just one ultrasonic sensor.

My Code

That's ESP8266 code. The ultrasound sensor is connected to the Arduino, not the ESP-01.

Understand how you're working with two rather different microcontrollers at the same time! The easy way out of this is to simply ditch the Arduino and get an ESP8266 based WeMOS or NodeMCU board instead.

wvmarle: The easy way out of this is to simply ditch the Arduino and get an ESP8266 based WeMOS or NodeMCU board instead.

Or use the ESP-01 with a programming adapter. |500x500 These adapters are useful to make simple and inexpensive but fully-functional devices with the ESP-01.

The two easily accessible I/O pins would be sufficient for one ultrasonic unit.