Arduino UNO-Based Soil Nutrient and Moisture Monitoring System with RS485 and Battery Power
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to read values from an NPK Soil Sensor using RS485 communication and a Capacitive Soil Moisture Sensor. The sensor values for Nitrogen, Phosphorous, and Potassium are read and printed to the Serial Monitor. The RS485 module is connected to the Arduino UNO. The moisture value is read from the Capacitive Soil Moisture Sensor and printed to the Serial Monitor.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
NPK Soil Sensor
- Description: A sensor used to measure the levels of Nitrogen, Phosphorous, and Potassium in the soil.
- Pins: VCC, GND, A, B
Lipo Battery 2200mAH 30c
- Description: A rechargeable lithium polymer battery.
- Pins: VCC, GND
RS485
- Description: A module used for RS485 communication.
- Pins: VCC, RO, RE, GND, B, A, DE, DI
Capacitive Soil Moisture Sensor V1.2
- Description: A sensor used to measure soil moisture levels.
- Pins: GND, VCC, AOUT
Wiring Details
Arduino UNO
- 5V connected to VCC of Capacitive Soil Moisture Sensor V1.2 and RS485.
- GND connected to GND of Capacitive Soil Moisture Sensor V1.2 and RS485.
- A0 connected to AOUT of Capacitive Soil Moisture Sensor V1.2.
- D8 connected to RE of RS485.
- D7 connected to DE of RS485.
- D3 connected to DI of RS485.
- D2 connected to RO of RS485.
NPK Soil Sensor
- VCC connected to VCC of Lipo Battery 2200mAH 30c.
- GND connected to GND of Lipo Battery 2200mAH 30c.
- A connected to A of RS485.
- B connected to B of RS485.
Lipo Battery 2200mAH 30c
- VCC connected to VCC of NPK Soil Sensor.
- GND connected to GND of NPK Soil Sensor.
RS485
- VCC connected to 5V of Arduino UNO.
- GND connected to GND of Arduino UNO.
- RE connected to D8 of Arduino UNO.
- DE connected to D7 of Arduino UNO.
- DI connected to D3 of Arduino UNO.
- RO connected to D2 of Arduino UNO.
- A connected to A of NPK Soil Sensor.
- B connected to B of NPK Soil Sensor.
Capacitive Soil Moisture Sensor V1.2
- GND connected to GND of Arduino UNO.
- VCC connected to 5V of Arduino UNO.
- AOUT connected to A0 of Arduino UNO.
Code Documentation
#include "SoftwareSerial.h"
#include "Wire.h"
/*
* This Arduino Sketch reads values from an NPK Soil Sensor using RS485
* communication and a Capacitive Soil Moisture Sensor. The sensor values for
* Nitrogen, Phosphorous, and Potassium are read and printed to the Serial
* Monitor. The RS485 module is connected to the Arduino UNO. The moisture
* value is read from the Capacitive Soil Moisture Sensor and printed to the
* Serial Monitor.
*/
#define RE 8
#define DE 7
#define MOISTURE_PIN A0
const byte nitro[] = {0x01, 0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};
const byte phos[] = {0x01, 0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};
const byte pota[] = {0x01, 0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};
byte values[11];
SoftwareSerial mod(2, 3);
void setup() {
Serial.begin(9600);
mod.begin(9600);
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
delay(500);
}
void loop() {
byte val1, val2, val3;
val1 = nitrogen();
delay(250);
val2 = phosphorous();
delay(250);
val3 = potassium();
delay(250);
int moisture = analogRead(MOISTURE_PIN);
Serial.print("Nitrogen: ");
Serial.print(val1);
Serial.println(" mg/kg");
Serial.print("Phosphorous: ");
Serial.print(val2);
Serial.println(" mg/kg");
Serial.print("Potassium: ");
Serial.print(val3);
Serial.println(" mg/kg");
Serial.print("Moisture: ");
Serial.println(moisture);
delay(2000);
}
byte nitrogen() {
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
if (mod.write(nitro, sizeof(nitro)) == 8) {
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
for (byte i = 0; i < 7; i++) {
values[i] = mod.read();
Serial.print(values[i], HEX);
}
Serial.println();
}
return values[4];
}
byte phosphorous() {
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
if (mod.write(phos, sizeof(phos)) == 8) {
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
for (byte i = 0; i < 7; i++) {
values[i] = mod.read();
Serial.print(values[i], HEX);
}
Serial.println();
}
return values[4];
}
byte potassium() {
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
if (mod.write(pota, sizeof(pota)) == 8) {
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
for (byte i = 0; i < 7; i++) {
values[i] = mod.read();
Serial.print(values[i], HEX);
}
Serial.println();
}
return values[4];
}
This code initializes the Arduino UNO to read values from the NPK Soil Sensor and the Capacitive Soil Moisture Sensor. The values are then printed to the Serial Monitor. The RS485 module is used for communication with the NPK Soil Sensor, and the Capacitive Soil Moisture Sensor is read using an analog pin.