Using ThingsBoard, MQTT, Arduino to Monitor Plant Soil Moisture, Temperature and Humidity - Part 1

Author: Shazin Sadakath


Problem

Recently I got a rose plant from one of my friends who got married. I have been having plants of all sorts at my home but as any busy guy I forget to water the plants. This is a problem I thought I need to address using technology.

Solution

After doing some research I got to know about a Platform called ThingsBoard which allows Devices to connect to a central server using HTTP, MQTT, CoAP protocols and send telemetry to visualize everything in a Dashboard. I quickly downloaded it, used my Ethernet Shield, DHT11 sensor and YL-69 Soil Moisture sensor which I had lying around to check the possibility of integrating everything together.


Implementation

I just connected YL-69 Soil Moisture sensor to Arduno Analog Pin A1 to read the sensor data and Digital Pin 7 to power it if and when required. I connected Digital Pin 6 to read the sensor data from DHT11 sensor. Finally I followed the ThingsBoard Installation guide [1] and Getting Started guide [2] to setup ThingsBoard server in my laptop.

Finally wrote the following Arduino Sketch to use Ethernet Shield to connect to the network and ThingsBoard via MQTT protocol to send data.

Arduino sketch can be found below;

#include 
#include 
#include 
#include 

// Update these with values suitable for your network.
byte mac[]    = {  0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 5);
IPAddress server(192, 168, 1, 2);

// YL-39 + YL-69 humidity sensor
byte humidity_sensor_pin = A1;
byte humidity_sensor_vcc = 7;

#define DHT11_PIN 6   
#define AUTH_TOKEN "1a3XZV0Tc17lkA7DkdKO" // ThingsBoard Device Auth Token

dht DHT;

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i=0;i



Data was sent in following format.
{"temperature":29.00, "humidity":30.00, "moisture":10, "active": false}

And was visualized in Dashboard Widgets like below;



You can see a Demo in the video below where the Blue Color Soil Moisture sensor reading go up and down based on inserting and removal of the YL-69 sensor probe and Temperature and Humidity going up when I exhale hot air into the DHT11 sensor.



Future Work

Future work would be to add ESP8266 wireless connectivity to the entire thing and using ThingsBoard rule to fire and send an email when soil moisture level goes down below a threshold.

References
 

  1. https://thingsboard.io/docs/user-guide/install/windows/
  2. https://thingsboard.io/docs/getting-started-guides/helloworld/
  3. https://create.arduino.cc/projecthub/nekhbet/using-the-yl-39-yl-69-soil-humidity-sensor-with-arduino-968268
  4. https://playground.arduino.cc/Main/DHT11Lib
  5. https://www.techtalks.lk/blog/2018/2/thingsboard-mqtt-arduino-part-1


Tags: Arduino ThingsBoard MQTT DHT11 YL-69
Views: 399

Comments

Please login or register to post a comment.


There are currently no comments.