0

I have an RGB LED strip which I want to control with my arduino uno, everything works fine, except for the green LEDs. They cannot be dimmed to less than 50%, because they will simply turn off.

I have this test code in my setup:

Serial.write("dimming green test started");
for(int x = 255; x > 0; x--) {
    analogWrite(greenPin,x);
    Serial.write(" - g:");
    Serial.print(x);
    delay(6);
  }
  Serial.println();
  Serial.write("dimming green test done");
  Serial.println();

And the green LEDs are fully turned on in the beginning, and at about 127, the just turn off. All the other colors are perfectly dimmable. I checked the energy usage, and green does only use a little more than the other colors, so that's not the problem.

Are green LEDs not dimmable? Or is this just an optical effect?

(I use a setup very similar to this one with one difference: but only use 5V, because my LED strip only needs 5V) setup

4
  • 1
    switch connections at arduino. swap pin 4 and 7 ... does the problem move to red color?
    – jsotola
    Commented Feb 27, 2018 at 17:43
  • 1
    the pins marked with ~ are the PWM pins ... use those
    – jsotola
    Commented Feb 27, 2018 at 17:48
  • so why does blue and red work :p Commented Feb 27, 2018 at 22:42
  • I used pins 5-7 (so the image was not exactly correct)
    – Finni
    Commented Mar 4, 2018 at 14:06

1 Answer 1

2

analogWrite only works on pins that support PWM. Those are the pins with the ~ next to it.

On no-PWM pins, analogWrite will set the pin to LOW, for all values lower than 128, and HIGH for all the higher values. Which is what you are experiencing.

4
  • interestingly, none of the 3 pins chosen by the OP - 2,4 and 7 - have that ~ symbol in the image in the question! Commented Feb 27, 2018 at 22:39
  • @JaromandaX the OP said the image was from a similar project, so I’m not assuming he used those exact pins.
    – Gerben
    Commented Feb 28, 2018 at 12:04
  • with one difference - well, there's three connections to LED's, but only one fails to work ... must be at least two differences between actual wiring and what OP shows in the question :p Commented Feb 28, 2018 at 12:24
  • I used pins 5-7, so only one of them was not PWM
    – Finni
    Commented Mar 4, 2018 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.