Soil Moisture Monitoring using ESP8266 and Blynk

 #define BLYNK_TEMPLATE_ID "template id"

#define BLYNK_TEMPLATE_NAME "template name"

#define BLYNK_AUTH_TOKEN "Auth token"


#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>


const int sensor_pin = A0;  /* Connect Soil moisture analog sensor pin to A0 of NodeMCU */

char ssid[] = "Wifi name";

char pass[] = "Wifi password";

BlynkTimer timer; //that creates a timer object used to run functions at fixed time intervals

void sendSensor() // function for reading and sending sensor data.

{

  int moisture_percentage;

  moisture_percentage = ( 100.00 - ( (analogRead(sensor_pin)/1023.00) * 100.00 ) );

//For zero moisture, we get the maximum value of 10-bit ADC, i.e. 1023.

  Serial.print("Soil Moisture(in Percentage) = ");

  Serial.print(moisture_percentage);

  Serial.println("%");

  delay(1000);

   

  // You can send any value at any time.

  // Please don't send more that 10 values per second.

  Blynk.virtualWrite(V5, moisture_percentage);

}

void setup() {

    pinMode(sensor_pin, INPUT);

  Serial.begin(115200); /* Define baud rate for serial communication */

    Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

    timer.setInterval(1000L, sendSensor);

}

void loop() {

  Blynk.run();

  timer.run();

}

Comments

Popular posts from this blog

System Bus Types, Functions, and Features

Motherboard form factor

ESP 8266- Ultrasonic Sensor Interfacing