element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Design For A Cause 2021
  • Challenges & Projects
  • Design Challenges
  • Design For A Cause 2021
  • More
  • Cancel
Design For A Cause 2021
Blog Landslide and Environment Monitoring System Integrated with Arduino Nano 33 IoT (6)
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ahmadradhy
  • Date Created: 5 May 2021 1:37 AM Date Created
  • Views 835 views
  • Likes 5 likes
  • Comments 0 comments
Related
Recommended

Landslide and Environment Monitoring System Integrated with Arduino Nano 33 IoT (6)

ahmadradhy
ahmadradhy
5 May 2021

This project will be demonstrated to how the report of sensor data is collected to the IoT cloud platform through MQTT service and stored on the database, in which MQTT protocol is used to communicate with each device to the broker. MQTT is a lightweight IoT messaging protocol based on the publish-subscribe model (https://www.emqx.io/mqtt).

 

 

image

 

 

It is designed as an extremely lightweight publish/subscribe messaging transport that is ideal for connecting remote devices with a small code footprint and minimal network bandwidth (https://mqtt.org/).

Now, we will create a project related to the previous project Arduino Nano 33 IoT for Early Warning Detection for Landslide (4) & Environment Monitoring Based on Arduino Nano 33 IoT and BME680. In this project, we will implement remote monitoring via Arduino Nano 33 IoT to sense environment and landslide condition and free public MQTT cloud which is operated and maintained by https://cloud.emqx.io/  and also use Arduino in PlatformIO to program Arduino Nano 33 IoT.  We use sensor BME680 for sensing environment (air temperature, humidity, and pressure) and LSM6DS3 IMU Sensor for sensing landslide condition.

 

Required Components:

  1. Arduino Nano 33 IoT
  2. PlatformIO https://platformio.org/
  3. BME680 environment sensor
  4. EMQ X Cloud https://cloud.emqx.io/
  5. MQTT X Desktop App
  6. Breadboard Electronic
  7. USB Cable

 

Arduino Nano 33 IoT Connection Diagram

 

 

image

 

 

The wiring diagram of the electronic system consists of Arduino Nano 33 IoT, Internal IMU sensor, and external BME680 sensor to collect the data which is then sent to the IoT cloud services. First, we will import WiFiNINA https://www.arduino.cc/en/Reference/WiFiNINA  and PubsubClient https://github.com/knolleary/pubsubclient  libraries. WiFiNINA can connect the Arduino Nano 33 IoT to the WiFi network, and the PubSubClient library allows us to connect to the MQTT broker and publish/subscribe to topics.

 

#include <WiFiNINA.h>

#include <PubSubClient.h>

 

We will use https://github.com/arduino-libraries/Arduino_LSM6DS3 library to interface with the IMU sensor and https://github.com/adafruit/Adafruit_BME680 for the BME680 environment sensor.

 

image

 

In the detail, we can try to use the source code below:

 

#include <Arduino.h>

#include <SPI.h>

#include <WiFiNINA.h>

#include <PubSubClient.h>

#include <Wire.h>

#include <Adafruit_Sensor.h>

#include <Adafruit_BME680.h>

#include <Arduino_LSM6DS3.h>

#include <ArduinoJson.h>


void initialize_sensor();

void initialize_wifi();

boolean reconnect();

void update_sensor();


struct senseData

{

  float temperature = 0.0F;

  float humidity = 0.0F;

  float pressure = 0.0F;

  float x = 0.0F;

  float y = 0.0F;

  float z = 0.0F;

};


static senseData data;

static char payload[256];

StaticJsonDocument<256>doc;


const char ssid[] = "";

const char password[] = "";


WiFiClient net;

PubSubClient mqttClient(net);


const char mqtt_broker[] = "w7b0b774.en.emqx.cloud";

const char publish_topic[] = "v1/devices/me/telemetry";


#define CLIENT_ID ""

#define USERNAME ""

#define PASSWORD ""


Adafruit_BME680 bme;

const long interval = 15000;

unsigned long lastMillis = 0;

long lastReconnectAttempt = 0;


void setup() {


  Serial.begin(9600);

  pinMode(LED_BUILTIN, OUTPUT);

  Wire.begin();

  initialize_sensor();

  initialize_wifi();

  mqttClient.setServer(mqtt_broker, 12143);

  lastReconnectAttempt = 0;

}


void loop() {


  if (WiFi.status() != WL_CONNECTED)

  {

    initialize_wifi();

  }


  if (!mqttClient.connected())

  {

    long now = millis();

    if (now - lastReconnectAttempt > 5000)

    {

      lastReconnectAttempt = now;


      if (reconnect())

      {

        lastReconnectAttempt = 0;

      }

 

    }

 

  } else

  {

    mqttClient.loop();

  }

 

 

  if (millis() - lastMillis > interval) {


    lastMillis = millis();

    update_sensor();

  }


}


void initialize_sensor(){


  if (!bme.begin())

  {

    Serial.println("Could not find a valid BME680");

    while (1);

  }


  bme.setTemperatureOversampling(BME680_OS_8X);

  bme.setHumidityOversampling(BME680_OS_2X);

  bme.setPressureOversampling(BME680_OS_4X);

  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);


  if (!IMU.begin())

  {

    Serial.println("Failed to initialize IMU!");

    while(1);

  }


}


void initialize_wifi(){


  delay(100);

  WiFi.disconnect();

  Serial.println();

  Serial.print("Firmware version: ");

  Serial.println(WiFi.firmwareVersion());

  Serial.print("Connecting WiFi to: ");

  Serial.println(ssid);


  while(WiFi.status() != WL_CONNECTED)

  {

    WiFi.begin(ssid, password);

    Serial.print("Attempting WiFi connection .....");

 

    if (WiFi.status() == WL_CONNECTED)

    {

      Serial.println("WiFi connected");

      Serial.println("IP address: ");

      Serial.println(WiFi.localIP());

      Serial.println("\nWiFi RSSI: ");

      Serial.println(WiFi.RSSI());

      digitalWrite(LED_BUILTIN, HIGH);

    }


    else

    {

      Serial.print("Failed to connect to WiFi");

      Serial.println(", Try again in 5 seconds");

      digitalWrite(LED_BUILTIN, LOW);

      delay(5000);

    }

 

  }

 

}


boolean reconnect(){


  Serial.println("Attempting to connect MQTT");


  if (mqttClient.connect(CLIENT_ID, USERNAME, PASSWORD))

  {

    Serial.println("Connected to MQTT broker");

  }


  return mqttClient.connected();

 

}


void update_sensor(){


  if (!bme.performReading())

  {

    Serial.println("Failed to perform reading");

    return;

  }


  float t = bme.temperature;

  float h = bme.humidity;

  float p = bme.pressure / 100.0;


  data.temperature = t;

  data.humidity = h;

  data.pressure = p;


  float x, y, z;


  if (IMU.accelerationAvailable())

  {

    IMU.readAcceleration(x, y, z);

    data.x = x;

    data.y = y;

    data.z = z;

  }

 


  doc["Temperature"] = data.temperature;

  doc["Humidity"] = data.humidity;

  doc["Pressure"] = data.pressure;

 

  doc["X"] = data.x;

  doc["Y"] = data.y;

  doc["Z"] = data.z;

 

  serializeJsonPretty(doc, payload);

  mqttClient.publish(publish_topic, payload);

  Serial.println(payload);

 

}

 

We can use the ArduinoJson library (https://arduinojson.org/ ) for packet data format to send all data sensors to the cloud.


 

image

 

EMQ X Cloud is the MQTT IoT Cloud Service Platform launched by EMQ, which provides the MQTT 5.0 access service with one-stop operations and maintenance managed and unique isolation environment.

 

 

image

 

image

 

image

 

image

 

 

To visualize all data published to the MQTT broker, we could use https://mqttx.app/.

 

 

 

 

GPS Tracking System:

image

image

Overall, the part of the design is integrated system of Arduino Nano 33 IoT for data acquisition dan GPS for tracking location, MEMS sensor for environmental monitoring, and internal IMU sensor as accelerometer and gyroscope. We can import this library https://github.com/mikalhart/TinyGPSPlus to read GPS data.

 

We could find all source code: https://github.com/radhyahmad/Nano33IoT_Ublox_Neo-7N

 

So far, we have successfully implemented remote monitoring of landslide and environment use-cases using Arduino Nano 33 IoT and a free public MQTT broker. This project only describes a simple scenario for collecting data related to landslides and environmental conditions. For real implementation, we could deploy it by using Arduino MKR WAN  as low-power devices.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube