Loading...
Vietnam Geography App
Loading...
Vietnam Geography App
Kết nối Arduino với thế giới! Học cách truyền nhận dữ liệu qua Serial, I2C, SPI, xây dựng web server, gửi dữ liệu lên cloud và điều khiển thiết bị từ xa qua WiFi/Bluetooth. Mở rộng khả năng sáng tạo không giới hạn.
/*
ESP32 Web Server với Sensor Data
Tạo web interface để hiển thị dữ liệu sensors
*/
#include <WiFi.h>
#include <WebServer.h>
#include <DHT.h>
const char* ssid = "YourWiFiName";
const char* password = "YourPassword";
#define DHT_PIN 4
#define DHT_TYPE DHT22
DHT dht(DHT_PIN, DHT_TYPE);
WebServer server(80);
void setup() {
Serial.begin(115200);
dht.begin();
// Kết nối WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("WiFi connected!");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
// Định nghĩa routes
server.on("/", handleRoot);
server.on("/data", handleData);
server.begin();
Serial.println("Web server started");
}
void handleRoot() {
String html = R"(
<!DOCTYPE html>
<html>
<head>
<title>Arduino Sensor Dashboard</title>
<meta http-equiv='refresh' content='5'>
</head>
<body>
<h1>Sensor Monitoring System</h1>
<div id='data'></div>
<script>
fetch('/data')
.then(response => response.json())
.then(data => {
document.getElementById('data').innerHTML =
'<p>Temperature: ' + data.temperature + '°C</p>' +
'<p>Humidity: ' + data.humidity + '%</p>';
});
</script>
</body>
</html>
)";
server.send(200, "text/html", html);
}
void handleData() {
float temp = dht.readTemperature();
float hum = dht.readHumidity();
String json = "{";
json += "\"temperature\":" + String(temp) + ",";
json += "\"humidity\":" + String(hum);
json += "}";
server.send(200, "application/json", json);
}
void loop() {
server.handleClient();
delay(10);
}
Sử dụng I2C để hiển thị sensor data trên OLED display
Tạo web dashboard có thể điều khiển từ mobile
IoT device monitoring và control
Remote sensor data collection
Home automation systems
Industrial monitoring solutions
Agricultural automation systems