A simple soil moisture sensor using an Arduino UNO microcontroller.
This program is written in the C++ programming language.
π View Code
Arduino Pin | Display Pin | Sensor Pin |
---|---|---|
GND | GND | GND |
A4 | SDA | β |
A5 | SCL | β |
A0 | β | AOUT |
5V | VCC | β |
3.3V | β | VCC |
The sensor data pin is connected to pin A0
.
void setup() {
Serial.begin(9600);
}
void loop() {
int value;
value = analogRead(A0);
Serial.println(value);
delay(100);
}
First, record the highest value the sensor obtains when dry. Change the value in the code (default is 603) to the measured value:
const int dryValue = 616; -> const int dryValue = YOUR_VALUE;
Next, measure the value the sensor obtains when wettest. Measure and replace the value in the code:
const int wetValue = 292; -> const int wetValue = YOUR_VALUE;
Now, upload the code to the Arduino and everything should work!