simonhyde88
Published © LGPL

WiFi ESP8226 D1 LED Painting

This project maps the signal strength of a known WIFI SSID to light up an LED strip.

IntermediateFull instructions provided1,243
WiFi ESP8226 D1 LED Painting

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
×1
WS2811b
×1
Resistor 221 ohm
Resistor 221 ohm
×1
Capacitor 10 µF
Capacitor 10 µF
×1
USB battery pack
×1
Adafruit UBEC DC/DC Step down
×1

Story

Read more

Schematics

Wiring laout

Wiring the WS211b to the WeMos D1

Code

WIFI LED sketch

C/C++
/*
    This sketch demonstrates how to scan WiFi networks and light up a strip of LEDs
*/
#define FASTLED_ESP8266_D1_PIN_ORDER
#include "ESP8266WiFi.h"
#include "FastLED.h"
String ssid_look = "Nhat Binh";
//String ssid_look = "DANANG WIFI";
String look;
//Define vartiables for LED calculations
long value;
long rssi;
long numLedsToLight;
// FastLED definitions
#define NUM_LEDS 99
#define DATA_PIN 4
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup() {
  Serial.begin(115200);
  //Set the strip up
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
   FastLED.setBrightness(100);
  FastLED.clear();
  // Set WiFi to station mode and disconnect from an AP if it was previously connected
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);
  Serial.println("Setup done");
}

void loop() {
  Serial.println("scan start");

  // WiFi.scanNetworks will return the number of networks found
  int n = WiFi.scanNetworks();
  Serial.println("scan done");
  if (n == 0) {
    Serial.println("no networks found");
    //Fill all red if no wifi found
    // First, clear the existing led values
    FastLED.clear();
    fill_solid( leds, NUM_LEDS, CRGB::White);

  } else {
    Serial.print(n);
    Serial.println(" networks found");
    for (int i = 0; i < n; ++i) {
      // Print SSID and RSSI for each network found
      Serial.printf("%d: %s, Ch:%d (%ddBm) %s\n", i + 1, WiFi.SSID(i).c_str(), WiFi.channel(i), WiFi.RSSI(i), WiFi.encryptionType(i) == ENC_TYPE_NONE ? "open" : "");
      look = WiFi.SSID(i);
      if (look == ssid_look) {
        //Put the signal strength of the SSID looked for in rssi
        rssi = WiFi.RSSI(i);
        Serial.print("Wifi scanned SSID iss...");
        Serial.println(look);
        break;
      }
    }
  }
  //Serial.println("Here");
  //Do all the light stuff where green is the strength and red fills the rest of the LEDS
  if (look == ssid_look) {
    // Calculate the number of Grren LEDs to light up
    int   value = 2 * (rssi + 100);
    int numLedsToLight = map(value, 0, 100, 0, NUM_LEDS);
    //Serial.println(numLedsToLight);
    // First, clear the existing led values
    FastLED.clear();
    //Turn on the scnnned channel value as Green LEDs
    for (int led = 0; led < numLedsToLight; led++) {
      //Serial.println(numLedsToLight);
      leds[led] = CRGB::Green;
      //Serial.print(led);
    }
    // Turn on the remaining LEDs as Red
    for (int led = numLedsToLight; led < NUM_LEDS; led++) {
      leds[led] = CRGB::Red;
    }
    Serial.print(numLedsToLight);
    Serial.println(" LEDS will be shown");
  } else {
    Serial.print("No SSID match");
    Serial.println("");
    fill_solid( leds, NUM_LEDS, CRGB::White);
  }

  FastLED.show();
  // Wait a bit before scanning again
  delay(500);
  //Delete all the WIFI scanned info
  WiFi.scanDelete();
  numLedsToLight = 0;
  Serial.println("--Clear values--");
}

Added WiFi manager

C/C++
Use this to manage the wifi SSID that your looking at...you willl need to know both the SSID and the password for it.
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#include <Adafruit_NeoPixel.h>
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager
long value;
int numLedsToLight;
// NeoPixel  definitions
#define PIN     0
#define N_LEDS 98

Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);
//Define colours
uint32_t white = strip.Color(255, 255, 255);
uint32_t red = strip.Color(255, 0, 0);
uint32_t green = strip.Color(0, 255, 0);

void setup() {
    // put your setup code here, to run once:
    Serial.begin(115200);
 strip.begin();
    //WiFiManager
    //Local intialization. Once its business is done, there is no need to keep it around
    WiFiManager wifiManager;
    //reset saved settings
    //wifiManager.resetSettings();
    
    //set custom ip for portal
    //wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));

    //fetches ssid and pass from eeprom and tries to connect
    //if it does not connect it starts an access point with the specified name
    //here  "AutoConnectAP"
    //and goes into a blocking loop awaiting configuration
    wifiManager.autoConnect("AutoConnectAP");
    //or use this for auto generated name ESP + ChipID
    //wifiManager.autoConnect();

    
    //if you get here you have connected to the WiFi
    Serial.println("connected...yeey :)");
}

void loop() {
    // put your main code here, to run repeatedly:
     Serial.print(WiFi.RSSI());
     Serial.println("  ");
     int   value = 2 * (WiFi.RSSI() + 100);
    int numLedsToLight = map(value, 0, 100, 0, N_LEDS);
    //Serial.println(numLedsToLight);
    // First, clear the existing led values
    strip.clear();
    //Turn on the scnnned channel value as Green LEDs
    for (int led = 0; led < numLedsToLight; led++) {
      //Serial.println(numLedsToLight);
      strip.fill(green, 0, led);
      //Serial.print(led);
    }
    // Turn on the remaining LEDs as Red
    for (int led = numLedsToLight; led < N_LEDS; led++) {
      strip.fill(red, numLedsToLight, N_LEDS);
    }
    Serial.print(numLedsToLight);
    Serial.println(" LEDS will be shown");
      strip.show();
     delay(1000);
}

Credits

simonhyde88

simonhyde88

3 projects • 1 follower

Comments