Eco-Smart AQ/AG Mesh Node

Self-sustained smart aquaculture/agriculture node powered by renewable energy, with mesh network & advanced sensors for real-time monitoring

AdvancedWork in progress4 days73
Eco-Smart AQ/AG Mesh Node

Things used in this project

Hardware components

Nordic Semiconductor nRF9151 DK
×1
DFRobot Water Turbine Generator (5VDC)
The quantity to be increased or cascaded based on the current requirements during development
×2
TP4056 1A Li-ion lithium Battery Charging Module With Current Protection – Type C
*subjective to change during development
×1
DFRobot Gravity: 7/24 Industrial Analog pH Meter Kit
×1
DFRobot Gravity: Lab Grade Analog EC / Electrical Conductivity Sensor Kit
×1
DFRobot Gravity: Analog Dissolved Oxygen / DO Sensor Meter Kit
×1
DFRobot Gravity: Industrial Stainless Steel Submersible Pressure Level Sensor(0~5m)
×1
DFRobot Gravity: Analog TDS Sensor
×1
DFRobot Gravity: Analog Turbidity Sensor for Arduino
×1
DFRobot Gravity: Analog Industrial ORP Sensor
×1
DFRobot Waterproof DS18B20 Digital Temperature Sensor
×1

Software apps and online services

Fusion
Autodesk Fusion
nRF Connect SDK
Nordic Semiconductor nRF Connect SDK
Zephyr RTOS
Zephyr Project Zephyr RTOS
PCBWay 3D Printing Service

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Land Unit Enclosure Mechanical Design

Base and top lid of the land unit enclosure.

Water Unit Enclosure Mechanical Design

Base and top lid of the water unit enclosure.

Mechanical Design Work Files

Contains Autodesk Fusion work files for the Land Unit and Water Unit enclosures. The work files will include all the STEP files of the assembled boards and devices (main unit, sensor boards, battery, etc.) integrated into the enclosure.

Code

main.c

C/C++
/******************************************************************************
 * Eco-Smart AQ/AG Mesh Node
 * 
 * Features:
 * - Air Quality (BME680: CO2, TVOC, Temp, Humidity, Pressure)
 * - Soil Monitoring (Moisture, NPK, pH)
 * - Water Quality (pH, Dissolved Oxygen, Turbidity, Temp)
 * - LoRaWAN + Mesh Networking
 * - Solar-Powered Low-Energy Operation
 ******************************************************************************/

#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "boards.h"
#include "timer.h"
#include "bme680.h"
#include "ads1115.h"
#include "ds18b20.h"    // Water temp sensor
#include "sensor.h"
#include "low_power.h"
#include "lorawan.h"
#include "mesh.h"
#include "solar.h"

// Configuration
#include "config.h"

// Global variables
static TimerEvent_t appTimer;
static bool sleepMode = false;
static sensor_data_t sensorData;

// Function prototypes
static void init_sensors(void);
static void read_sensors(void);
static void process_sensor_data(void);
static void send_data(void);
static void enter_sleep_mode(void);
static void wake_up_handler(void);

/******************************************************************************
 * Main Application
 ******************************************************************************/
int main(void) {
    BoardInitMcu();
    BoardInitPeriph();
    
    if (LORAWAN_Init() != LORAWAN_SUCCESS) {
        BoardDeInitMcu();
        while (1); // Hang if LoRaWAN fails
    }
    
    init_sensors();     // Initialize all sensors
    MESH_Init();        // Initialize mesh
    SOLAR_Init();       // Initialize solar
    
    TimerInit(&appTimer, wake_up_handler);
    TimerSetValue(&appTimer, SLEEP_INTERVAL_MS);
    
    while (1) {
        if (!sleepMode) {
            read_sensors();         // Read air, soil, water
            process_sensor_data();  // Process data
            send_data();            // Send via LoRaWAN/mesh
            SOLAR_Update();         // Check solar status
            enter_sleep_mode();     // Enter low-power mode
        }
        
        MESH_Process();     // Handle mesh packets
        LORAWAN_Process();  // Handle LoRaWAN events
    }
}

/******************************************************************************
 * Sensor Initialization (Air, Soil, Water)
 ******************************************************************************/
static void init_sensors(void) {
    // Air Quality (BME680)
    if (BME680_Init() != BME680_OK) {
        // Handle error
    }
    
    // Soil Sensors (ADS1115)
    if (ADS1115_Init() != ADS1115_OK) {
        // Handle error
    }
    
    // Water Sensors (DS18B20 for temp)
    if (DS18B20_Init() != DS18B20_OK) {
        // Handle error
    }
}

/******************************************************************************
 * Read All Sensors (Air, Soil, Water)
 ******************************************************************************/
static void read_sensors(void) {
    // Air Quality (BME680)
    BME680_Read(&sensorData.temperature, 
                &sensorData.humidity, 
                &sensorData.pressure, 
                &sensorData.gas_resistance);
    
    // Soil Sensors (ADS1115)
    sensorData.soil_moisture = ADS1115_ReadChannel(SOIL_MOISTURE_CHANNEL);
    sensorData.soil_npk = ADS1115_ReadChannel(SOIL_NPK_CHANNEL);
    sensorData.soil_ph = ADS1115_ReadChannel(SOIL_PH_CHANNEL);
    
    // Water Quality (ADS1115 + DS18B20)
    sensorData.water_ph = ADS1115_ReadChannel(WATER_PH_CHANNEL);
    sensorData.water_do = ADS1115_ReadChannel(WATER_DO_CHANNEL);
    sensorData.water_turbidity = ADS1115_ReadChannel(WATER_TURBIDITY_CHANNEL);
    sensorData.water_temp = DS18B20_ReadTemp();
    
    // Power Status
    sensorData.battery_voltage = BoardGetBatteryLevel();
    sensorData.solar_charging = SOLAR_IsCharging();
    sensorData.solar_voltage = SOLAR_GetVoltage();
}

/******************************************************************************
 * Process Sensor Data (Calibration & Unit Conversion)
 ******************************************************************************/
static void process_sensor_data(void) {
    // Soil Moisture (%)
    sensorData.soil_moisture = (sensorData.soil_moisture - SOIL_DRY_VALUE) * 100.0 / 
                              (SOIL_WET_VALUE - SOIL_DRY_VALUE);
    sensorData.soil_moisture = (sensorData.soil_moisture < 0) ? 0 : 
                              (sensorData.soil_moisture > 100) ? 100 : sensorData.soil_moisture;
    
    // Water pH (Calibration)
    sensorData.water_ph = (sensorData.water_ph * 14.0 / 4095.0);  // 12-bit ADC to 0-14 pH
    
    // Dissolved Oxygen (% Saturation)
    sensorData.water_do = (sensorData.water_do / 4095.0) * WATER_DO_SATURATION;
    
    // Turbidity (NTU)
    sensorData.water_turbidity = (sensorData.water_turbidity / 4095.0) * 100.0;  // 0-100 NTU
}

/******************************************************************************
 * Send Data via LoRaWAN & Mesh (Supports AQ + AG)
 ******************************************************************************/
static void send_data(void) {
    uint8_t payload[PAYLOAD_SIZE];
    int payload_len = 0;
    
    // Air Quality (4 bytes)
    payload[payload_len++] = (uint8_t)(sensorData.temperature >> 8);
    payload[payload_len++] = (uint8_t)sensorData.temperature;
    payload[payload_len++] = (uint8_t)sensorData.humidity;
    payload[payload_len++] = (uint8_t)sensorData.pressure;
    
    // Soil Data (3 bytes)
    payload[payload_len++] = (uint8_t)sensorData.soil_moisture;
    payload[payload_len++] = (uint8_t)sensorData.soil_npk;
    payload[payload_len++] = (uint8_t)(sensorData.soil_ph * 10);  // pH * 10 for precision
    
    // Water Quality (5 bytes)
    payload[payload_len++] = (uint8_t)(sensorData.water_ph * 10);  // pH * 10
    payload[payload_len++] = (uint8_t)sensorData.water_do;
    payload[payload_len++] = (uint8_t)sensorData.water_turbidity;
    payload[payload_len++] = (uint8_t)(sensorData.water_temp >> 8);
    payload[payload_len++] = (uint8_t)sensorData.water_temp;
    
    // Power Status (3 bytes)
    payload[payload_len++] = (uint8_t)(sensorData.battery_voltage * 10);  // V * 10
    payload[payload_len++] = (uint8_t)(sensorData.solar_voltage * 10);    // V * 10
    payload[payload_len++] = sensorData.solar_charging ? 0x01 : 0x00;
    
    // Send via LoRaWAN
    LORAWAN_Send(payload, payload_len, false);
    
    // Broadcast to Mesh
    MESH_Broadcast(payload, payload_len);
}

/******************************************************************************
 * Power Management
 ******************************************************************************/
static void enter_sleep_mode(void) {
    sleepMode = true;
    LOW_POWER_Prepare();
    TimerStart(&appTimer);
    LOW_POWER_Enter();
}

static void wake_up_handler(void) {
    sleepMode = false;
    TimerStart(&appTimer);
}

config.h

C/C++
/******************************************************************************
 * Eco-Smart AQ/AG Mesh Node
 * Supports:
 * - Air Quality (BME680)
 * - Soil Monitoring (Moisture, NPK)
 * - Water Quality (pH, Dissolved Oxygen, Turbidity, Temperature)
 * - LoRaWAN & Mesh Networking
 ******************************************************************************/

#ifndef __CONFIG_H__
#define __CONFIG_H__

// Device Configuration
#define DEVICE_ID                 0x01        
#define DEVICE_TYPE               "AQAG-01"   
#define FIRMWARE_VERSION          "2.0.0"     

// LoRaWAN Configuration
#define LORAWAN_DEV_EUI          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
#define LORAWAN_APP_EUI          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
#define LORAWAN_APP_KEY          { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
                                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
#define LORAWAN_REGION           REGION_EU868  
#define LORAWAN_ADR_ENABLED      1           
#define LORAWAN_CONFIRMED_MSG    0           

// Air Quality Sensor (BME680)
#define BME680_I2C_ADDR          0x76        

// Soil Sensors (ADS1115 for Analog Sensors)
#define ADS1115_I2C_ADDR         0x48        
#define SOIL_MOISTURE_CHANNEL    0           
#define SOIL_NPK_CHANNEL         1           // NPK Sensor (Analog)
#define SOIL_PH_CHANNEL          2           // Soil pH (Analog)

// Water Quality Sensors (Aquaculture)
#define WATER_PH_CHANNEL         3           // Water pH (Analog)
#define WATER_DO_CHANNEL         4           // Dissolved Oxygen (Analog)
#define WATER_TURBIDITY_CHANNEL  5           // Turbidity (Analog)
#define WATER_TEMP_CHANNEL       6           // Water Temperature (DS18B20)

// Calibration Values
#define SOIL_DRY_VALUE           15000       // ADC value for dry soil
#define SOIL_WET_VALUE           8000        // ADC value for wet soil
#define WATER_PH_NEUTRAL         7.0         // Neutral pH calibration
#define WATER_DO_SATURATION      100.0       // 100% DO calibration

// Power Management
#define SLEEP_INTERVAL_MS        300000      // 5 minutes sleep
#define LOW_BATTERY_THRESHOLD    3.3         // Low battery (V)
#define CRITICAL_BATTERY_THRESHOLD 3.0       // Critical battery (V)

// Solar Charging
#define SOLAR_CHARGE_THRESHOLD   4.0         // Min solar voltage (V)
#define SOLAR_MAX_VOLTAGE        5.5         // Max solar voltage (V)

// Mesh Network
#define MESH_CHANNEL             6           
#define MESH_PAN_ID              0x1234      
#define MESH_SHORT_ADDR          0x0001      
#define MESH_TX_POWER            20          // dBm
#define MESH_BROADCAST_INTERVAL  60000       // 60 sec

// Payload Configuration (Supports AQ + AG)
#define PAYLOAD_SIZE             64          // Larger payload for all sensors

// Debug Mode
#define DEBUG_ENABLED            1           
#define SERIAL_BAUDRATE          115200      

#endif // __CONFIG_H__

Credits

Jithesh Thulasidharan
6 projects • 9 followers
Contact
Rohith M Ravi
3 projects • 0 followers
Contact
jithindev mk
3 projects • 0 followers
PCB layout designing
Contact

Comments