Soil Moisture Sensor

This project will allow you to read the moisture of the soil using a capacitive sensor.   Component List:
  • 1 x Arduino Uno R3
  • 1 x Capacitive soil moisture sensor
  • Jumper wires (male-to-male)
  Wiring Guide:
  1. Connect Power and Ground:
    • Connect the GND (ground) pin on the Arduino Uno to the GND pin on the soil moisture sensor using a jumper wire.
    • Connect the VCC (power) pin on the Arduino Uno to the VCC pin on the soil moisture sensor using a jumper wire.
  2. Connect Analog Output:
    • Connect the AO (analog output) pin on the soil moisture sensor to the A0 (analog input) pin on the Arduino Uno using a jumper wire.
  3. Double-Check Connections:
    • Make sure all connections are secure and there are no loose wires.
  4. Power Up:
    • Connect the Arduino Uno board to your computer via USB cable to power it up.
  5. Upload Code:
    • Copy the Arduino code provided in the previous response to your Arduino IDE.
    • Upload the code to the Arduino Uno board.
  6. Open Serial Monitor:
    • Once the code is uploaded, open the Arduino IDE's Serial Monitor (Tools -> Serial Monitor) to view the output.
  CODE:
​

// Define the analog pin to which the sensor is connected
const int moistureSensorPin = A0;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);
}

void loop() {
  // Read the raw analog value from the sensor
  int moistureValue = analogRead(moistureSensorPin);
  
  // Map the raw value to a range (0-100 or any other range you prefer)
  int moisturePercentage = map(moistureValue, 600, 200, 0, 100); //you will need to tune in the numbers based on your scenario
  
  // Print the moisture percentage to the serial monitor
  Serial.print("Moisture Percentage: ");
  Serial.print(moisturePercentage);
  Serial.println("%");
  
  // Delay for a short period before reading again (adjust as needed)
  delay(1000);
}
  Looking to build this project? Check out our custom, Bahraini Assembled, starter kit here! https://www.bitware.store/product/arduino-uno-r3-compatible-with-arduino-ide/

[bitware_arabic_portfolio_content]

Project Details

Level: Beginner (1/5)
Category: Monitoring System
Platform: Arduino
Creator: BitWare Store