Components and supplies
USB battery pack
UBEC DC/DC Step down
Capacitor 10 µF
Resistor 221 ohm
WS2811b
Wemos D1 Mini
Project description
Code
WIFI LED sketch
c_cpp
1/* 2 This sketch demonstrates how to scan WiFi networks and light up a strip of LEDs 3*/ 4#define FASTLED_ESP8266_D1_PIN_ORDER 5#include "ESP8266WiFi.h" 6#include "FastLED.h" 7String ssid_look = "Nhat Binh"; 8//String ssid_look = "DANANG WIFI"; 9String look; 10//Define vartiables for LED calculations 11long value; 12long rssi; 13long numLedsToLight; 14// FastLED definitions 15#define NUM_LEDS 99 16#define DATA_PIN 4 17// Define the array of leds 18CRGB leds[NUM_LEDS]; 19void setup() { 20 Serial.begin(115200); 21 //Set the strip up 22 FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); 23 FastLED.setBrightness(100); 24 FastLED.clear(); 25 // Set WiFi to station mode and disconnect from an AP if it was previously connected 26 WiFi.mode(WIFI_STA); 27 WiFi.disconnect(); 28 delay(100); 29 Serial.println("Setup done"); 30} 31 32void loop() { 33 Serial.println("scan start"); 34 35 // WiFi.scanNetworks will return the number of networks found 36 int n = WiFi.scanNetworks(); 37 Serial.println("scan done"); 38 if (n == 0) { 39 Serial.println("no networks found"); 40 //Fill all red if no wifi found 41 // First, clear the existing led values 42 FastLED.clear(); 43 fill_solid( leds, NUM_LEDS, CRGB::White); 44 45 } else { 46 Serial.print(n); 47 Serial.println(" networks found"); 48 for (int i = 0; i < n; ++i) { 49 // Print SSID and RSSI for each network found 50 Serial.printf("%d: %s, Ch:%d (%ddBm) %s\ 51", i + 1, WiFi.SSID(i).c_str(), WiFi.channel(i), WiFi.RSSI(i), WiFi.encryptionType(i) == ENC_TYPE_NONE ? "open" : ""); 52 look = WiFi.SSID(i); 53 if (look == ssid_look) { 54 //Put the signal strength of the SSID looked for in rssi 55 rssi = WiFi.RSSI(i); 56 Serial.print("Wifi scanned SSID iss..."); 57 Serial.println(look); 58 break; 59 } 60 } 61 } 62 //Serial.println("Here"); 63 //Do all the light stuff where green is the strength and red fills the rest of the LEDS 64 if (look == ssid_look) { 65 // Calculate the number of Grren LEDs to light up 66 int value = 2 * (rssi + 100); 67 int numLedsToLight = map(value, 0, 100, 0, NUM_LEDS); 68 //Serial.println(numLedsToLight); 69 // First, clear the existing led values 70 FastLED.clear(); 71 //Turn on the scnnned channel value as Green LEDs 72 for (int led = 0; led < numLedsToLight; led++) { 73 //Serial.println(numLedsToLight); 74 leds[led] = CRGB::Green; 75 //Serial.print(led); 76 } 77 // Turn on the remaining LEDs as Red 78 for (int led = numLedsToLight; led < NUM_LEDS; led++) { 79 leds[led] = CRGB::Red; 80 } 81 Serial.print(numLedsToLight); 82 Serial.println(" LEDS will be shown"); 83 } else { 84 Serial.print("No SSID match"); 85 Serial.println(""); 86 fill_solid( leds, NUM_LEDS, CRGB::White); 87 } 88 89 FastLED.show(); 90 // Wait a bit before scanning again 91 delay(500); 92 //Delete all the WIFI scanned info 93 WiFi.scanDelete(); 94 numLedsToLight = 0; 95 Serial.println("--Clear values--"); 96} 97
Added WiFi manager
c_cpp
Use this to manage the wifi SSID that your looking at...you willl need to know both the SSID and the password for it.
1#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino 2#include <Adafruit_NeoPixel.h> 3//needed for library 4#include <DNSServer.h> 5#include <ESP8266WebServer.h> 6#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager 7long value; 8int numLedsToLight; 9// NeoPixel definitions 10#define PIN 0 11#define N_LEDS 98 12 13Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800); 14//Define colours 15uint32_t white = strip.Color(255, 255, 255); 16uint32_t red = strip.Color(255, 0, 0); 17uint32_t green = strip.Color(0, 255, 0); 18 19void setup() { 20 // put your setup code here, to run once: 21 Serial.begin(115200); 22 strip.begin(); 23 //WiFiManager 24 //Local intialization. Once its business is done, there is no need to keep it around 25 WiFiManager wifiManager; 26 //reset saved settings 27 //wifiManager.resetSettings(); 28 29 //set custom ip for portal 30 //wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); 31 32 //fetches ssid and pass from eeprom and tries to connect 33 //if it does not connect it starts an access point with the specified name 34 //here "AutoConnectAP" 35 //and goes into a blocking loop awaiting configuration 36 wifiManager.autoConnect("AutoConnectAP"); 37 //or use this for auto generated name ESP + ChipID 38 //wifiManager.autoConnect(); 39 40 41 //if you get here you have connected to the WiFi 42 Serial.println("connected...yeey :)"); 43} 44 45void loop() { 46 // put your main code here, to run repeatedly: 47 Serial.print(WiFi.RSSI()); 48 Serial.println(" "); 49 int value = 2 * (WiFi.RSSI() + 100); 50 int numLedsToLight = map(value, 0, 100, 0, N_LEDS); 51 //Serial.println(numLedsToLight); 52 // First, clear the existing led values 53 strip.clear(); 54 //Turn on the scnnned channel value as Green LEDs 55 for (int led = 0; led < numLedsToLight; led++) { 56 //Serial.println(numLedsToLight); 57 strip.fill(green, 0, led); 58 //Serial.print(led); 59 } 60 // Turn on the remaining LEDs as Red 61 for (int led = numLedsToLight; led < N_LEDS; led++) { 62 strip.fill(red, numLedsToLight, N_LEDS); 63 } 64 Serial.print(numLedsToLight); 65 Serial.println(" LEDS will be shown"); 66 strip.show(); 67 delay(1000); 68}
Added WiFi manager
c_cpp
Use this to manage the wifi SSID that your looking at...you willl need to know both the SSID and the password for it.
1#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino 2#include <Adafruit_NeoPixel.h> 3//needed for library 4#include <DNSServer.h> 5#include <ESP8266WebServer.h> 6#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager 7long value; 8int numLedsToLight; 9// NeoPixel definitions 10#define PIN 0 11#define N_LEDS 98 12 13Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800); 14//Define colours 15uint32_t white = strip.Color(255, 255, 255); 16uint32_t red = strip.Color(255, 0, 0); 17uint32_t green = strip.Color(0, 255, 0); 18 19void setup() { 20 // put your setup code here, to run once: 21 Serial.begin(115200); 22 strip.begin(); 23 //WiFiManager 24 //Local intialization. Once its business is done, there is no need to keep it around 25 WiFiManager wifiManager; 26 //reset saved settings 27 //wifiManager.resetSettings(); 28 29 //set custom ip for portal 30 //wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); 31 32 //fetches ssid and pass from eeprom and tries to connect 33 //if it does not connect it starts an access point with the specified name 34 //here "AutoConnectAP" 35 //and goes into a blocking loop awaiting configuration 36 wifiManager.autoConnect("AutoConnectAP"); 37 //or use this for auto generated name ESP + ChipID 38 //wifiManager.autoConnect(); 39 40 41 //if you get here you have connected to the WiFi 42 Serial.println("connected...yeey :)"); 43} 44 45void loop() { 46 // put your main code here, to run repeatedly: 47 Serial.print(WiFi.RSSI()); 48 Serial.println(" "); 49 int value = 2 * (WiFi.RSSI() + 100); 50 int numLedsToLight = map(value, 0, 100, 0, N_LEDS); 51 //Serial.println(numLedsToLight); 52 // First, clear the existing led values 53 strip.clear(); 54 //Turn on the scnnned channel value as Green LEDs 55 for (int led = 0; led < numLedsToLight; led++) { 56 //Serial.println(numLedsToLight); 57 strip.fill(green, 0, led); 58 //Serial.print(led); 59 } 60 // Turn on the remaining LEDs as Red 61 for (int led = numLedsToLight; led < N_LEDS; led++) { 62 strip.fill(red, numLedsToLight, N_LEDS); 63 } 64 Serial.print(numLedsToLight); 65 Serial.println(" LEDS will be shown"); 66 strip.show(); 67 delay(1000); 68}
WIFI LED sketch
c_cpp
1/* 2 This sketch demonstrates how to scan WiFi networks and light up a strip of LEDs 3*/ 4#define FASTLED_ESP8266_D1_PIN_ORDER 5#include "ESP8266WiFi.h" 6#include "FastLED.h" 7String ssid_look = "Nhat Binh"; 8//String ssid_look = "DANANG WIFI"; 9String look; 10//Define vartiables for LED calculations 11long value; 12long rssi; 13long numLedsToLight; 14// FastLED definitions 15#define NUM_LEDS 99 16#define DATA_PIN 4 17// Define the array of leds 18CRGB leds[NUM_LEDS]; 19void setup() { 20 Serial.begin(115200); 21 //Set the strip up 22 FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); 23 FastLED.setBrightness(100); 24 FastLED.clear(); 25 // Set WiFi to station mode and disconnect from an AP if it was previously connected 26 WiFi.mode(WIFI_STA); 27 WiFi.disconnect(); 28 delay(100); 29 Serial.println("Setup done"); 30} 31 32void loop() { 33 Serial.println("scan start"); 34 35 // WiFi.scanNetworks will return the number of networks found 36 int n = WiFi.scanNetworks(); 37 Serial.println("scan done"); 38 if (n == 0) { 39 Serial.println("no networks found"); 40 //Fill all red if no wifi found 41 // First, clear the existing led values 42 FastLED.clear(); 43 fill_solid( leds, NUM_LEDS, CRGB::White); 44 45 } else { 46 Serial.print(n); 47 Serial.println(" networks found"); 48 for (int i = 0; i < n; ++i) { 49 // Print SSID and RSSI for each network found 50 Serial.printf("%d: %s, Ch:%d (%ddBm) %s\ 51", i + 1, WiFi.SSID(i).c_str(), WiFi.channel(i), WiFi.RSSI(i), WiFi.encryptionType(i) == ENC_TYPE_NONE ? "open" : ""); 52 look = WiFi.SSID(i); 53 if (look == ssid_look) { 54 //Put the signal strength of the SSID looked for in rssi 55 rssi = WiFi.RSSI(i); 56 Serial.print("Wifi scanned SSID iss..."); 57 Serial.println(look); 58 break; 59 } 60 } 61 } 62 //Serial.println("Here"); 63 //Do all the light stuff where green is the strength and red fills the rest of the LEDS 64 if (look == ssid_look) { 65 // Calculate the number of Grren LEDs to light up 66 int value = 2 * (rssi + 100); 67 int numLedsToLight = map(value, 0, 100, 0, NUM_LEDS); 68 //Serial.println(numLedsToLight); 69 // First, clear the existing led values 70 FastLED.clear(); 71 //Turn on the scnnned channel value as Green LEDs 72 for (int led = 0; led < numLedsToLight; led++) { 73 //Serial.println(numLedsToLight); 74 leds[led] = CRGB::Green; 75 //Serial.print(led); 76 } 77 // Turn on the remaining LEDs as Red 78 for (int led = numLedsToLight; led < NUM_LEDS; led++) { 79 leds[led] = CRGB::Red; 80 } 81 Serial.print(numLedsToLight); 82 Serial.println(" LEDS will be shown"); 83 } else { 84 Serial.print("No SSID match"); 85 Serial.println(""); 86 fill_solid( leds, NUM_LEDS, CRGB::White); 87 } 88 89 FastLED.show(); 90 // Wait a bit before scanning again 91 delay(500); 92 //Delete all the WIFI scanned info 93 WiFi.scanDelete(); 94 numLedsToLight = 0; 95 Serial.println("--Clear values--"); 96} 97
Downloadable files
Wiring laout
Wiring the WS211b to the WeMos D1
Wiring laout
Comments
Only logged in users can leave comments
simonhyde88
0 Followers
•0 Projects
Table of contents
Intro
0
0