Ahmad Radhy
Published © MIT

LoraWAN Natural Drying System in Post-Harvest Agriculture

Smart IoT Sensors In Natural Drying System of Post-Harvest Agriculture

IntermediateWork in progressOver 2 days975
LoraWAN Natural Drying System in Post-Harvest Agriculture

Things used in this project

Hardware components

Helium Developer Kit
Helium Developer Kit
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
The Things Gateway
The Things Industries The Things Gateway
×1

Software apps and online services

Arduino IDE
Arduino IDE
The Things Stack
The Things Industries The Things Stack

Story

Read more

Schematics

Infrastructure of Drying System

Code

Dev Kit sensors

Arduino
/* Simple OTAA join for TheThingNetwork LoRaWAN network
 *
 *  Uncomment one of the region defined below to select the
 *  proper radio setup.
 *    
 *  EU868/IN865 have duty cycle restrictions. For debugging it makes sense
 *  to disable those via setDutyCycle(false);
 *    
 *  For an external antenna one should set the proper antenna gain
 *  (default is 2.0) via setAntennaGain().
 *    
 *  Please edit the keys below as they are just debugging samples.
 *    
 *    
 * This example code is in the public domain.
 */

#include "LoRaWAN.h"
#include <DHT.h>
#include <Adafruit_Sensor.h>

// #define REGION_AS923_920_923 /* Japan, Malaysia, Singapore */
// #define REGION_AS923_923_925 /* Brunei, Cambodia, Hong Kong, Indonesia, Laos, Taiwan, Thailand, Vietnam */
// #define REGION_AU915
// #define REGION_EU868
// #define REGION_IN865
// #define REGION_KR920
#define REGION_US915

const char *appEui  = "xxxxxxxxxxx";
const char *appKey  = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const char *devEui  = "xxxxxxxxxxx";

#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

void setup( void )
{
    Serial.begin(9600);
    dht.begin();
    
    while (!Serial) { }

#if defined(REGION_AS923_920_923)
    LoRaWAN.begin(AS923);
#endif

#if defined(REGION_AS923_920_923)
    LoRaWAN.begin(AS923);
#endif

#if defined(REGION_AU915)
    LoRaWAN.begin(AU915);
    LoRaWAN.setSubBand(2);
#endif

#if defined(REGION_EU868)
    LoRaWAN.begin(EU868);
    LoRaWAN.addChannel(1, 868300000, 0, 6);
#endif

#if defined(REGION_IN865)
    LoRaWAN.begin(IN865);
#endif

#if defined(REGION_KR920)
    LoRaWAN.begin(KR920);
#endif

#if defined(REGION_US915)
    LoRaWAN.begin(US915);
    LoRaWAN.setSubBand(2);
#endif

    // LoRaWAN.setDutyCycle(false);
    // LoRaWAN.setAntennaGain(2.0);
    LoRaWAN.joinOTAA(appEui, appKey, devEui);

    Serial.println("JOIN( )");
}

void loop( void )
{

  uint16_t humidity = dht.readHumidity(false) * 100;

  // false: Celsius (default)
  // true: Farenheit
  uint16_t temperature = dht.readTemperature(false) * 100;
  // Split both words (16 bits) into 2 bytes of 8
  
  byte payload[4];
  payload[0] = highByte(temperature);
  payload[1] = lowByte(temperature);
  payload[2] = highByte(humidity);
  payload[3] = lowByte(humidity);

  
    if (LoRaWAN.joined() && !LoRaWAN.busy())
    {
        Serial.print("TRANSMIT( ");
        Serial.print("TimeOnAir: ");
        Serial.print(LoRaWAN.getTimeOnAir());
        Serial.print(", NextTxTime: ");
        Serial.print(LoRaWAN.getNextTxTime());
        Serial.print(", MaxPayloadSize: ");
        Serial.print(LoRaWAN.getMaxPayloadSize());
        Serial.print(", DR: ");
        Serial.print(LoRaWAN.getDataRate());
        Serial.print(", TxPower: ");
        Serial.print(LoRaWAN.getTxPower(), 1);
        Serial.print("dbm, UpLinkCounter: ");
        Serial.print(LoRaWAN.getUpLinkCounter());
        Serial.print(", DownLinkCounter: ");
        Serial.print(LoRaWAN.getDownLinkCounter());
        Serial.println(" )");

        LoRaWAN.beginPacket();
        LoRaWAN.write(payload, sizeof(payload));
        LoRaWAN.endPacket();
    }

    delay(10000);
}

Credits

Ahmad Radhy

Ahmad Radhy

23 projects • 42 followers
Physicist and IoT Software and Hardware Engineer
Thanks to Aldi Raharja.

Comments