Can't get what you mean with "nothing happens" so please post here the full sketch you used to test the sensor, and if possible a picture of your hardware and wirings including how you're powering everything.
You posted in the section that was only for the Arduino Nano ESP32.
Therefore I have moved it here
All alternative versions of the ESP processor belong here.
Nobody expects the Spanish Inquisit... Uh, no, sorry, that was a Monty Python skit...
Jokes aside, I don't know that sensor, but I think you don't need to connect it to any board to test it, you just need to use a voltage source. As far as I can see, the problem is you're powering it with 3.3V coming from ESP8266 and the label I can see on your picture says 5V, and if it isn't properly powered it can't work good.
Use an external 5V power supply and see if it lights correctly.
When it's ok, you can go on connecting it to the ESP (signal cable to any GPIO, and GND in common with the sensor power supply) and run any test or example sketch available for your sensor.
(anyway, always read the datasheets of the devices you want use, if you gave us the direct link to the sensor you have -could you post it here now?- it'd be much easier for you and us...)
PS: not to mention your weird cable colors:
You here used a red on the link D6, orange to GND and brown to 3V! YIKES!
It isn't a matter of aestethics, using a good color cable coding helps avoid (often fatal for the devices) mistakes in the future.
Use red for Vcc, black for GND and any other for signals (anyway, common color for signals is yellow).
PS: to protect the ESP I'd first try adding a 470 Ohm resistor in series and a 3V Zener from the pin and GND, but google around a bit to see what others did with same or similar sensors.
There is no way you can get a current of 300mA from any arduino pin. You need a driver.
The way sensors like this normally work is that when it is supplied with the correct voltage, on detecting what the sensor is designed to sense then the current from the sensor will change.
You were asked for a schematic and code. You provided some photographs. So you are just feeding us scraps. Some would say you don't want to cooperate, but maybe your skill level needs to be greatly increased before you have the skills needed for you to cooperate.
I'm a total beginner at this so sorry if you think I don't want to cooperate, that's not the case.
Thank you for your intervention.
The goal is to automate my water consumption, I followed a project on the internet which uses exactly the same components as me. Just the way the ESP was powered changed.
So you are totally right, I have no skills in this area, sorry if it was difficult to deal with me. But the main thing is that it works: my water consumption goes back to my Home Assistant.
So you have code that you are keeping secret, and a tutorial that you are keeping secrete.
So post the links to them at least. Better still post your code and the way you have wired it up.
We can only know what you tell us, and at the moment you are telling us precious little.
Notice on the picture you posted you show you connected the sensor's power to 3V3 and ground, where as you should have used Vin and ground, with D6 being on the other side of the board. Not the same side that your photograph shows.