ESP32 + PC817 count 5v pump powered on
Don't use 5 V on the ESP32 GPIO pins. The way you have drawn your schematic, you are actually putting &gt; 6 V on the GPIO when the opto fires. You may want to use the opto as an active low device instead of active high.