IOT control temp and PM 2.5 using ESP8266 Node MCU + water spray system

 

This project add soil sensor for measure wet in soil then program control solenoid feed water valve through nozzle splash foggy water to plant and cool ambien temperature down and same time water misc with reduce PM 2.5 dust in the same time.

 

Add  Blynk application follow this

 

 

 

Add Relay and Soi sensor

Sensor

เครื่องวัดความหนาแน่นของความชื้นความชื้นความชื้น เซนเซอร์ สำหรับ Arduino

https://sea.banggood.com/custlink/GmGvctPJ9N

โมดูลรีเลย์ 12V 2 ช่องพร้อมการสนับสนุน Optocoupler การเรียกระดับต่ำสำหรับ Arduino

https://sea.banggood.com/custlink/3K3mWP5cFy

 

Soi connect to  D2

Relay IN1 >>> D0
IN2>>>  D1

 

 

VDO How to make

 

CODE

#include <Adafruit_Sensor.h>

/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest

Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.

Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp


Blynk library is licensed under MIT license
This example code is in public domain.

*************************************************************
qwert7yip0[p=]\
This example shows how value can be pushed from Arduino to
the Blynk App.

WARNING :
For this example you'll need Adafruit DHT sensor libraries:
https://github.com/adafruit/Adafruit_Sensor
https://github.com/adafruit/DHT-sensor-library

App project setup:
Value Display widget attached to V5
Value Display widget attached to V6
*************************************************************/

// www.a-arduino.com

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <SPI.h>

#include<ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#include <DHT.h>


//////////oled display

#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`

//////////////


// TimeClient settings


/*Dust sensor

*/
int measurePin = A0;
int ledPower = D6;

const int soi = D2;
const int waterfeed = D0;
const int foggy = D1;

int soiState = 0;

unsigned int samplingTime = 280;
unsigned int deltaTime = 40;
unsigned int sleepTime = 9680;

float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;

SSD1306 display(0x3c, D3, D4);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "970a60d64416434c8e37cbc85efdbd5f";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "oppo";
char pass[] = "santi136";

#define DHTPIN D5 // What digital pin we're connected to GPIO14

// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);

/******************
* Dust
*****************/
digitalWrite(ledPower,LOW);
delayMicroseconds(samplingTime);

voMeasured = analogRead(measurePin);

delayMicroseconds(deltaTime);
digitalWrite(ledPower,HIGH);
delayMicroseconds(sleepTime);

calcVoltage = voMeasured*(3.0/1024);
dustDensity = 0.17*calcVoltage-0.1;

if ( dustDensity < 0)
{
dustDensity = 0.00;
}


Serial.println("temp:");
Serial.println(t);

Serial.println("Humi:");
Serial.println(h);

Serial.println("Raw Signal Value (0-1023):");
Serial.println(voMeasured);

Serial.println("Voltage:");
Serial.println(calcVoltage);

dustDensity = dustDensity*1000 ;

Serial.println("Dust Density micro gram/m^3:");
Serial.println(dustDensity);


Blynk.virtualWrite(V7,dustDensity);

///////////////////////////////

display.clear();
display.drawString(0, 16, String(t)+"C\t" + String(h) + "%\t"); 

display.drawString(0, 32, "Dust: " + String(dustDensity) + "ug/m^3"); 
delay(1000);
soiState = digitalRead(soi);
Serial.print(soiState);

if (soiState == HIGH) //D2
{
digitalWrite(waterfeed,LOW); // D0

WidgetLED led1(V10);
led1.on();
display.clear();
//display.drawString(0, 16, String(t)+"C\t" + String(h) + "%\t"); 
//display.drawString(0, 32, "Dust: " + String(dustDensity) + "ug/m^3"); 
display.drawString(0, 32, "FEED WATER"); 

delay(1000);

}
else{
digitalWrite(waterfeed,HIGH); // D0
WidgetLED led1(V10);
led1.off();
}

if ( t >= 36 )
{
digitalWrite(foggy,LOW); //D1

delay(2000);

digitalWrite(foggy,HIGH); //D1

}
else if( t<36 )
{
digitalWrite(foggy,HIGH); //D1
}

}

BLYNK_WRITE(V8)

{

int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();

Serial.println(pinValue);
if(pinValue == 1)
{
digitalWrite(waterfeed,LOW);

}
else
{ 
digitalWrite(waterfeed,HIGH);
}

}


BLYNK_WRITE(V9)

{

int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
Serial.print("Forward value is: ");
Serial.println(pinValue);
if(pinValue == 1)
{
digitalWrite(foggy,LOW);

}
else
{ 
digitalWrite(foggy,HIGH);
}

}
void setup()
{
// Debug console
Serial.begin(9600);

Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

dht.begin();

// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);


pinMode(ledPower,OUTPUT);

pinMode(soi,INPUT);
pinMode(waterfeed,OUTPUT);
pinMode(foggy,OUTPUT);

digitalWrite(waterfeed,HIGH);
digitalWrite(foggy,HIGH);
///////////////

display.init();

display.flipScreenVertically();
display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_LEFT);
dht.begin(); // initialize dht
}

void loop()
{
Blynk.run();
timer.run();
display.display();
}