Keith Mitchell
Published © GPL3+

Photon WiFi Strength Meter v2

A device made with a bar graph and a Particle Photon to show the WiFi strength.

BeginnerShowcase (no instructions)30 minutes3,588
Photon WiFi Strength Meter v2

Things used in this project

Hardware components

Photon
Particle Photon
×1
Resistor 220 ohm
Resistor 220 ohm
×10
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Breadboard circuit

Code

Photon Code

C/C++
Flash to your Photon from build.particle.io
//The pins connected to the bar graph LCD in order from lowest to largest
int bars [] = {D0, D1, D2, D3, D4, D5, D6, D7, A0, A1};
//The pin the optional speaker is on
int speakerPin = RX;

void setup() {

    //Takes control of the on-board RGB led for showing errors
    RGB.control(true);

    pinMode(D7, OUTPUT);
    pinMode(D6, OUTPUT);
    pinMode(D5, OUTPUT);
    pinMode(D4, OUTPUT);
    pinMode(D3, OUTPUT);
    pinMode(D2, OUTPUT);
    pinMode(D1, OUTPUT);
    pinMode(D0, OUTPUT);
    
    pinMode(A1, OUTPUT);
    pinMode(A0, OUTPUT);
}

bool error = false;
bool errorLightOn = false;
int errorCode;

int lastStrength;

void loop() {
    //Section to handle error codes from the WiFi, and to make the light flash
    if(error){
        if(!errorLightOn){
            //WiFi chip error
            if(errorCode == 1)
                RGB.color(255, 0, 0);
            //Time-out
            if(errorCode == 2)
                RGB.color(0, 0, 255);
            errorLightOn = true;
        }else{
            RGB.color(0, 0, 0);        
            errorLightOn = false;
        }
        delay(100);
    }else{
        RGB.color(0, 0, 0);
    }
        
    //Checks the strength
    int strength = WiFi.RSSI();
    
    //Converts the -127 to -1 strength range to 0-9
    int color = (((strength - -127) * 10) / (-1 - -127));
        
    //Checks for an error
    if(strength > 0){
        // 1 = WiFi Chip error
        // 2 = Timed out
        if(strength == 1 || strength ==2){
            error = true;
            errorCode = strength;
            return;
        }else{
            //If your close to the router, sometimes the values will go past the -1 max for an unknown reason
            //This function simplly sets the bars to the max when that's the case
            error = false;
            
            for (int i = 0; i < 10; i++ )
                digitalWrite(bars[i], HIGH);
        }
    }else{
        error = false;
        
        //Set the strength bars that are used to HIGH, and the unused ones to LOW
        for (int i = 0; i < 10; i++ ){
            if(i < color)
                digitalWrite(bars[i], HIGH);
            else
                digitalWrite(bars[i], LOW);
                
            //Play a tone on the speaker if the strength changes significantly (12.5% for a 10 segment graph)
            if(color != lastStrength)
                 tone(speakerPin, 1908, 125);    
            lastStrength = color;
        }
    }
}

Credits

Keith Mitchell

Keith Mitchell

10 projects • 44 followers
Canadian DevOps Engineer and hobbyist technology enthusiast

Comments