Loading...
Vietnam Geography App
Loading...
Vietnam Geography App
Kết nối robot với Internet để điều khiển từ xa và thu thập dữ liệu
// Robot IoT với ESP32 và Blynk
#define BLYNK_TEMPLATE_ID "YourTemplateID"
#define BLYNK_DEVICE_NAME "Robot IoT"
#define BLYNK_AUTH_TOKEN "YourAuthToken"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
char ssid[] = "YourWiFiName";
char pass[] = "YourWiFiPassword";
void setup() {
Serial.begin(115200);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// Khởi tạo pins cho motor
pinMode(motorA1, OUTPUT);
pinMode(motorA2, OUTPUT);
pinMode(motorB1, OUTPUT);
pinMode(motorB2, OUTPUT);
}
// Điều khiển robot từ app
BLYNK_WRITE(V0) { // Nút tiến
if (param.asInt() == 1) {
moveForward();
} else {
stopMotors();
}
}
BLYNK_WRITE(V1) { // Nút lùi
if (param.asInt() == 1) {
moveBackward();
} else {
stopMotors();
}
}
void loop() {
Blynk.run();
// Gửi dữ liệu cảm biến lên app
float temperature = readTemperature();
Blynk.virtualWrite(V2, temperature);
delay(1000);
}
Kết nối ESP32 với mạng WiFi và hiển thị trạng thái
#include <WiFi.h>
const char* ssid = "YourWiFiName";
const char* password = "YourPassword";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Đang kết nối WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected!");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
// Kiểm tra kết nối
if (WiFi.status() == WL_CONNECTED) {
Serial.println("WiFi OK");
} else {
Serial.println("WiFi disconnected");
}
delay(5000);
}
Tạo ứng dụng web đơn giản để điều khiển robot
#include <WiFi.h>
#include <WebServer.h>
WebServer server(80);
void handleRoot() {
String html = "<html><body>";
html += "<h1>Robot Control</h1>";
html += "<button onclick="location.href='/forward'">Forward</button><br>";
html += "<button onclick="location.href='/backward'">Backward</button><br>";
html += "<button onclick="location.href='/left'">Left</button>";
html += "<button onclick="location.href='/right'">Right</button><br>";
html += "<button onclick="location.href='/stop'">Stop</button>";
html += "</body></html>";
server.send(200, "text/html", html);
}
void handleForward() {
moveForward();
server.send(200, "text/plain", "Moving Forward");
}
void setup() {
WiFi.begin(ssid, password);
server.on("/", handleRoot);
server.on("/forward", handleForward);
server.begin();
}
void loop() {
server.handleClient();
}
Robot giám sát từ xa
Hệ thống nhà thông minh
Robot giao hàng tự động
Thiết bị IoT nông nghiệp
Robot an ninh thông minh