Yl105 Datasheet Better
Most users assume they can source current from an Arduino pin to drive the IN pin high. While true, the improved datasheet would clarify that the YL-105 is more robust when used as a . Why? Because the onboard LED and base resistor are referenced to VCC. When you pull the IN pin low (sinking current), the path is direct to ground, avoiding voltage drop issues from the MCU's output driver. A superior datasheet would include a driver recommendation: "For best noise immunity, drive the IN pin with an open-drain or open-collector configuration, or use an active-low signal."
void loop() int moisture = analogRead(analogPin); // 0 (dry) – 1023 (very wet) int wetDetected = digitalRead(digitalPin); // LOW = wet yl105 datasheet better