Bookmark

Monday 17 January 2022

Friday 19 February 2021

Measure Soil Nutrient using Arduino & Soil NPK Sensor - private use

 

S.N.Components NameDescriptionQuantity
1Arduino BoardArduino Nano1https://amzn.to/2tsBbp1
2NPK SensorJXCTIOT Soil NPK Sensor1https://amzn.to/38kHbAH
3OLED Display0.96" I2C OLED Display1https://amzn.to/2XaQ5uz
4Modbus ModuleMAX485 Modbus1https://amzn.to/36PM2JG
5Power Supply9V - 12V DC Supply1https://amzn.to/3fhi057
6Connecting WiresJumper Wires10https://amzn.to/2L8Xc1p
7Breadboard-1https://amzn.to/2YM6YyS

Soil NPK Sensor

The soil NPK sensor is suitable for detecting the content of nitrogen, phosphorus, and potassium in the soil. It helps in determining the fertility of the soil thereby facilitating the systematic assessment of the soil condition. The sensor can be buried in the soil for a long time. It has a High-quality proberust resistanceelectrolytic resistancesalt & alkali corrosion resistance, to ensure the long-term operation of the probe part. Therefore, it is suitable for all kinds of soil. It is suitable for the detection of alkaline soil, acid soil, substrate soil, seedling bed soil & coconut bran soil.

Soil NPK Sensor

The sensor doesn’t require any chemical reagent. Since it has High measurement accuracy, fast response speed, and good interchangeability, it can be used with any microcontroller. You cannot use the sensor directly with the microcontroller as it has a Modbus Communication port. Hence you need any Modbus Module like RS485/MAX485 and connect the sensor to the microcontroller.

The sensor operates on 9-24V & power consumption is very low. While talking about the accuracy of the sensor, it is up to within 2%. The nitrogen, phosphorous & potassium measuring resolution is up to 1mg/kg (mg/l).

Specifications

1. Power: 9V-24V
2. Measuring Range: 0-1999 mg/kg (mg/l)
3. Operating Temperature: 5-45 °C
4. Resolution: 1mg/kg
5. Precision: ±2% F.S.
6. Output Signal: RS485
7. Baud Rate: 2400/4800/9600
8. Protection Class: IP68

MAX485 TTL to RS-485 Interface Module

The MAX485 TTL to RS-485 Interface Module allows us to use the RS-485 differential signaling for robust long-distance serial communications up to 1200 meters or in electrically noisy environments and is commonly used in industrial environments. It supports up to 2.5MBit/Sec data rates, but as distance goes up, the maximum data rate that can be supported comes down.

The data starts out as a typical TTL level serial as far as the microcontroller is concerned while the RS-485 module takes care of converting the electrical signals between TTL and the differential signaling used by RS-485. A significant benefit of RS-485 is that it supports multiple devices (up to 32) on the same cable, commonly referred to as ‘multi-drop’.


Specifications

1. Use MAX485 Interface chip
2. Uses differential signaling for noise immunity
3. Distances up to 1200 meters
4. Speeds up to 2.5Mbit/Sec
5. Multi-drop supports up to 32 devices on same bus
6. Red power LED
7. 5V operation


Pinout & Module Connection

The module has two 4-pin headers on the assembly.

1 x 4 Header (Data side)

RO = Receiver Output. Connects to a serial RX pin on the microcontroller
RE = Receiver Enable. Active LOW. Connects to a digital output pin on a microcontroller. Drive LOW to enable receiver, HIGH to enable Driver
DE = Driver Enable. Active HIGH. Typically jumpered to RE Pin.
DI = Driver Input. Connects to serial TX pin on the microcontroller

1 x 4 Header (Output side)

VCC = 5V
B = Data ‘B’ Inverted Line. Common with the B
A = Data ‘A’ Non-Inverted Line. Connects to A on far end module
GND = Ground

1 x 2 Screw Terminal Block (Output side)

B = Data ‘B’ Inverted Line. Connects to B on far end module
A = Data ‘A’ Non-Inverted Line. Connects to A on far end module

Interfacing Soil NPK Sensor with Arduino

Now, let us interface the Soil NPK Sensor with the Arduino Nano Board using the MAX485 Modbus Module. The connection diagram is given below.

Soil NPK Sensor Arduino Interfacing

The R0 & DI pin of from the Modbus is connected to D2 & D3 of Arduino using Software Serial. Similarly, we have to enable DE & RE high which is done by connecting them to the D7 & D8 pin of Arduino. The NPK Sensor has 4 wires. The brown one is VCC which needs a 9V-24V Power Supply. The GND pin which is black in color needs to be connected to the GND of Arduino. The Blue wire which is the B pin is connected to the B pin of MAX485 & the Yellow Wire which is the A pin is connected to the A pin of MAX485.

The 0.96″ SSD1306 OLED Display is an I2C Module. The OLED Display VCC & GND are connected to 3.3V & GND of Arduino. Similarly, its SDA & SCL pins are connected to the A4 & A5 of Arduino. You can follow the circuit diagram & assemble the circuit on a breadboard or make a custom design PCB.


Project PCB Gerber File & PCB Ordering Online

If you don’t want to assemble the circuit on breadboard and you want PCB for the project, then here is the PCB for you. The PCB Board for the NPK Meter is designed using EasyEDA online Circuit Schematics & PCB designing tool. The front side and back side of the PCB is given below.

Download Gerber File: NPK Meter PCB

Source Code/Program

The source code for interfacing Soil NPK Sensor with Arduino & retrieving Soil Nutrient value from the Sensor via Modbus command is given below. You can send the command and retrieve the value in HEX Code. The HEX code needs to be converted into Decimal to get the Measured Soil Nutrient content data.

Since we are using OLED Display to display the Soil Nutrient values (Nitrogen, Phosphorous & Potassium) in mg/kg, you will need OLED Library. Download the following OLED Library and add it to the Arduino IDE.
1. Adafruit SSD1306 LibraryDownload
2. Adafruit GFX LibraryDownload

Here is the complete source code. Compile & upload it to the Arduino Nano Board.

smart garden automatic

https://create.arduino.cc/projecthub/patelDeep/smart-garden-cda82f