0% found this document useful (0 votes)
3 views2 pages

Arduino Soil Moisture Monitor Code

This document contains an Arduino sketch that reads soil moisture levels using a sensor and controls a relay to operate a motor based on the moisture level. It displays the moisture status on an LCD screen and sends corresponding messages to the serial monitor. The program categorizes the soil moisture into three states: dry, medium, and wet, and activates or deactivates the motor accordingly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Arduino Soil Moisture Monitor Code

This document contains an Arduino sketch that reads soil moisture levels using a sensor and controls a relay to operate a motor based on the moisture level. It displays the moisture status on an LCD screen and sends corresponding messages to the serial monitor. The program categorizes the soil moisture into three states: dry, medium, and wet, and activates or deactivates the motor accordingly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <Wire.

h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header

hd44780_I2Cexp lcd;
int sensor_pin = A0;
int relay_pin = 7;

void setup()
{
[Link](9600);
[Link](16,2);//Defining 16 columns and 2 rows of lcd display
[Link]();//To Power ON the back light
pinMode(sensor_pin, INPUT);
pinMode(relay_pin, OUTPUT);

void loop()
{
int sensor_data = analogRead(sensor_pin);
[Link]("Sensor_data:");
[Link](sensor_data);
[Link]("\t | ");

if(sensor_data > 600)


{
[Link]("No moisture, Soil is dry");
digitalWrite(relay_pin, HIGH);
[Link]();//Clean the screen
[Link](0,0); //Defining positon to write from first column,first row .
[Link]("Soil Dry-"); //You can write 16 Characters per line .
[Link](sensor_data);
[Link](0,1); //Defining positon to write from first column,second row .
[Link]("Motor ON");
}
else if(sensor_data >= 400 && sensor_data <= 600)
{
[Link]("There is some moisture, Soil is medium");
digitalWrite(relay_pin, LOW);
[Link]();//Clean the screen
[Link](0,0);
[Link]("Soil Medium-");
[Link](sensor_data);
[Link](0,1);
[Link]("Motor OFF");
}
else if(sensor_data < 400)
{
[Link]("Soil is wet");
digitalWrite(relay_pin, LOW);
[Link]();//Clean the screen
[Link](0,0);
[Link]("Soil Wet-");
[Link](sensor_data);
[Link](0,1);
[Link]("Motor OFF");
}
delay(100);
}

You might also like