A ESP32/ESP8266 is not 5V tolerant. A ESP GPIO pins are 3.3V. Putting 5V onto the ESP's pins can destroy the pins or the ESP.
In the upper right hand corner is a input text box labeled "Search Forums". Do a search on the words "level shifter". Much has been written on the subject.