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

Message

The document contains an Arduino code for a soil moisture monitoring system using a soil moisture sensor, LCD display, buzzer, and RGB LED. It reads the soil moisture level, displays the status on the LCD, and activates the buzzer and RGB LED based on the moisture level (dry, moist, or wet). The system provides feedback through visual and auditory signals to indicate the moisture condition of the soil.

Uploaded by

martina
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)
4 views2 pages

Message

The document contains an Arduino code for a soil moisture monitoring system using a soil moisture sensor, LCD display, buzzer, and RGB LED. It reads the soil moisture level, displays the status on the LCD, and activates the buzzer and RGB LED based on the moisture level (dry, moist, or wet). The system provides feedback through visual and auditory signals to indicate the moisture condition of the soil.

Uploaded by

martina
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
You are on page 1/ 2

#include <LiquidCrystal_I2C.

h>
LiquidCrystal_I2C lcd (0x27, 16,2);
//INT MEANS INTEGER, IT IS USED TO GIVE DECLARATION TO DIGITAL PINS
//SOIL MOISTURE SENSOR
int soilpin= A0;
//BUZZER
int buzz= 2;
//RGB
int R=9;
int G=10;
int B=11;
void setup()
{
pinMode (buzz, OUTPUT);
pinMode (soilpin, INPUT);
//SERIAL.BEGIN USED TO INITIALIZE THE SERIAL MONITOR.
//SYNTAX IS USED TO TURN ON THE BACKLIGHT AND INITIALIZE THE LCD.
Serial.begin(9600);
lcd.backlight();
lcd.init();
}
void loop()
{
//THE SYNTAX ANALOGREAD USED TO READ THE ANALOG MEASUREMENT FROM THE SENSOR.
//FLOAT USED TO NAME A DECIMAL VALUE.
int soilmoistureVal= analogRead (soilpin);
float soilmoisturePercen=map(soilmoistureVal, 1023,0,0,100);
Serial.print("Soil Moisture");
Serial.print (soilmoisturePercen);
Serial.println("%" );
delay (1000);

if (soilmoisturePercen <=5)
{
//IF SOIL IS DRY, "SOIL IS DRY" WILL DISPLAY.
lcd.setCursor(0,0);
lcd.print("SOIL IS DRY");
lcd.setCursor(0,1);
lcd.print(soilmoisturePercen);
lcd.print("%");
delay (2000);
lcd.clear();
//IF SOIL IS DRY, THE BUZZER WILL MAKE A NOISE.
digitalWrite (buzz, HIGH);
//IF SOIL IS DRY; THE RGB WILL TURN RED.
analogWrite (R, 255);
analogWrite (G, 0);
analogWrite (B, 0);

}
else if (soilmoisturePercen<=50)
{
//IF SOIL IS MOIST, "SOIL IS MOIST" WILL DISPLAY.
lcd.setCursor (0,0);
lcd.print ("SOIL IS MOIST");
lcd.setCursor (0,1);
lcd.print (soilmoisturePercen);
lcd.print ("%");
delay (2000);
lcd.clear ();
//IF THE SOIL IS MOIST, THE BUZZER WILL MAKE A NOISE.
digitalWrite (buzz, HIGH);
//IF THE SOIL IS MOIST, THE RGB WILL TURN GREEN.
analogWrite (R, 0);
analogWrite (G, 255);
analogWrite (B, 0);
}
else
{
//IF NO CONDITIONS ARE MET, "SOIL IS WET" WILL DISPLAY.
lcd.print ("SOIL IS WET");
lcd.setCursor (0,1);
lcd.print (soilmoisturePercen);
lcd.print ("%");
delay (2000);
lcd.clear ();
//IF NO CONDITIONS ARE MET, THE BUZZER WILL NOT SOUND.
digitalWrite (buzz, LOW);
//IF THE SOIL IS WET, THE RGB WILL TURN BLUE.
analogWrite (R, 0);
analogWrite (G, 0);
analogWrite (B, 255);
}
}

You might also like