iot 4
iot 4
Practical - 4
Aim: Building a Web Server to Control LED Brightness with a Slider using
NodeMCU (ESP8266)
Theory:
The slider’s value will be sent to NodeMCU, which will adjust the
PWM output accordingly.
1. Hardware Connections
2. Software Setup
Ensure the correct Board (NodeMCU 1.0 ESP-12E) and Port are selected
in Arduino IDE.
Once uploaded, open the Serial Monitor to check the IP address assigned
to NodeMCU.
Use this IP address in a browser to access the LED control web interface.
.
Code :
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
// WiFi credentials
ESP8266WebServer server(80);
void handleRoot() {
<head>\
<script>\
function updateBrightness(value) {\
xhttp.send();\
}\
</script>\
</head>\
<body>\
</body>\
</html>";
void handleBrightness() {
if (server.hasArg("value")) {
analogWrite(LED_PIN, brightness);
} else {
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
WiFi.softAP(ssid, password);
Serial.println(WiFi.softAPIP());
server.on("/", handleRoot);
server.on("/setBrightness", handleBrightness);
server.begin();
void loop() {
server.handleClient();
Conclusion:
2. The project showcased the integration of Soft AP mode, web server hosting, and
PWM control.