Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

arduino - Designing a basic RGB LED blinking circuit

The circuit:

enter image description here

Trying to get this just to blink, can't figure out how!

void setup() {
  pinMode(3, OUTPUT);
}
    
void loop() {
  digitalWrite(3, HIGH);   
  delay(250);                     
  digitalWrite(3 , LOW);   
  delay(250);                   
}

Pretty much the stock Arduino code, but don't know why it won't work with multiple LEDs.

EDIT: The LEDs aren't blown out, because they all still work one at a time.

question from:https://stackoverflow.com/questions/65839434/designing-a-basic-rgb-led-blinking-circuit

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The problem isn't in your code:

A single standard red LED drops about 1.8V, and with the proper resistor an Arduino pin can drive such a LED at the right current.

Three LEDs (especially with a blue one among them) in series need more voltage than the Arduino pin can deliver ( 5V), so they won't light up.

Maybe two LEDs with a recalculated resistor will just about work.

Try leaving out the blue LED; it has the highest voltage drop (about 3V to 3.3V), and adding one other LED will already go too close to, or beyond, 5V, and the LEDs won't light up.

You could put the LEDs in parallel, each with their own properly calculated resistor, but the total current you pull in that configuration may exceed the maximum current allowed per Arduino pin (this depends on the Arduino used: about 20mA for most Arduinos, but only about 7mA for SAMD21-based Arduinos, for example).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...