Internet Up/ Down LED Alert with Arduino Uno with WiFi

This project shows you you to create a visual alert to notify you if your internet service has gone down.

Functional Parts in the Project:

#include <WiFiNINA.h>

#define googleOnlineLED 9
#define googleOfflineLED 10

char ssid[] = "test";
char pass[] = "";

int status = WL_IDLE_STATUS;

char google[] = "google.com";

WiFiClient client;

void setup() {
  pinMode(googleOnlineLED, OUTPUT);
  pinMode(googleOfflineLED, OUTPUT);

  Serial.begin(9600);

  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    delay(10000);
  }

  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  IPAddress ip = WiFi.localIP();
  IPAddress gateway = WiFi.gatewayIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  Serial.print("Default Gateway: ");
  Serial.println(gateway);
}

void loop() {

  if (client.connect(google, 80)) {
    Serial.print("Google is ONLINE at:  ");
    Serial.println(client.remoteIP());
    digitalWrite(googleOnlineLED, HIGH);
    digitalWrite(googleOfflineLED, LOW);
  }
  else {
    Serial.println("Google is OFFLINE");
    digitalWrite(googleOnlineLED, LOW);
    digitalWrite(googleOfflineLED, HIGH);
  }
  
  delay(2000);
}

Be the first to comment

Leave a Reply