Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
The Importance and Utility of Wi-Fi Module
The Wi-Fi module is an essential component in the field of electronics and Internet of Things (IoT). It allows Arduino boards to connect to the internet wirelessly, enabling a wide range of applications such as remote monitoring, home automation, and data logging. With the Wi-Fi module, Arduino becomes capable of accessing web services, sending and receiving data, and interacting with other devices over the internet.
Project: Arduino Weather Station
In this example project, we will create an Arduino Weather Station that collects temperature and humidity data from a sensor and sends it to an online platform for monitoring. The goal is to demonstrate how the Wi-Fi module can be used to connect Arduino to the internet and transmit data in real-time.
List of Components:
Examples:
#include <ESP8266WiFi.h>
const char ssid = "YourNetworkSSID"; const char password = "YourNetworkPassword";
void setup() { Serial.begin(115200); WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi..."); }
Serial.println("Connected to WiFi!"); }
void loop() { // Your code here }
2. Reading data from the DHT11 sensor:
```arduino
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
dht.begin();
}
void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %");
delay(2000);
}
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
const char ssid = "YourNetworkSSID"; const char password = "YourNetworkPassword"; const char* server = "api.example.com";
void setup() { Serial.begin(115200); WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi..."); }
Serial.println("Connected to WiFi!"); }
void loop() { float temperature = getTemperature(); float humidity = getHumidity();
if (WiFi.status() == WL_CONNECTED) { WiFiClient client;
if (client.connect(server, 80)) {
String url = "/data?temperature=" + String(temperature) + "&humidity=" + String(humidity);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + server + "\r\n" +
"Connection: close\r\n\r\n");
while (client.connected()) {
if (client.available()) {
String line = client.readStringUntil('\r');
Serial.println(line);
}
}
client.stop();
}
}
delay(5000); }