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!
Techatronic
Published

IoT based Smart Irrigation

This project is about IoT-based smart irrigation in which we use soil moisture sensors and nodemcu.

BeginnerFull instructions provided2 hours7,608
IoT based Smart Irrigation

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
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Relay (generic)
×1
water pump
×1
LED (generic)
LED (generic)
×1
9V battery (generic)
9V battery (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1
Arduino UNO
Arduino UNO
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Code snippet #1

Plain text
  
 void sendSensor()  
 {  
  float h = dht.readHumidity();  
  float t = dht.readTemperature();  
  if (isnan(h) || isnan(t)) {  
   Serial.println("Failed to read from DHT sensor!");  
   return;  
  }  
  Blynk.virtualWrite(V5, h); //V5 is for Humidity  
  Blynk.virtualWrite(V6, t); //V6 is for Temperature  
 }  
 

Code snippet #2

Plain text
  
 void sendSensor()  
 {  
  float h = dht.readHumidity();  
  float t = dht.readTemperature();  
  if (isnan(h) || isnan(t)) {  
   Serial.println("Failed to read from DHT sensor!");  
   return;  
  }  
  Blynk.virtualWrite(V5, h); //V5 is for Humidity  
  Blynk.virtualWrite(V6, t); //V6 is for Temperature  
 }  
 

Code snippet #3

Plain text
  
 void setup()  
 {  
  Serial.begin(9600);  
  Blynk.begin(auth, ssid, pass);  
  dht.begin();  
  timer.setInterval(1000L, sendSensor);  
  Serial.begin(115200);  
  Blynk.begin(auth, ssid, pass);  
   sensors.begin();  
 }  

Code snippet #4

Plain text
  
 void setup()  
 {  
  Serial.begin(9600);  
  Blynk.begin(auth, ssid, pass);  
  dht.begin();  
  timer.setInterval(1000L, sendSensor);  
  Serial.begin(115200);  
  Blynk.begin(auth, ssid, pass);  
   sensors.begin();  
 }  

Code snippet #5

Plain text
 
 void sendTemps()  
 {  
 sensor=analogRead(A0);  
 sensors.requestTemperatures();  
 float temp = sensors.getTempCByIndex(0);   
 Serial.println(temp);  
 Serial.println(sensor);  
 Blynk.virtualWrite(V1, temp);  
 Blynk.virtualWrite(V2,sensor);  
 delay(1000);  
 }  

Code snippet #6

Plain text
 
 void sendTemps()  
 {  
 sensor=analogRead(A0);  
 sensors.requestTemperatures();  
 float temp = sensors.getTempCByIndex(0);   
 Serial.println(temp);  
 Serial.println(sensor);  
 Blynk.virtualWrite(V1, temp);  
 Blynk.virtualWrite(V2,sensor);  
 delay(1000);  
 }  

Code snippet #7

Plain text
 //TECHATRONIC.COM  
 // BLYNK LIBRARY  
 // https://github.com/blynkkk/blynk-library  
 // ESP8266 LIBRARY  
 // https://github.com/ekstrand/ESP8266wifi  
 // DHT11 SENSOR LIBRARY  
 // https://github.com/adafruit/DHT-sensor-library  
 #define BLYNK_PRINT Serial    
 #include <SPI.h>  
 #include <ESP8266WiFi.h>  
 #include <BlynkSimpleEsp8266.h>  
 #include <SimpleTimer.h>  
 #include <DHT.h>  
 #define BLYNK_PRINT Serial  
 #include <OneWire.h>  
 #include <DallasTemperature.h>  
 #define ONE_WIRE_BUS D2  
 OneWire oneWire(ONE_WIRE_BUS);  
 DallasTemperature sensors(&oneWire);  
 char auth[] =" your auth code";   
 char ssid[] = "your wifi ssid";   
 char pass[] = "your wifi password";   
 #define DHTPIN 2    
 #define DHTTYPE DHT11   // DHT11 SENSOR CONNECT D4 PIN  
 DHT dht(DHTPIN, DHTTYPE);  
 SimpleTimer timer;  
 void sendSensor()  
 {  
  float h = dht.readHumidity();  
  float t = dht.readTemperature();  
  if (isnan(h) || isnan(t)) {  
   Serial.println("Failed to read from DHT sensor!");  
   return;  
  }  
  Blynk.virtualWrite(V5, h); //V5 is for Humidity  
  Blynk.virtualWrite(V6, t); //V6 is for Temperature  
 }  
 void setup()  
 {  
  Serial.begin(9600);  
  Blynk.begin(auth, ssid, pass);  
  dht.begin();  
  timer.setInterval(1000L, sendSensor);  
  Serial.begin(115200);  
  Blynk.begin(auth, ssid, pass);  
   sensors.begin();  
 }  
 int sensor=0;  
 void sendTemps()  
 {  
 sensor=analogRead(A0);  
 sensors.requestTemperatures();  
 float temp = sensors.getTempCByIndex(0);   
 Serial.println(temp);  
 Serial.println(sensor);  
 Blynk.virtualWrite(V1, temp);  
 Blynk.virtualWrite(V2,sensor);  
 delay(1000);  
 }  
 void loop()  
 {  
  Blynk.run();   
  timer.run();   
  sendTemps();  
 }  

Code snippet #8

Plain text
 //TECHATRONIC.COM  
 // BLYNK LIBRARY  
 // https://github.com/blynkkk/blynk-library  
 // ESP8266 LIBRARY  
 // https://github.com/ekstrand/ESP8266wifi  
 // DHT11 SENSOR LIBRARY  
 // https://github.com/adafruit/DHT-sensor-library  
 #define BLYNK_PRINT Serial    
 #include <SPI.h>  
 #include <ESP8266WiFi.h>  
 #include <BlynkSimpleEsp8266.h>  
 #include <SimpleTimer.h>  
 #include <DHT.h>  
 #define BLYNK_PRINT Serial  
 #include <OneWire.h>  
 #include <DallasTemperature.h>  
 #define ONE_WIRE_BUS D2  
 OneWire oneWire(ONE_WIRE_BUS);  
 DallasTemperature sensors(&oneWire);  
 char auth[] =" your auth code";   
 char ssid[] = "your wifi ssid";   
 char pass[] = "your wifi password";   
 #define DHTPIN 2    
 #define DHTTYPE DHT11   // DHT11 SENSOR CONNECT D4 PIN  
 DHT dht(DHTPIN, DHTTYPE);  
 SimpleTimer timer;  
 void sendSensor()  
 {  
  float h = dht.readHumidity();  
  float t = dht.readTemperature();  
  if (isnan(h) || isnan(t)) {  
   Serial.println("Failed to read from DHT sensor!");  
   return;  
  }  
  Blynk.virtualWrite(V5, h); //V5 is for Humidity  
  Blynk.virtualWrite(V6, t); //V6 is for Temperature  
 }  
 void setup()  
 {  
  Serial.begin(9600);  
  Blynk.begin(auth, ssid, pass);  
  dht.begin();  
  timer.setInterval(1000L, sendSensor);  
  Serial.begin(115200);  
  Blynk.begin(auth, ssid, pass);  
   sensors.begin();  
 }  
 int sensor=0;  
 void sendTemps()  
 {  
 sensor=analogRead(A0);  
 sensors.requestTemperatures();  
 float temp = sensors.getTempCByIndex(0);   
 Serial.println(temp);  
 Serial.println(sensor);  
 Blynk.virtualWrite(V1, temp);  
 Blynk.virtualWrite(V2,sensor);  
 delay(1000);  
 }  
 void loop()  
 {  
  Blynk.run();   
  timer.run();   
  sendTemps();  
 }  

Credits

Techatronic
72 projects • 127 followers
Electronic engineer

Comments