Jump to content

Title: Internet of Things Flower Growing System Based on ESP8266

In order to enrich our elderly care life. In this article, we will introduce the use of Esp8266 to make an intelligent flower cultivation system.假装有花

Implementation of functions

Check the current temperature, humidity and soil humidity through the mobile phone. When the soil humidity is less than 50%, automatically start the relay and water it with a water pump. Disconnect the relay if the humidity exceeds 50%.

Required Equipment

esp8266 relay DHT11 soil moisture sensor

Line connection

Equipment VCC (+) GND (-) Signal Line Relay 3VGNDD4DHT113VGNDD2 Soil Sensor 3VGNDD0

Code

#define BLINKER_WIFI

#define BLINKER_MIOT_SENSOR //Introduce Xiaoai classmate

#define soilPin A0 //Soil sensor pin DO

#define CS 2 //Define the relay pin to D4

#include Blinker.h

#include DHT.h //DHT11 sensor header file

#define DHTPIN 4 //Define DHT11 module connection pin io4 (D2 pin)

#define DHTTYPE DHT11 //Use the DHT11 temperature and humidity module, of course you can also replace other DHTs

//Storage the soil value

int soilValue;

//Define soil moisture

int soilMoisture;

char auth[]='1c2ce3eef946'; //The key key of the lamp app

char ssid[]='PDCN'; //WiFi name to connect to

char pswd[]='1234567890'; //WiFi password

BlinkerNumber HUMI('humi'); //Define the humidity data key name

BlinkerNumber TEMP('temp'); //Define the temperature data key name

BlinkerNumber TEMP2('temp2'); //Define the soil moisture data key name

DHT dht(DHTPIN, DHTTYPE); //Define dht

float humi_read=0, temp_read=0; //Initialize the read data

//Dashboard components

void heartbeat()

{

HUMI.print(humi_read); //Relay humidity data back to blinkerapp

TEMP.print(temp_read); //Relay the temperature data to blinkerapp

TEMP2.print(soilMoisture);

if(soilMoisture=50) //Soil humidity is less than 50

{

digitalWrite(CS,digitalRead(CS)); //Run the relay

}

else

{

digitalWrite(CS, HIGH);

}

}

//Real-time curve chart component

void dataStorage()

{

Blinker.dataStorage('temp', temp_read);

Blinker.dataStorage('humi', humi_read);

Blinker.dataStorage('humi2', soilMoisture);

}

//The data is returned to Xiao Ai classmate

void miotQuery(int32_t queryCode)

{

BLINKER_LOG('MIOT Query codes: ', queryCode);

int humi_read_int=humi_read; //Convert float to int type, integer

BlinkerMIOT.humi(humi_read_int); //Xiaoai receives humidity

BlinkerMIOT.temp(temp_read); //Xiaoai receives temperature

BlinkerMIOT.print();

}

void setup()

{

//Initialize the serial port Serial, enable debug output

Serial.begin(9600);//Bad rate

BLINKER_DEBUG.stream(Serial);

BLINKER_DEBUG.debugAll();

Blinker.begin(auth, ssid, pswd);//WIFI initialization settings

Blinker.attachHeartbeat(heartbeat);//Register dashboard

dht.begin();

BlinkerMIOT.attachQuery(miotQuery);//Register Xiaoai

Blinker.attachDataStorage(dataStorage);//Register real-time curve

pinMode(LED_BUILTIN, OUTPUT);

digitalWrite(LED_BUILTIN, 1);

pinMode(CS, OUTPUT);//Initialize the relay pin

digitalWrite(CS, HIGH); //Initialize the relay pin

}

void loop()

{

Blinker.run();//Responsible for processing the data received by blinker. Each time it runs, it will parse the data received by the device once. (This is very important)

float h=dht.readHumidity();//Read the humidity data collected by DHT11

float t=dht.readTemperature();//Read the temperature data collected by DHT11

if (isnan(h) || isnan(t))//Judge whether the temperature and humidity value is empty

{

BLINKER_LOG('Reading sensor data failed');

}

else

{

BLINKER_LOG('Humidity: ', h, ' %');//Print out debug information

BLINKER_LOG('Temperature: ', t, ' *C');

humi_read=h;

temp_read=t;

}

soilValue=analogRead(soilPin); //Get the soil value 0-1024

soilMoisture=map(soilValue,0,1023,100,0);//Convert 0-1024 to 100%-0 The soil moisture in the air is 1024

Blinker.delay(200);

//Delay function, maintains connection between devices and data reception processing during the delay process

}

Effect

When the humidity is less than 50%, the relay automatically works.

jhf4y2ouxkb2108.png

When the soil moisture is higher than 50%, the relay stops working u3dts10v0xi2109.png

Of course, the above code only completes the corresponding functions. There may be certain shortcomings. You can modify it yourself according to your actual situation.

0 Comments

Recommended Comments

There are no comments to display.

Guest
Add a comment...