[Solved] Photon - RGB LED to WKP pin always dimly lit?

Hi all, first time poster, long(ish) time lurker.

I have been working on an aquarium controller to switch some 12v solenoids, all working as expected except a status RGB LED i want to use…

I have the RGB LED connected to WKP/A7 (Red), A5 (Green), A4 (Blue) (all with 1k ohm resistors in series) and the 5v DC I am supplying the photon with (using a single 12v DV supply with LM7805 voltage regulator). The problem i have is that the red LED is dimly lit when it should be completely off, which i suspect has something to do with the fact i am using the WKP pin for PWM. Adding to this suspicion is that fact that it is still dimly lit when the photon is in deep sleep mode.

Anyone have any idea what i’m doing wrong? I could use a different pin instead of WKP/A7 but this would mean updating the PCB i already have and getting it re-made which i would like to avoid if possible.

https://www.youtube.com/watch?v=ahSaqaAUp_Q

The sketch is a bit complicated to control all of the solenoids and sensors, but the relevant bits for the LED are pretty much the following:

int rgbLED_r = A7; 
int rgbLED_g = A5;
int rgbLED_b = A4;  
int redValue = 255;  
int greenValue = 255;
int blueValue = 255;

void setup() {
    pinMode( rgbLED_r, OUTPUT);
    pinMode( rgbLED_g, OUTPUT);
    pinMode( rgbLED_b, OUTPUT);
    analogWrite( rgbLED_r, redValue);
    analogWrite( rgbLED_g, greenValue);
    analogWrite( rgbLED_b, blueValue);
}

void loop() {
    analogWrite( rgbLED_r, 100);
    analogWrite( rgbLED_g, 255);
    analogWrite( rgbLED_b, 255);
    delay(1000);
    
    analogWrite( rgbLED_r, 255);
    analogWrite( rgbLED_g, 100);
    analogWrite( rgbLED_b, 255);
    delay(1000);
    
    analogWrite( rgbLED_r, 255);
    analogWrite( rgbLED_g, 255);
    analogWrite( rgbLED_b, 100);
    delay(1000);

    analogWrite( rgbLED_r, 100);
    analogWrite( rgbLED_g, 255);
    analogWrite( rgbLED_b, 255);
    delay(1000);
    
    analogWrite( rgbLED_r, 255);
    analogWrite( rgbLED_g, 100);
    analogWrite( rgbLED_b, 255);
    delay(1000);
    
    analogWrite( rgbLED_r, 255);
    analogWrite( rgbLED_g, 255);
    analogWrite( rgbLED_b, 100);
    delay(1000);

    analogWrite( rgbLED_r, 255);
    analogWrite( rgbLED_g, 255);
    analogWrite( rgbLED_b, 255);
    delay(1000);

    System.sleep(SLEEP_MODE_DEEP, 30);
}

Deep sleep uses a ~40k internal pull-down resistor. If you are using a common anode RGB LED and control the cathode via WKP then the pull-down will draw current while in deep sleep.

So either use a different pin or a common cathode LED.

Just a side note on coding practice: You may want to replace all these analogWrite() blocks with one single function call setRGB(r, g, b); when having a function doing that

void setRGB(int R, int G, int B) {
    analogWrite( rgbLED_r, R);
    analogWrite( rgbLED_g, G);
    analogWrite( rgbLED_b, B);
}

Thanks for that info, and good call on the function to control LED!

I get what you are saying about the deep sleep using the pull-down resistor, but does that explain why I still see the same dim red colour even when the program is running and I set the colour to 255,255,255?

Also take your point about using cathode RGB LED, but this would also require modification to the existing PCB (as would changing the pin), but I guess I might just have to bite the bullet? I take such a long time to solder the components haha I’m trying to avoid doing it again!

Since you are running the RGB LED off 5V your analogWrite(x, 255) will only rise the GPIO level to 3.3V and since the forward voltage of a red LED is ~1.2V the difference will still be enough to "open" the barrier.

If you run the LED off 3v3 an analog 255 value should make the LED go off completely. If it doesn't you can also use digitalWrite(x, HIGH) to make entirely sure.

BTW, having a GPIO drive 3.3V against a 5V rail isn't going to do well with the GPIO's well-being over time.
Driving voltage while having to sink current seems just wrong :wink:

Thanks for the explanation. Looks like the best option will be change to a cathode RGB LED… I guess I’m going to have to get the screwdriver out and remove a bit of trace, then do some ad hoc soldering to the PCB!!

Thanks for your help, much appreciated :slight_smile:

1 Like