This sensor has 4 legs, which mean:
So, we connect VCC to the DC3.3v or 5V output of the Raspberry Pi, I use PIN 01, GND is connected to any grounded GND port, I use PIN 09, DO output is connected to any free GPIO port, I use 12. If you are not clear about the layout of the Raspberry Pi port, you can refer to this figure (the code I wrote uses the physical interface, that is, the board code):
The soil moisture is different from the real thing for reference only, and only the corresponding pin position is explained. My aim is to implement the soil moisture detection function, where the LED gives an alarm when the soil moisture is low. So add a small LED light as an alarm unit. The LED long pin is connected to an indirect resistor in GPIO11. Short feet connected to GND.
Save the code as turang.py run the program sudo python turang.py
When there is no moisture in the soil, the LED light glows. This prompts me to water the soil.
When the water has been watered, the sensor detects that the humidity is sufficient and the LED light is off.
Save the code as turang.py run the program sudo python turang.py
When there is no moisture in the soil, the LED light glows. This prompts me to water the soil.