This circuit integrates various sensors and displays with an Arduino UNO microcontroller to measure environmental parameters such as temperature, humidity, soil moisture, and raindrop detection. The data collected from the sensors is displayed on an OLED display and an LCD I2C display. The Arduino UNO serves as the central processing unit, interfacing with the DHT11 temperature and humidity sensor, a rain sensor, a soil moisture sensor, and two displays (OLED and LCD) via I2C and digital/analog connections.
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
// OLED display settings
#define OLED_RESET -1
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);
// DHT11 sensor settings
#define DHTPIN 2 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
// LCD I2C display settings
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD I2C address
// Soil Moisture Sensor settings
#define SOIL_MOISTURE_PIN A1 // Analog pin connected to the soil moisture sensor
// Raindrop sensor settings
#define RAINDROP_SENSOR_PIN A0 // Analog pin connected to the raindrop sensor
void setup() {
// Initialize OLED display
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize with the I2C addr 0x3C
display.display();
delay(2000);
display.clearDisplay();
// Initialize DHT sensor
dht.begin();
// Initialize LCD display
lcd.init();
lcd.backlight();
// Set up the analog pins for soil moisture and raindrop sensors
pinMode(SOIL_MOISTURE_PIN, INPUT);
pinMode(RAINDROP_SENSOR_PIN, INPUT);
}
void loop() {
// Read temperature and humidity from DHT11
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Read soil moisture level
int soilMoistureValue = analogRead(SOIL_MOISTURE_PIN);
// Read raindrop sensor value
int raindropValue = analogRead(RAINDROP_SENSOR_PIN);
// Display temperature and humidity on OLED
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print("Temp: ");
display.print(temperature);
display.print(" C");
display.setCursor(0,10);
display.print("Humidity: ");
display.print(humidity);
display.print(" %");
display.setCursor(0,20);
display.print("Soil Moisture: ");
display.print(soilMoistureValue);
display.display();
// Display raindrop sensor information on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Raindrop:");
lcd.setCursor(0, 1);
lcd.print(raindropValue);
// Wait a bit before reading again
delay(2000);
}
This code initializes and reads data from the DHT11 sensor, soil moisture sensor, and raindrop sensor, displaying the results on the OLED and LCD displays. The OLED display shows temperature, humidity, and soil moisture levels, while the LCD display shows the raindrop sensor value. The code includes initialization of the displays and sensors, as well as the main loop where sensor readings are taken and displayed.