stm32 Graduation Design MCU Family Weather Station System

1 Introduction

🔥 Hi, everyone, here is a series of articles about Dan Cheng's final project!

🔥 If you have any questions about Bizhu, you can ask the seniors!

Since the past two years, various schools have higher and higher requirements for graduation design, and the difficulty has become more and more difficult... Graduation design is time-consuming and energy-consuming, and even some topics take a long time even for professional teachers or master students, so Once you find a problem, you must prepare in advance to avoid being caught off guard later and rushing through the matter.

In order for everyone to pass the graduation project smoothly and with the least amount of energy, the seniors share high-quality graduation design projects. The new project to be shared today is

🚩 Home weather station system based on ESP32

🥇 Seniors here give a comprehensive score for a topic (full score for each item is 5 points)

  • Difficulty factor: 4 points
  • Workload: 4 points
  • Innovation point: 3 points

🧿 Topic selection guidance, project sharing:

https://blog.csdn.net/molodi/article/details/125933857


2 main components

In this project, seniors will use ESP32 to create a weather station.

The basic principle is to display the weather data on the webpage by reading the data from the DHT22 and BMP180 sensors, and then using the ESP32 to transmit the created webpage.

pin connection

The connection between DHT22 and ESP32 is as follows:

DHT22 pin 1 VCC —–>ESP32 / 3.3V;

DHT22 pin 2 DATA——>ESP32/D15;

DHT22 pin 4 GND —–>ESP32 /GND.

Then connect the BMP180 pressure sensor to the ESP32. The connection is as follows:

BMP180 Vin —–> ESP32 / 3.3V;

BMP180 GND —–> ESP32 /GND;

BMP180 SCL —–> ESP32 / pin 22; (The 22nd pin of ESP32 is SCL.)

BMP180 SDA —–> ESP32 / pin 21; (The 21st pin of ESP32 is SDA.)

Pins 22 and 21 of ESP32 are I2C communication interfaces.

ESP GPIO

3 Realize the effect

First, replace the Wi-Fi name and password information in the code with your own. Then upload the code and open the serial monitor. The serial monitor will display the IP address as shown in the picture below.


Enter this IP address into your browser. After entering the IP address, the web page will be displayed as shown in the figure below.

4 part implementation code

#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
}
}
}
}
}

🧿 Topic selection guidance, project sharing:

https://blog.csdn.net/molodi/article/details/125933857

Tags: Embedded system stm32 Single-Chip Microcomputer GraduationDesign

Posted by w4seem on Sat, 03 Dec 2022 21:31:11 +1030