Soil moisture combined with Temperature sensor (BME 280)

HI I'm new to Arduino can you guys help me out , so it be like this , i was looking for soil moisture project to determine the moisture of soil and displayed through LCD display . now i want to combine the soil moisture sensor with LCD display and BME 280 with another display (OLED) but seems like i was having some trouble compiling the codes because i was copy and paste the codes

the codes are shown below

#include <Wire.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

//#define SEALEVELPRESSURE_HPA (1013.25)
#define SEALEVELPRESSURE_HPA (1039.76)

Adafruit_BME280 bme;

void setup() {
Serial.begin(9600);

if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}

void loop() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println("*C");

Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println("hPa");

Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println("m");

Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println("%");

Serial.println();
delay(1000);
}

int sensorPin = A0;
int sensorValue = 0;
int percentValue = 0;
LiquidCrystal_I2C lcd(0x27,16,2);

void setup() {
Serial.begin(9600);
lcd.init();
}

void loop() {

sensorValue = analogRead(sensorPin);
Serial.print("\n\nAnalog Value: ");
Serial.print(sensorValue);

percentValue = map(sensorValue, 1023, 200, 0, 100);
lcd.backlight();
Serial.print("\nPercentValue: ");

Serial.print(percentValue);
Serial.print("%");
lcd.setCursor(0, 0);
lcd.backlight();
lcd.print("Soil Moisture");

lcd.setCursor(0, 1);
lcd.backlight();
lcd.print("Percent: ");
lcd.print(percentValue);
lcd.backlight();
lcd.print("%");
delay(1000);
lcd.clear();
}

You can only have one setup() and one loop() function.

Hi @jefffer .

Please use tags when posting sketches or printouts.
To use tags just click in the toolbar on </> and post your sketck.

If you had read How to get the best out of this forum you would have been better informed.

I modified your sketch to form a single set of setup() and loop(), but I haven't tested it.
Test and then say the result.

RV mineirin


int sensorPin = A0;
int sensorValue = 0;
int percentValue = 0;

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

//#define SEALEVELPRESSURE_HPA (1013.25)
#define SEALEVELPRESSURE_HPA (1039.76)

Adafruit_BME280 bme;

void setup() {
  Serial.begin(9600);
  lcd.init();
  if (!bme.begin(0x76)) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }
}
//--------------------------------------------------
void loop() {
  temp();
  soil();
}
//--------------------------------------------------
void temp()
{
  Serial.print("Temperature = ");
  Serial.print(bme.readTemperature());
  Serial.println("*C");

  Serial.print("Pressure = ");
  Serial.print(bme.readPressure() / 100.0F);
  Serial.println("hPa");

  Serial.print("Approx. Altitude = ");
  Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  Serial.println("m");

  Serial.print("Humidity = ");
  Serial.print(bme.readHumidity());
  Serial.println("%");

  Serial.println();
  delay(1000);
}
//--------------------------------------------------
void soil() {
  sensorValue = analogRead(sensorPin);
  Serial.print("\n\nAnalog Value: ");
  Serial.print(sensorValue);

  percentValue = map(sensorValue, 1023, 200, 0, 100);
  lcd.backlight();
  Serial.print("\nPercentValue: ");

  Serial.print(percentValue);
  Serial.print("%");
  lcd.setCursor(0, 0);
  lcd.backlight();
  lcd.print("Soil Moisture");

  lcd.setCursor(0, 1);
  lcd.backlight();
  lcd.print("Percent: ");
  lcd.print(percentValue);
  lcd.backlight();
  lcd.print("%");
  delay(1000);
  lcd.clear();
}
1 Like

wow so helpful!! i just tested the code and it was success Thankyou very much !!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.