Control an LED From a Web Dashboard Using NodeMCU ESP8266 and KiwisIoT
by harispidy07 in Circuits > Microcontrollers
60 Views, 2 Favorites, 0 Comments
I wanted to build a simple IoT project that could connect a physical electronic component to a web dashboard. For this project, I used a NodeMCU ESP8266, KiwisIoT, Arduino IDE, Wi-Fi and an external LED.
The idea was simple: I wanted to control a real LED by clicking a toggle on a web dashboard. When I turned the toggle ON, the LED should turn ON. When I turned it OFF, the LED should turn OFF.
This project helped me understand how a web interface, wireless communication, microcontroller programming and physical hardware can work together as one IoT system.
Supplies
HARDWAARE COMPONENT
NodeMCU ESP8266
External LED
Resistor
Jumper wire
USB cable
Computer and Wi-Fi connection
Software / Tools
Arduino IDE
ESP8266 board support
KiwisIoT Arduino library
KiwisIoT web dashboard
Arduino Serial Monitor
Connecting the LED to the NodeMCU
I started by connecting an external LED to the NodeMCU ESP8266. I used the D2 GPIO pin as the output pin for the LED. I connected the LED through a resistor and connected the other side to GND.
LED anode (+) → resistor → D2
LED cathode (-) → GND
NodeMCU → USB connection to my computer
Creating the KiwisIoT Dashboard
After preparing the hardware, I created my control dashboard in KiwisIoT. I added a Toggle widget and configured it to use Channel 1.
The Toggle works as a virtual ON/OFF switch. When I turn it ON, the dashboard sends value 1. When I turn it OFF, the dashboard sends value 0.
Preparing Arduino IDE
Next, I programmed the NodeMCU using Arduino IDE. I connected the board through USB, selected the ESP8266 board and the correct COM port, and made sure the KiwisIoT library was available.
Connect the NodeMCU to the computer using USB.
Open Arduino IDE.
Select the correct ESP8266 board.
Select the correct COM port.
Install/include the KiwisIoT library.
Enter the Wi-Fi and KiwisIoT topic information.
Writing the NodeMCU Program
I then wrote the program that connects the ESP8266 to KiwisIoT and listens for commands from the dashboard.
include <KiwisIoT.h>
const char* ssid = "YOUR_WIFI_SSID";
const char* pass = "YOUR_WIFI_PASSWORD";
const char* topic = "YOUR_TOPIC";
KiwisIoT kiwisiot(ssid, pass, topic);
#define LED_PIN D2
void receiveCommand(String channel, String value) {
Serial.print("Channel: ");
Serial.print(channel);
Serial.print(" Value: ");
Serial.println(value);
if (channel == "1") {
if (value == "1") {
digitalWrite(LED_PIN, HIGH);
Serial.println("LED -> ON");
}
else if (value == "0") {
digitalWrite(LED_PIN, LOW);
Serial.println("LED -> OFF");
}
}
}
void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
kiwisiot.begin();
kiwisiot.onReceive(receiveCommand);
}
void loop() {
kiwisiot.run();
}
Understanding the Important Parts of the Code
Selecting D2
#define LED_PIN D2
This tells the ESP8266 that the external LED is connected to the D2 GPIO pin.
Receiving the Dashboard Command
void receiveCommand(String channel, String value)
This callback function receives the channel and value sent by the KiwisIoT dashboard. I check the channel first so that only Channel 1 controls my LED.
Turning the LED ON
if (value == "1") {
digitalWrite(LED_PIN, HIGH);
}
When the received value is 1, the NodeMCU sets D2 HIGH and the LED turns ON.
Turning the LED OFF
else if (value == "0") {
digitalWrite(LED_PIN, LOW);
}
When the received value is 0, the NodeMCU sets D2 LOW and the LED turns OFF.
Uploading the Program
After completing the code, I uploaded the program to the NodeMCU. I checked the board selection, COM port and USB connection before starting the upload.
Verify the code.
Select the NodeMCU/ESP8266 board.
Select the correct COM port.
Upload the program.
Wait for the upload to complete successfully.
Open the Serial Monitor.
Checking the Serial Monitor
The Serial Monitor was useful for checking whether the NodeMCU was receiving commands from the dashboard. I used 9600 baud.
Channel: 1 Value: 1
LED -> ON
Channel: 1 Value: 0
LED -> OFF
Testing the LED
Now I tested the complete system. I opened the KiwisIoT dashboard and changed the Toggle several times.
When I switched the Toggle ON:
Toggle ON → Channel 1 → Value 1 → NodeMCU → D2 HIGH → LED ON
When I switched the Toggle OFF:
Toggle OFF → Channel 1 → Value 0 → NodeMCU → D2 LOW → LED OFF
The physical LED followed the dashboard state correctly.
My Final Working Result
This was the most satisfying part of the project. I was able to control the physical LED from the KiwisIoT web dashboard. A simple click on the dashboard caused a real hardware output to change.
Test Results
Test Action Result
1 Toggle OFF LED OFF
2 Toggle ON LED ON
3 Toggle repeatedly LED followed the toggle
4 Check Serial Monitor Commands displayed
Troubleshooting
LED does not turn ON
Check the LED polarity.
Check the resistor connection.
Check the D2 connection.
Check the GND connection.
Check that the dashboard toggle is sending the expected value.
Dashboard command is not received
Check the Wi-Fi connection.
Check the KiwisIoT topic.
Check that the dashboard uses Channel 1.
Check the KiwisIoT library.
Check the Serial Monitor.
Upload fails
Check the ESP8266 board selection.
Check the COM port.
Check the USB cable.
Check the ESP8266 board package installation.
What I Learned
This project gave me practical experience with several important IoT concepts.
How an ESP8266 connects to Wi-Fi.
How a web dashboard can communicate with hardware.
How callback functions can process incoming commands.
How channel IDs can be used for device control.
How GPIO HIGH and LOW control an LED.
How to use the Serial Monitor for debugging.
How software and hardware can be tested together.
How an end-to-end IoT system is assembled.
Conclusion
This project started with a simple goal: control a physical LED from a web dashboard. I connected the LED to the NodeMCU ESP8266, programmed the board using Arduino IDE, connected it to KiwisIoT through Wi-Fi, created a Toggle widget, and tested the complete system.
The final result was exactly what I wanted: I could click a button on the web dashboard and see the physical LED respond.
What I liked most about this project was seeing the connection between software and hardware. A simple web action was converted into a command, received by the ESP8266, and finally used to control a real electronic component.
Even though this is a small project, it gave me a strong practical foundation for exploring more advanced IoT projects such as smart lighting, monitoring systems, remote control and automation.