Francesco Azzola
Published © CC BY-SA

IoT System To Monitor Soil Moisture With Arduino

This IoT system monitors the soil moisture using Arduino and sensors. Data are sent to an IoT cloud platform to access it anywhere.

IntermediateFull instructions provided2 hours7,721
IoT System To Monitor Soil Moisture With Arduino

Things used in this project

Story

Read more

Schematics

Soil moisture with Arduino

Code

Code snippet #2

Plain text
#include "WiFi101.h"
WiFiClient client;
void setup() {
  Serial.begin(9600);
  Serial.print("Starting...");

  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while (true);
  }
  connectToWifi();
}

Code snippet #3

Plain text
void connectToWifi() {
  while ( status != WL_CONNECTED) {
   Serial.print("Attempting to connect to WPA SSID: ");
   Serial.println(ssid);
   // Connect to WPA/WPA2 network:
   status = WiFi.begin(ssid, pass);
   // wait 10 seconds for connection:
  delay(10000);
 }
}

Code snippet #4

Plain text
void sendData(float data) {
  if (client.connect(server,80)) {
   Serial.println("Connected to the server....");

   String jsonData = "{\"protocol\":\"v2\",\"device\":\""+DEVICE_ID+
                     "\",\"at\":\"now\",\"data\":{\"soil\":\""+
                     String(data)+"\"}}";  // Make a HTTP request
  client.println("POST /streams HTTP/1.1");
  client.println("Host: api.carriots.com");
  client.println("Accept: application/json");
  client.println("User-Agent: Arduino-Carriots");
  client.println("Content-Type: application/json");
  client.print("carriots.apikey: ");
  client.println(API_KEY);
  client.print("Content-Length: ");
  int thisLength = jsonData.length();
  client.println(thisLength);
  client.println("Connection: close");
  client.println();
  client.println(jsonData);
 }
}

Credits

Francesco Azzola

Francesco Azzola

4 projects • 16 followers
I'm an electronic engineer with over 15 years of experience in programming. I'm the Book Author "Android things projects". Dzone MVB

Comments