Show WiFi Connection Status with a Common Cathode LED (Red, Green)

Description: A Wemos Lolin D1 Mini Pro V2 shows its WiFi Connection Status with a Common Cathode LED that turns green when it’s connected to WiFi and turns red when it’s not.

Show WiFi Connection Status with a Common Cathode LED(Red, Green)

Notes: Make sure the baud rate is set to 9600 as shown in the Serial Monitor below.

Serial Monitor WiFi Connection Status with Common Cathode LED

Supplies:

1 – Breadboard 400 Points
1 – Wemos Lolin D1 Mini Pro V2
1 – Common Cathode LED (Red, Green)
1 – 220 Ohm Resistor

Arduino Code:

#include "ESP8266WiFi.h"

const char* ssid = "Network Name";    // Enter your WiFi SSID
const char* password = "password";  // Enter Password

#define green 4
#define red 5

void setup() {

  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  
  Serial.begin(9600);
  delay(10);

}

void loop() {

  if (WiFi.status() !=WL_CONNECTED) {
      WiFi.begin(ssid, password);
      digitalWrite(green, LOW);
      digitalWrite(red, HIGH);
      Serial.println(); 
      Serial.println();
     
  }

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

    Serial.println("Connecting to WiFi");

    while(WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print("*");
    }

    Serial.println();
    Serial.println("WiFi connection successful");
    Serial.print("IP Address: ");
    Serial.print(WiFi.localIP());
    
  }

  if (WiFi.status() == WL_CONNECTED) {
      digitalWrite(red, LOW);
      digitalWrite(green, HIGH);
  } 
}

Leave a Comment

54 − 49 =