Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Pro Mini Based Soil Moisture Monitoring System with Sleep Mode

View and Edit Project In Cirkit DesignerImage of Arduino Pro Mini Based Soil Moisture Monitoring System with Sleep Mode

Soil Moisture Indicator Circuit Documentation

Summary

This circuit is designed to measure soil moisture levels using a capacitive soil moisture sensor and visually indicate the moisture level through a set of three LEDs (red, yellow, and green). The Arduino Pro Mini serves as the central processing unit, reading sensor data and controlling the LEDs based on the moisture level. The circuit also features a pushbutton to activate the system and initiate a reading. After 30 seconds of inactivity, the system enters sleep mode to conserve power, which can be exited by pressing the button again.

Component List

Arduino Pro Mini

Capacitive Soil Moisture Sensor V1.2

LED: Two Pin (red)

LED: Two Pin (yellow)

LED: Two Pin (green)

Resistor (330 Ohms)

Pushbutton

Wiring Details

Arduino Pro Mini

Capacitive Soil Moisture Sensor V1.2

LEDs (red, yellow, green)

Resistor (330 Ohms)

Pushbutton

Documented Code

/*
 * This Arduino Sketch reads soil moisture levels using a capacitive sensor and
 * indicates the moisture level via three LEDs (red, yellow, green). The device
 * also outputs the reading to the serial monitor. The device enters sleep mode
 * after 30 seconds of inactivity to conserve battery power.
 */

#include <EEPROM.h>
#include <avr/sleep.h>

const int redLED = 2;
const int yellowLED = 3;
const int greenLED = 4;
const int buttonPin = 5;
const int sensorPin = A0;

const int MaxDry = 607;
const int MaxWet = 221;

void setup() {
  pinMode(redLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
  Serial.begin(9600);
  EEPROM.write(0, MaxDry);
  EEPROM.write(1, MaxWet);
}

void loop() {
  if (digitalRead(buttonPin) == LOW) {
    int sensorValue = analogRead(sensorPin);
    if (sensorValue >= 478.34 && sensorValue <= MaxDry) {
      flashLED(redLED, "Dry Reading: ", sensorValue);
    } else if (sensorValue >= 349.67 && sensorValue < 478.34) {
      flashLED(yellowLED, "Moderate Reading: ", sensorValue);
    } else if (sensorValue >= MaxWet && sensorValue < 349.67) {
      flashLED(greenLED, "Wet Reading: ", sensorValue);
    }
    delay(30000); // Wait for 30 seconds
    enterSleepMode();
  }
}

void flashLED(int ledPin, const char* message, int value) {
  for (int i = 0; i < 2; i++) {
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
    delay(1000);
  }
  Serial.print(message);
  Serial.println(value);
}

void enterSleepMode() {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  attachInterrupt(digitalPinToInterrupt(buttonPin), wakeUp, LOW);
  sleep_mode();
  sleep_disable();
  detachInterrupt(digitalPinToInterrupt(buttonPin));
}

void wakeUp() {
  // This function will be called when the interrupt occurs
}

This code is designed to be uploaded to the Arduino Pro Mini. It initializes the pins connected to the LEDs and the pushbutton, sets up the serial communication, and writes calibration values to EEPROM. The main loop checks for button presses and reads the moisture sensor, lighting the appropriate LED and printing the reading to the serial monitor. After a delay, it enters sleep mode to save power.