Katelyn Rule
Published © CC0

WiFi Strength Meter

A meter that indicates the Wi-Fi signal strength in an intuitive way, using the parts I had on hand.

BeginnerShowcase (no instructions)30 minutes3,458
WiFi Strength Meter

Things used in this project

Hardware components

Photon
Particle Photon
×1
NeoPixel Ring: WS2812 5050 RGB LED
Adafruit NeoPixel Ring: WS2812 5050 RGB LED
×1
SMA Female to N-Type Male Weatherproof
×1
Bluesky Plastic Electronic Project Box
×1
Antenna
×1

Story

Read more

Code

Wifi-meter.ino

C/C++
Uses strength of signal to light up certain LED's on the neopixel ring. The number of green lights running counter-clockwise indicates signal stregth (the more lit, the stronger the signal). Rainbow lights mean loss of signal.
/*
    This code was based on an adafruit neopixel example. 
*/

/* ======================= includes ================================= */

#include "Particle.h"
#include "neopixel.h"

/* ======================= prototypes =============================== */

void colorAll(uint32_t c, uint8_t wait);
void colorWipe(uint32_t c, uint8_t wait);
void rainbow(uint8_t wait);
void rainbowCycle(uint8_t wait);
uint32_t Wheel(byte WheelPos);


SYSTEM_MODE(AUTOMATIC);

#define PIXEL_COUNT 24
#define PIXEL_PIN D6
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

void setup() {
    //This enables the external antenna connector on the particle. 
    STARTUP(WiFi.selectAntenna(ANT_EXTERNAL)); 
    strip.begin();
    strip.show(); 
}

void loop() {
    int strength = WiFi.RSSI(); // -127 (weak) to -1 (strong)
    double v = (double) ((strength+127.0)/127.0);
    Particle.variable("strength", strength);
    Particle.variable("anormal", v);
    
    if (strength > 0 || !WiFi.ready())
    {
        rainbowCycle(100);
    }
    else
    {
        int count = (int) (PIXEL_COUNT*v);
        Particle.variable("count", count);
        for (int i = 0; i < PIXEL_COUNT; i++)
        {
            if (i < count)
            {
                strip.setPixelColor(i, strip.Color(0, 15, 0));
            }
            else
            {
                strip.setPixelColor(i, strip.Color(0, 0, 0));
            }
        }
        strip.show(); 
    }
    delay(100);
}

// Set all pixels in the strip to a solid color, then wait (ms)
void colorAll(uint32_t c, uint8_t wait) {
  uint16_t i;

  for(i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
  }
  strip.show();
  delay(wait);
}

// Fill the dots one after the other with a color, wait (ms) after each one
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout, then wait (ms)
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) { // 1 cycle of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

Credits

Katelyn Rule

Katelyn Rule

1 project • 3 followers

Comments