Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Gautam JainLIPCY GARG
Created October 25, 2017

Soil Moisture Monitoring on Smartphone

The idea is to observe the Soil Moisture reading on your mobile phone without any requirement of Internet.

19
Soil Moisture Monitoring on Smartphone

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
SparkFun Soil Moisture Sensor (with Screw Terminals)
SparkFun Soil Moisture Sensor (with Screw Terminals)
×1
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×1
IOIO-OTG - V2.2
SparkFun IOIO-OTG - V2.2
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Schematic Diagram

Code

Working Code

Arduino
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

const char *ssid = "Your ssid";
const char *password = "Your password";

// Define a web server at port 80 for HTTP
ESP8266WebServer server(80);

int moisturepin = A0; //A0 pin for sensor reading

int moistureread;

void handleRoot() 
{
moistureread = analogRead(A0);

char ledText[80];  // you can create any window of your choice
  
  if (moistureread <= 350) {
    strcpy(ledText, "Soil is wet");
  }
  else if (moistureread > 350 && moistureread <=600) {
    strcpy(ledText, "Soil is normal");
  }
  else {
    strcpy(ledText, "Soil is Dry");
  }

char html[1000]; 

//Build an HTML page to display on the web-server root address
  snprintf ( html, 1000,

"<html>\
  <head>\
    <meta http-equiv='refresh' content='5'/>\
    <title>.:Soil Moisture:.</title>\
    <style>\
      body { background: linear-gradient(to bottom, rgba(243,226,199,1) 0%, rgba(182,141,76,1) 32%, rgba(193,158,103,1) 65%, rgba(233,212,179,1) 100%); font-family: Arial, Helvetica, Sans-Serif; font-size: 1.5em; Color: #000000; }\
      h1 { text-align: center;Color: #0040ff; font-family:Comic Sans MS, cursive, sans-serif; }\
      h3 { Color: #aa40ff; }\
      p { Color: #000000; font-face:Bookman Old Style; font-size:20; }\
      h6 { text-align: center;font-face:Times New Roman ;font-size:20; color:black; }\
    </style>\
  </head>\
  <body>\
    <h1>Soil Moisture Record</h1>\
    <h3>Reading: %d</h3>\
    <h3>Status: %s</h3>\
    <p>This page refreshes every 5 seconds. Click <a href=\"javascript:window.location.reload();\">here</a> to refresh the page now.</p>\
    <br>\
     <h6>&copy Gautam Lipcy | &regAll Rights Reserved</h6>\
  </body>\
</html>",

  moistureread,
  ledText
  );

   server.send ( 200, "text/html", html );
   
}
void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.println("Configuring access point...");

  //set-up the custom IP address
 
  /* You can remove the password parameter if you want the AP to be open. */
  WiFi.softAP(ssid, password);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
 
  server.on ( "/", handleRoot );
  server.on ( "/inline", []() {
    server.send ( 200, "text/plain", "this works as well" );
  } );
  server.begin();
  Serial.println("HTTP server started");
}

void loop() {
  server.handleClient();
}

Credits

Gautam Jain
2 projects • 0 followers
LIPCY GARG
0 projects • 0 followers

Comments