Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Importance and Utility of Network Connectivity
Network connectivity is a crucial aspect in today's interconnected world. It allows devices to communicate with each other, enabling data transfer, remote control, and automation. With the help of Arduino, we can easily establish network connectivity and create projects that leverage the power of the internet.
Project: Arduino Web Server
In this project, we will create a simple web server using Arduino and Ethernet Shield. The objective is to control an LED remotely through a web interface. This project can be expanded to control other devices or gather data from sensors.
List of Components:
Examples:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
void setup() {
Ethernet.begin(mac);
}
void loop() {
// Your code here
}
Explanation:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 100);
EthernetServer server(80);
void setup() {
Ethernet.begin(mac, ip);
server.begin();
}
void loop() {
EthernetClient client = server.available();
if (client) {
// Handle client requests
}
}
Explanation:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 100);
EthernetServer server(80);
int ledPin = 2;
bool ledState = false;
void setup() {
Ethernet.begin(mac, ip);
server.begin();
pinMode(ledPin, OUTPUT);
}
void loop() {
EthernetClient client = server.available();
if (client) {
if (client.connected()) {
String request = client.readStringUntil('\r');
client.flush();
if (request.indexOf("/led/on") != -1) {
ledState = true;
digitalWrite(ledPin, HIGH);
} else if (request.indexOf("/led/off") != -1) {
ledState = false;
digitalWrite(ledPin, LOW);
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("");
client.println("<html><body>");
client.println("<h1>Arduino Web Server</h1>");
client.println("<p>LED is " + String(ledState ? "on" : "off") + "</p>");
client.println("<a href=\"/led/on\">Turn LED On</a><br/>");
client.println("<a href=\"/led/off\">Turn LED Off</a>");
client.println("</body></html>");
client.stop();
}
}
}
Explanation: