I'm doing the classic water moisture sensor project with my ESP32, but I want to be able to switch the sensor on and off since that will reduce the amount of corrosion that occurs. Can I use a BC547 transistor as suggested below to achieve turning using GPIO18?
I've also wired an LED in series to show when it's reading/not reading. Would I need the resistor if I didn't have this LED?
Please be easy on me – I'm a beginner to all of this.
CORRECTIONS (and removed the led):
Best Answer
Your proposed setup will not work, but the second (corrected) one will. Here are some issues in the first setup:
The solution would be to put the BC547 in the right way, remove the LED and 220 Ohm resistor in the GND path and put a resistor of around 2.2K between D18 and the base of the transistor. The 2.2K resistor is for limiting the base current from the GPIO pin while assuring enough current can flow through the transistor.
This way, your transistor can switch the GND current to the sensor on and off freely. If you need an indicator, you can use a different GPIO pin, and LED and a resistor to provide it.
simulate this circuit – Schematic created using CircuitLab