About a week ago I decided to try and grow some flowers in my room and I figured this would be the perfect excuse to make a cool thing. More specifically, I made a moisture sensor to let me know if I've forgotten to water them
I used an Arduino nano and one of these moisture sensors from Amazon. The Arduino needs to supply power and ground to the sensor, as well as read the data from the sensor. So I hooked the positive up to 5V on the nano, ground to ground, and the data line to A4. Choosing an analog pin is important because the moisture sensor gives a DC signal proportional to the moisture detected, and converting that to a digital value requires an ADC pin. I've included the code below.
The code works as follows: Every so often the Arduino will power the sensor, sample the signal magnitude, and if it's below a certain value it will enter a while loop until that value is increased enough through watering the plant. Until such time as the moisture level is restored, the while loop uses a boolean variable, delays, and some if statements to flash the nano's built in LED. I also 3d printed a case for it, I uploaded the .stl's available for download here