Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Based Smart Soil Monitoring System with RS485 and Multiple Sensors

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Soil Monitoring System with RS485 and Multiple Sensors

Circuit Documentation

Summary

This circuit is designed to interface an ESP32 microcontroller with various sensors including a DS18B20 temperature sensor, a YL-69 soil moisture sensor, a pH meter, an RS485 communication module, and an NPK soil sensor. The ESP32 reads data from these sensors and communicates with the NPK soil sensor via RS485.

Component List

  1. ESP32 Wroom Dev Kit

    • Description: A powerful microcontroller with Wi-Fi and Bluetooth capabilities.
    • Pins: NOP, EN, VP, VN, GPIO 34, GPIO 35, GPIO 32, GPIO 33, GPIO 25, GPIO 26, GPIO 27, GPIO 14, GPIO 13, V5, GPIO 23, GPIO 22, TXD, RXD, GPIO 21, GND, GPIO 19, GPIO 18, GPIO 5, GPIO 17, GPIO 16, GPIO 4, GPIO 0, GPIO 15, 3V3
  2. Humidity YL-69

    • Description: A soil moisture sensor.
    • Pins: A0, D0, GND, VCC
  3. DS18B20

    • Description: A digital temperature sensor.
    • Pins: signal, GND, vcc
  4. Resistor

    • Description: A 4700 Ohms resistor.
    • Pins: pin1, pin2
    • Properties: Resistance: 4700 Ohms
  5. PH Meter

    • Description: A sensor to measure pH levels.
    • Pins: Signal, VCC, GND
  6. RS485

    • Description: A module for RS485 communication.
    • Pins: VCC, RO, RE, GND, B, A, DE, DI
  7. NPK Soil Sensor (mini)

    • Description: A sensor to measure NPK levels in soil.
    • Pins: VCC, GND, A, B

Wiring Details

ESP32 Wroom Dev Kit

Humidity YL-69

DS18B20

Resistor

PH Meter

RS485

NPK Soil Sensor (mini)

Code Documentation

#include <OneWire.h>
#include <DallasTemperature.h>
#include <HardwareSerial.h>

// DS18B20
#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

// Soil Moisture Sensor
#define SOIL_MOISTURE_PIN 35

// pH Sensor
#define PH_PIN 34

// RS485
HardwareSerial RS485Serial(1);
#define RS485_RX 16
#define RS485_TX 17
#define RS485_DE_RE 18

void setup() {
  Serial.begin(115200);
  
  // DS18B20
  sensors.begin();
  
  // RS485
  RS485Serial.begin(9600, SERIAL_8N1, RS485_RX, RS485_TX);
  pinMode(RS485_DE_RE, OUTPUT);
  digitalWrite(RS485_DE_RE, LOW); // Set to receive mode initially
}

void loop() {
  // Read DS18B20
  sensors.requestTemperatures();
  float tempC = sensors.getTempCByIndex(0);
  Serial.print("DS18B20 Temperature: ");
  Serial.print(tempC);
  Serial.println(" *C");
  
  // Read Soil Moisture Sensor
  int soilMoistureValue = analogRead(SOIL_MOISTURE_PIN);
  Serial.print("Soil Moisture Value: ");
  Serial.println(soilMoistureValue);
  
  // Read pH Sensor
  int phValue = analogRead(PH_PIN);
  Serial.print("pH Value: ");
  Serial.println(phValue);
  
  // Read NPK Sensor via RS485
  // Set to transmit mode
  digitalWrite(RS485_DE_RE, HIGH);
  RS485Serial.write("Your command to NPK sensor"); // Replace with actual command
  delay(100); // Wait for the command to be sent
  
  // Set to receive mode
  digitalWrite(RS485_DE_RE, LOW);
  if (RS485Serial.available()) {
    String response = RS485Serial.readString();
    Serial.print("NPK Sensor Response: ");
    Serial.println(response);
  }
  
  delay(2000);
}

This code initializes the sensors and the RS485 communication module, reads data from the sensors, and prints the data to the serial monitor. The RS485 communication is used to send and receive data from the NPK soil sensor.