# # # # Oled - Reset 4
# # # # Oled - Reset 4
# # # # Oled - Reset 4
h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
const int AirValue = 620; //you need to replace this value with Value_1
const int WaterValue = 310; //you need to replace this value with Value_2
int soilMoistureValue = 0;
int soilmoisturepercent=0;
void setup() {
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C
(128x64)
display.clearDisplay();
}
void loop() {
soilMoistureValue = analogRead(A0); //put Sensor insert into soil
Serial.println(soilMoistureValue);
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0,
100);
if(soilmoisturepercent > 100)
{
Serial.println("100 %");
delay(250);
display.clearDisplay();
}
else if(soilmoisturepercent <0)
{
Serial.println("0 %");
delay(250);
display.clearDisplay();
}
else if(soilmoisturepercent >0 && soilmoisturepercent < 100)
{
Serial.print(soilmoisturepercent);
Serial.println("%");
delay(250);
display.clearDisplay();
}
}