【毕业设计项目】基于ESP32的家庭气象站系统 - stm32 物联网 嵌入式 单片机

201 篇文章 121 订阅
187 篇文章 118 订阅


1 简介

Hi,大家好,这里是丹成学长,今天向大家介绍一个学长做的单片机项目

基于ESP32的家庭气象站系统

大家可用于 课程设计 或 毕业设计


单片机-嵌入式毕设选题大全及项目分享:

https://blog.csdn.net/m0_71572576/article/details/125409052


2 主要器件

本项目学长将使用ESP32创建一个气象站。

基本原理是通过读取DHT22和BMP180传感器的数据,然后使用ESP32传输创建的网页上,在网页上显示气象数据。

在这里插入图片描述

引脚连接

DHT22与ESP32的连接如下:

DHT22 引脚1 VCC —–>ESP32 / 3.3V;

DHT22 引脚2 DATA—–>ESP32 / D15;

DHT22 引脚4 GND —–>ESP32 /GND.

然后将BMP180压力传感器连接到ESP32上。连接如下:

BMP180 Vin —–> ESP32 / 3.3V;

BMP180 GND —–> ESP32 /GND;

BMP180 SCL —–> ESP32 / pin 22;(ESP32的22号引脚是SCL.)

BMP180 SDA —–> ESP32 / pin 21;(ESP32的21号引脚是SDA.)

ESP32的22和21号引脚是I2C通信接口。

ESP GPIO

在这里插入图片描述

3 实现效果

首先,将代码中的Wi-Fi名称和密码信息替换为你自己的。然后上传代码并打开串口监视器。串口监视器将显示如下图所示的IP地址。

在这里插入图片描述
在浏览器中输入这个IP地址。输入IP地址后,网页会显示如下图所示。

在这里插入图片描述

4 部分实现代码

#include <WiFi.h>
#include <Wire.h>
#include <DHT.h>
#include <Adafruit_BMP085.h>
#define DHTPIN 15
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP085 bmp;
char pressure_value[4];
const char* wifi_name = "Asus_2.4G"; //Your Wifi name
const char* wifi_pass = "basemu.com"; //Your Wifi password
WiFiServer server(80); //Port 80
void setup()
{
Serial.begin(115200);
dht.begin();
bmp.begin();
// Let's connect to wifi network
Serial.print("Connecting to ");
Serial.print(wifi_name);
WiFi.begin(wifi_name, wifi_pass); //Connecting to wifi network
while (WiFi.status() != WL_CONNECTED) //Waiting for the responce of wifi network
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("Connection Successful");
Serial.print("IP address: ");
Serial.println(WiFi.localIP()); //Getting the IP address at which our webserver will be created
Serial.println("Type the above IP address into a browser search bar");
server.begin(); //Starting the server
}
void loop()
{
String pressure = String(bmp.readPressure());
// convert the reading to a char array
pressure.toCharArray(pressure_value, 4);
float hum = dht.readHumidity();
float temp = dht.readTemperature();
float fah = dht.readTemperature(true);
float heat_index = dht.computeHeatIndex(fah, hum);
float heat_indexC = dht.convertFtoC(heat_index);
WiFiClient client = server.available(); //Checking for incoming clients
if (client)
{
Serial.println("new client");
String currentLine = ""; //Storing the incoming data in the string
while (client.connected())
{
if (client.available()) //if there is some client data available
{
char c = client.read(); // read a byte
if (c == '\n') // check for newline character,
{
if (currentLine.length() == 0) //if line is blank it means its the end of the client HTTP request
{
client.print("<html><title> ESP32 Weather Station</title></html>");
client.print("<body bgcolor=\"#E6E6FA\"><h1 style=\"text-align: center; color: blue\"> ESP32 Weather Station </h1>");
client.print("<p style=\"text-align: center; font-size:150% \">Temperature in C: ");
client.print(temp);
client.print("<br/>Temperature in fah: ");
client.print(fah);
client.print("<br/>Humidity is: ");
client.print(hum);
client.print("<br/>Heat Index in C: ");
client.print(heat_indexC);
client.print("<br/>Heat Index in fah: ");
client.print(heat_index);
client.print("<br/>Pressure is: ");
client.print(pressure_value);
client.print("hpa");
client.print("</p></body>");
break; // break out of the while loop:
}
else
{ // if you got a newline, then clear currentLine:
currentLine = "";
}
}
else if (c != '\r')
{ // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
}
}

单片机-嵌入式毕设选题大全及项目分享:

https://blog.csdn.net/m0_71572576/article/details/125409052


5 最后

  • 12
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于单片机STM32和ESP8266的智能家居安防OneNet物联网设计项目的开发环境可以包括以下内容: 1. 开发工具:选择适合STM32和ESP8266的开发工具,如Keil MDK、IAR Embedded Workbench等。这些工具提供了编译、调试、烧录等功能,方便进行嵌入式软件的开发和调试。 2. 编程语言:常用的嵌入式开发语言包括C和C++,可以根据开发团队的熟悉程度和项目需求选择合适的编程语言。 3. 开发板:为了简化开发过程,可以选择基于STM32和ESP8266的开发板,如ST-Link、NodeMCU等。这些开发板提供了丰富的接口和资源,方便进行硬件的连接和调试。 4. 软件库:STM32和ESP8266都有丰富的软件库可供使用,可以根据项目需求选择合适的库。例如,对于STM32,可以使用STM32Cube HAL库来访问硬件资源;对于ESP8266,可以使用ESP8266非官方库或者AT指令集进行开发。 5. 物联网平台:OneNet是一个常用的物联网平台,提供了数据接收、存储、分析等功能。在项目开发中,需要注册并创建设备和数据流,获取相应的API密钥,以便与OneNet平台进行数据交互。 6. 调试工具:为了方便调试和排查问题,可以使用调试工具,如串口调试助手、逻辑分析仪等。这些工具可以帮助检查通信数据、观察信号波形等,提高调试效率。 7. 物联网协议:根据项目需求和OneNet平台支持的协议,选择合适的物联网协议进行数据交互,如MQTT、HTTP等。 除了以上开发环境,还需要合适的硬件连接线缆、电源供应和测试设备等来支持开发和测试工作。 需要注意的是,具体的开发环境可能会根据项目需求和开发团队的偏好有所差异,以上是一个一般的开发环境示例。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值