Pages: [1]   Go Down
Author Topic: RGB LED and PWM pins does not work properly  (Read 231 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everybody!
I have this image which describes the cables I've "attached" to my Arduino Mega to control an RGB LED.
I get something very strange:
when I write
analogWrite(RED, 0)
the LED becomes red and not set the RED component of the color to 0.
I'm a bit confused... smiley-confuse smiley-confuse
If I write
analogWrite(RED, 255)
the LED turn itself off.
(in these examples, the others colors are set to 0. Really.... 0. They are not visible).

I have an Arduino Mega and I've connected the RED to 8, GREEN to 9 and BLUE to 10 and Ground to 5V port.

What is the mistake?

Thanks a lot!

Jymmy
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26477
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 Common anode LED?
The behaviour you describe sounds perfectly normal.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've seen some tuts that explain that I have to set the colour with analogWrite(colour, 0 if I have to turn off that colour and vice versa.
So that seemed a strange behavior. To avoid errors, I post the image of my led here (it's attached!)

Thanks.


* immagine010.jpg (6.19 KB, 200x200 - viewed 7 times.)
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26477
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the LED is common anode ( impossible to tell from the photo) then the analogWrite sinks current, so the action of analogWrite is inverted - 0 turns the LED on full, and 255 turns it off.
If you want to write, say, 25/255 brightness, and a variable "brightness" contains 25, then analogWrite (redPin, 255 - brightness);
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1]   Go Up
Jump to: