buddhimaan
Published © GPL3+

IoT Moisture Sensor

An IoT Moisture sensor that sends moisture data from an Arduino Nano 33 IoT to the Arduino IoT Cloud

BeginnerFull instructions provided2,536
IoT Moisture Sensor

Things used in this project

Hardware components

Arduino Nano 33 IoT
Arduino Nano 33 IoT
×1
Gravity: Analog Capacitive Soil Moisture Sensor- Corrosion Resistant
DFRobot Gravity: Analog Capacitive Soil Moisture Sensor- Corrosion Resistant
×1
9V battery (generic)
9V battery (generic)
×1
9V Battery Clip
9V Battery Clip
×1
Jumper wires (generic)
Jumper wires (generic)
×3

Software apps and online services

Arduino IoT Cloud
Arduino IoT Cloud
Arduino Web Editor
Arduino Web Editor

Story

Read more

Schematics

Schematic

Circuit Diagram using Paint 3D (since I don't have fritzing)

Code

Code

Arduino
Code for Nano 33 IoT. You can modify the pin number if you have Analog Pin A1 already used.
#include "thingProperties.h"

int soilMoistureLevel;
int soilMoisturePercent;

int airValue = 830;
int waterValue = 360;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update(); // Update the Cloud's data
  
  //Read data from Analog Pin 1 on Nano 33 IoT and print to Serial Monitor for debugging
  soilMoistureLevel = analogRead(1);
  Serial.println(soilMoistureLevel);
  
  //Convert soilMoistureLevel integer into percentage by using air and water values defined above and mapping with 0 - 100
  soilMoisturePercent = map(soilMoistureLevel, airValue, waterValue, 0, 100);
  Serial.println(soilMoisturePercent); //Print to Serial Monitor for debugging
  
  
  //Update Arduino IoT Cloud values
  moistureLevel = soilMoistureLevel;
  moisturePercent = soilMoisturePercent;
  
  //If the moisture percentage is less than 30%
  if(moisturePercent < 30)
  {
    //Send message to Arduino Cloud messenger on dashboard
    message = "Water Levels Low. Watering Required!";
  }
  
  //If the moisture percentage is greater than 50%
  if(moisturePercent > 50)
  {
    //Send message to Arduino Cloud messenger on dashboard
    message = "Water Levels Sufficient.";
  }
  
  
}


//End of Code

Credits

buddhimaan

buddhimaan

3 projects • 5 followers

Comments