KEMBAR78
Led Control Webpage | PDF
0% found this document useful (0 votes)
5 views3 pages

Led Control Webpage

This document contains an Arduino sketch for controlling an LED using an ESP8266 WiFi module. It connects to a specified WiFi network and sets up a web server that allows users to turn the LED on or off via HTTP requests. The server responds with an HTML page for user interaction.

Uploaded by

nitusp156789
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Led Control Webpage

This document contains an Arduino sketch for controlling an LED using an ESP8266 WiFi module. It connects to a specified WiFi network and sets up a web server that allows users to turn the LED on or off via HTTP requests. The server responds with an HTML page for user interaction.

Uploaded by

nitusp156789
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <ESP8266WiFi.

h>

// WiFi credentials

const char* ssid = "your wifi id";

const char* password = "your wifi password";

// Set LED pin

const int ledPin = D1;

WiFiServer server(80);

void setup() {

Serial.begin(115200);

pinMode(ledPin, OUTPUT);

digitalWrite(ledPin, LOW);

// Connect to Wi-Fi

Serial.println();

Serial.print("Connecting to ");

Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(1000);

Serial.print(".");

Serial.println("");

Serial.println("WiFi connected.");

Serial.print("IP Address: ");

Serial.println(WiFi.localIP());

// Start server
server.begin();

void loop() {

WiFiClient client = server.available();

if (!client) {

return;

// Wait until client sends data

while (!client.available()) {

delay(1);

String request = client.readStringUntil('\r');

client.flush();

// Control LED based on request

if (request.indexOf("/LED=ON") != -1) {

digitalWrite(ledPin, HIGH);

if (request.indexOf("/LED=OFF") != -1) {

digitalWrite(ledPin, LOW);

// Send HTML page

client.println("HTTP/1.1 200 OK");

client.println("Content-Type: text/html");

client.println("");

client.println("<!DOCTYPE HTML>");

client.println("<html>");
client.println("<h1>IoT LED Control</h1>");

client.println("<p><a href=\"/LED=ON\"><button>LED ON</button></a></p>");

client.println("<p><a href=\"/LED=OFF\"><button>LED OFF</button></a></p>");

client.println("</html>");

You might also like