Hari
Published © Apache-2.0

Control an LED from a Web Dashboard

Control a physical LED wirelessly from a KiwisIoT web dashboard using a NodeMCU ESP8266.

BeginnerShowcase (no instructions)1 hour27
Control an LED from a Web Dashboard

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
LED (generic)
LED (generic)
×1
Resistor 221 ohm
Resistor 221 ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1

Software apps and online services

KiwisIoT

Hand tools and fabrication machines

Arduino IDE
Serial Monitor

Story

Read more

Schematics

NodeMCU ESP8266 LED Wiring Diagram

File missing, please reupload.

NodeMCU ESP8266 LED Wiring Diagram

Code

KiwisIoT_LED_Control.ino

C/C++
/*
 * Project: Control an LED From a Web Dashboard
 * Board: NodeMCU ESP8266
 * Platform: KiwisIoT
 */

#include <KiwisIoT.h>

// Wi-Fi and KiwisIoT configuration
const char* ssid  = "MY_WIFI_SSID";
const char* pass  = "MY_WIFI_PASSWORD";
const char* topic = "MY_KIWISIOT_TOPIC";

// Create KiwisIoT object
KiwisIoT kiwisiot(ssid, pass, topic);

// External LED connected to NodeMCU D2
#define LED_PIN D2


// --------------------------------------------------
// Receive commands from KiwisIoT
// --------------------------------------------------
void receiveCommand(String channel, String value)
{
  Serial.print("Channel: ");
  Serial.print(channel);

  Serial.print("  Value: ");
  Serial.println(value);

  // Use Channel 1 to control the LED
  if (channel == "1")
  {
    // Turn LED ON
    if (value == "1")
    {
      digitalWrite(LED_PIN, HIGH);
      Serial.println("LED -> ON");
    }

    // Turn LED OFF
    else if (value == "0")
    {
      digitalWrite(LED_PIN, LOW);
      Serial.println("LED -> OFF");
    }
  }
}


// --------------------------------------------------
// Setup
// --------------------------------------------------
void setup()
{
  Serial.begin(9600);

  // Configure LED pin
  pinMode(LED_PIN, OUTPUT);

  // Start with LED OFF
  digitalWrite(LED_PIN, LOW);

  // Start KiwisIoT
  kiwisiot.begin();

  // Register command receiver
  kiwisiot.onReceive(receiveCommand);
}


// --------------------------------------------------
// Main Loop
// --------------------------------------------------
void loop()
{
  // Keep KiwisIoT communication running
  kiwisiot.run();
}

Credits

Hari
14 projects • 1 follower

Comments