I am working on my 8th grade STEM fair project right now. I am trying to make an automatic plant watering system that will allow you to still have your plant be watered even when you are away from home. I have everything setup and connected right now and the code below is what I've written to test reading the capacitive moisture sensor:
int moistSensorPin = A1;
int soilMoistureValue = 0;
void setup()
{
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
pinMode(moistSensorPin, INPUT); // Pin used to read signal from moisture sensor
delay(3000);
}
void loop()
{
soilMoistureValue = analogRead(moistSensorPin); //read Sensor inserted into soil
Serial.print("Moisture sensor reading: ");
Serial.println(soilMoistureValue);
delay(1000);
}
I am having issues however because I keep getting the same numbers (soilMoistureValue ) from the Arduino no matter if the moisture sensor is in water or air or soil, and no matter what port I set to read the capacitive moisture sensor, for example A0 vs A1 vs A2. All are giving me the same readings (155-162) , even when nothing is connected to those ports. I've confirmed that the moisture sensor gives variable output voltages: 0.83v in water and 2.20v in air.
I'm using IDE 2.3.6, Arduino Nano Connect RP2040 and Windows 11 Home 24H2.
I am hoping someone could help me and see if there is something wrong with my code or what is wrong with my connections or setup.
You probably need to make some sort of adjustment to accommodate the sensor resolution to the analog pin resolution. I have a vague memory that is needed, but I don't remember how. I would check the LRM.
Sensor is at bottom of photo. Arduino Nano Connect in a Screw Terminal adapter in center. Relay and small pump to the right and USB for 5v power at top right.
I tried specifying analogReadResolution() with 10 (default) and it made no difference (still get the same stream of results around 155-162). I tried analogReadResolution() with 12 and it changed it to a stream of values around 660 (about 4 times greater) , but there is no change based on whether the sensor is in air or water. I'm not sure what analogReference() does so I'm reluctant to try it.
Wow. Thanks for the video. I am supplying 5V to the sensor board (from a USB brick), confirmed by measuring across the pins. What differences are you seeing between my photo and Amazon?
the 662k is a 3.3 voltage regulator and a NE555 needs minimum 4.5 Vcc. Something's fishy. Did you have a multimeter? Measure voltage between GND (left bottom) and Vout (right bottom)
I just rewatched the video you submitted. I have the right voltage regulator U1, 662K. I have the older timing chip U2, NE555, but I'm supplying 5.0V so it should be good.
If you get the same values with the Aout connected / not connected, it means A1 is floating, ie no connection between sensor and A1. That's what you have to troubleshoot. Time to set your multimeter to continuity mode and get to work.