当前位置:网站首页>Esp32-cam high cost performance temperature and humidity monitoring system
Esp32-cam high cost performance temperature and humidity monitoring system
2022-06-23 10:59:00 【daodanjishui】
ESP32-CAM ArduinoIDE Development series article catalog
Chapter one :ESP32-CAM High cost performance WIFI Quick start tutorial of image transmission scheme
Second articles :ESP32-CAM The first wireless lighting program
Third articles :ESP32-CAM Design and implementation of intelligent gateway
Fourth articles :ESP32-CAM Create a hot spot composition and style DNS The server
Chapter five :ESP32-CAM High cost performance temperature and humidity monitoring system
List of articles
Preface
daodanjishui The core original technology of the Internet of things ESP32 Arduino IDE Development of embedded web server setup 、http Request sending, receiving and parsing 、 Single chip microcomputer IO Oral reading and writing operation 、AJAX technology 、 Concurrent server technology 、DNS Technology and sensors DHT11 Integrated composition :ESP32-CAM High cost performance temperature and humidity monitoring system .
One 、ESP32-CAM What is a cost-effective temperature and humidity monitoring system ?
daodanjishui The project in the previous article :ESP32-CAM Create a hot spot composition and style DNS Server introduces embedded server LAN in detail DNS Application , At that time, the main page of the server could only be queried ESP32-CAM On board LED Lamp status and control LED Light on and off , But there is no function to query environment parameters , It does not really reflect the essence of the Internet of things technology , This is also the deficiency of the previous article .
daodanjishui In the project of this article , Keep the functions of the previous article , Will join DHT11 Temperature and humidity sensor module , And add the sensor driver , This module has only one data interface data, So only ESP32-CAM One of the GPIO14, Therefore, it is easy to transform the previous project into a temperature and humidity monitoring system . The function of the system is to input in the window of the form :data Click again cmd Button to submit the command ,ESP32 The server will query the temperature and humidity data and return to the server home page , You can query the environment parameters , Displayed in the feedback message , Buyers who are not clear about the functions of the previous article can go to the previous article ( Fourth articles ) Introduction to . The hardware effect is shown in the figure below :

The running effect of the program is as follows ( The red font is the data collected by the sensor ):
DHT11 At that time, I found a driver on the Internet to collect data , The effect of the test is not very good , It takes several times to get the data , In fact, it's almost enough , To be accurate, you need to modify the driver carefully , I found a more reliable one later DHT The driver , Share it here , Some common libraries can be found in :http://www.taichi-maker.com/homepage/download/#library-download
Download for free .
Two 、 Software development process
1. Import and stock in dht11.h and dht11.cpp
dht11.h The code is as follows :
#ifndef dht11_h
#define dht11_h
#if defined(ARDUINO) && (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#define DHT11LIB_VERSION "0.4.1"
#define DHTLIB_OK 0
#define DHTLIB_ERROR_CHECKSUM -1
#define DHTLIB_ERROR_TIMEOUT -2
class dht11
{
public:
int read(int pin);
int humidity;
int temperature;
};
#endif
//
// END OF FILE
//
dht11.c The code is as follows :
//
// FILE: dht11.cpp
// VERSION: 0.4.1
// PURPOSE: DHT11 Temperature & Humidity Sensor library for Arduino
// LICENSE: GPL v3 (http://www.gnu.org/licenses/gpl.html)
//
// DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf
//
// HISTORY:
// George Hadjikyriacou - Original version (??)
// Mod by SimKard - Version 0.2 (24/11/2010)
// Mod by Rob Tillaart - Version 0.3 (28/03/2011)
// + added comments
// + removed all non DHT11 specific code
// + added references
// Mod by Rob Tillaart - Version 0.4 (17/03/2012)
// + added 1.0 support
// Mod by Rob Tillaart - Version 0.4.1 (19/05/2012)
// + added error codes
//
#include "dht11.h"
// Return values:
// DHTLIB_OK
// DHTLIB_ERROR_CHECKSUM
// DHTLIB_ERROR_TIMEOUT
int dht11::read(int pin)
{
// BUFFER TO RECEIVE
uint8_t bits[5];
uint8_t cnt = 7;
uint8_t idx = 0;
// EMPTY BUFFER
for (int i=0; i< 5; i++) bits[i] = 0;
// REQUEST SAMPLE
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
delay(18);
digitalWrite(pin, HIGH);
delayMicroseconds(40);
pinMode(pin, INPUT);
// ACKNOWLEDGE or TIMEOUT
unsigned int loopCnt = 10000;
while(digitalRead(pin) == LOW)
if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
loopCnt = 10000;
while(digitalRead(pin) == HIGH)
if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
// READ OUTPUT - 40 BITS => 5 BYTES or TIMEOUT
for (int i=0; i<40; i++)
{
loopCnt = 10000;
while(digitalRead(pin) == LOW)
if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
unsigned long t = micros();
loopCnt = 10000;
while(digitalRead(pin) == HIGH)
if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT;
if ((micros() - t) > 40) bits[idx] |= (1 << cnt);
if (cnt == 0) // next byte?
{
cnt = 7; // restart at MSB
idx++; // next byte!
}
else cnt--;
}
// WRITE TO RIGHT VARS
// as bits[1] and bits[3] are allways zero they are omitted in formulas.
humidity = bits[0];
temperature = bits[2];
uint8_t sum = bits[0] + bits[2];
if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM;
return DHTLIB_OK;
}
//
// END OF FILE
//
2. Read in the data
Arduino The sensor drive code is as follows :
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
} // The Celsius temperature is converted to the Fahrenheit temperature
double Kelvin(double celsius)
{
return celsius + 273.15;
} // Centigrade temperature is converted to Kelvin temperature
// the dew point ( At this temperature , The air saturates and produces dew drops )
// Reference resources : http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
double A0= 373.15/(273.15 + celsius);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * humidity;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}
// Calculate dew point quickly , The velocity is 5 times dewPoint()
// Reference resources : http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
double Td = (b * temp) / (a - temp);
return Td;
}
#include <dht11.h>
dht11 DHT11;
#define DHT11PIN 2
void setup()
{
Serial.begin(9600);
Serial.println("DHT11 TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT11LIB_VERSION);
Serial.println();
}
void loop()
{
Serial.println("\n");
int chk = DHT11.read(DHT11PIN);
Serial.print("Read sensor: ");
switch (chk)
{
case DHTLIB_OK:
Serial.println("OK");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println("Checksum error");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.println("Time out error");
break;
default:
Serial.println("Unknown error");
break;
}
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);
Serial.print("Temperature (oC): ");
Serial.println((float)DHT11.temperature, 2);
Serial.print("Temperature (oF): ");
Serial.println(Fahrenheit(DHT11.temperature), 2);
Serial.print("Temperature (K): ");
Serial.println(Kelvin(DHT11.temperature), 2);
Serial.print("Dew Point (oC): ");
Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));
Serial.print("Dew PointFast (oC): ");
Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));
delay(2000);
}
3. Porting to Engineering
By adding this code to the previous project, you can use the web page to trigger the query of environment parameters .
if(!strcmp(value_buf, "data")){
// Check the temperature and humidity
dht11 DHT11;
if (DHTLIB_OK == DHT11.read(14))// I use it GPIO14
{
Serial.print("HUMID = ");
Serial.print(DHT11.humidity);
Serial.println(" %RH");
Serial.print("TMEP = ");
Serial.print(DHT11.temperature);
Serial.println("^C");
String T=DHT11.temperature+"";
String H=DHT11.humidity+"";
return request->send(200, "text/plain", "temperature="+T+" humidity="+H);// Return temperature and humidity
}else return request->send(200, "text/plain", "no temperature and humidity");// Return temperature and humidity
}
summary

daodanjishui This issue has two more files than the source code of the previous issue , These two documents are arduino Of dht11 library , It is also difficult to find on the Internet , There are also many problems in the debugging process , Finally, the function of temperature and humidity query is realized , I also said in the last issue , This sister article has a high degree of code expansion , Improve the function of the system at will , So now the code of the sister chapter is transformed into a temperature and humidity monitoring system , Readers want to learn how to expand the system functions , Consider the similarities and differences between the two sets of code , Most people will make many mistakes when adding library functions , It is not so easy to succeed , Compared these two sets of codes , New sensor code will be added , There must be gains !!!
Code transfer address :https://www.cirmall.com/circuit/19388/
Click jump to download
边栏推荐
- NOI OJ 1.2 10:Hello, World! Size of C language
- Torch weight to mindspore
- Build a QQ robot to wake up your girlfriend
- "Internet +" contest topic hot docking | I figure to understand 38 propositions of Baidu
- 最简单DIY串口蓝牙硬件实现方案
- 韦东山设备信息查询例程学习
- Noi OJ 1.3 13: reverse output of a three digit C language
- 新派科技美学、原生物联网操作系统重塑全屋智能
- UWA new | real person real machine test new overseas model zone
- Noi OJ 1.3 17: calculating triangle area C language
猜你喜欢

Solve the problem of invalid audio autoplay

TTY drive frame

STM32F103ZET6单片机双串口互发程序设计与实现

社招腾讯高P(高级产品经理)的面试手册

UWA上新|真人真机测试新增海外机型专区

当 Pandas 遇见 SQL,一个强大的工具库诞生了

How to write a literature review? What should I do if I don't have a clue?

Win10 Microsoft input method (Microsoft Pinyin) does not display the word selection column (unable to select words) solution

六张图详解LinkedList 源码解析

MAUI使用Masa blazor组件库
随机推荐
Noi OJ 1.3 05: floating point numeric C language for calculating fractions
Solve the problem that Preview PDF cannot be downloaded
"Internet +" contest topic hot docking | I figure to understand 38 propositions of Baidu
AI芯片技术-2022年
长安LUMIN是否有能力成为微电市场的破局产品
NOI OJ 1.2 整数数据类型存储空间大小
Noi OJ 1.2 conversion between integer and Boolean C language
UART的奇偶校验
File has not been synchronized when NFS is mounted
NOI OJ 1.2 10:Hello, World! Size of C language
最简单DIY串口蓝牙硬件实现方案
连番承压之后,苹果或将大幅提高iPhone14的售价
圖片存儲--引用
Interview Manual of social recruitment Tencent high P (Senior Product Manager)
Similarities and differences between SPI and IIC
[golden section] and [Fibonacci series]
Is the online security of securities account opening high
最简单DIY基于STM32的远程控制电脑系统②(无线遥杆+按键控制)
Large homework collection
Data structures and differences between MySQL InnoDB engine and MyISAM