1

I just begun with the Arduino starter kit, and in the second example I would like to test some changes to learn more.

The point is to have a green LED shining, and when pressing the button the two red LEDs blink.

This is the code:

int switchState = 0;
void setup()
{
 pinMode(2, INPUT);
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(5, OUTPUT);
 // the button is pressed
 digitalWrite(3, LOW);
 digitalWrite(4, LOW);
 digitalWrite(5, HIGH);
 delay(250); // wait for a quarter second
 // toggle the LEDs
 digitalWrite(4, HIGH);
 digitalWrite(5, LOW);
 delay(250); // wait fo a quarter second
}
void loop()
{
 switchState = digitalRead(2);
 // this is a comment
 if(switchState == LOW)
 {
 // the button is not pressed
 digitalWrite(3, HIGH); // green LED
 digitalWrite(4, LOW); // red LED
 digitalWrite(5, LOW); // red LED
 }
 else
 {
 // the button is pressed
 digitalWrite(3, LOW);
 digitalWrite(4, LOW);
 digitalWrite(5, HIGH);
 delay(250); // wait for a quarter second
 // toggle the LEDs
 digitalWrite(4, HIGH);
 digitalWrite(5, LOW);
 delay(250); // wait fo a quarter second
 }
} // go back to the beginning of the loop

I added a modification into the schema (a fourth LED in parallel with the green), like this:

enter image description here

enter image description here

But the added LED is not shining. It's a long time ago I finish school and I forgot a lot of things. Am I wiring the fourth LED incorrectly?

The Guy with The Hat
5,2927 gold badges30 silver badges51 bronze badges
asked Sep 6, 2014 at 13:45

1 Answer 1

1

Blue LEDs have a higher Vf than green LEDs, hence much less current will pass through it, not enough to make it visible. Give it its own resistor instead of sharing the resistor with the green.

answered Sep 6, 2014 at 15:47
1
  • Thank you, I checked it with different LEDs and with its own resistor and everything ok. Commented Sep 6, 2014 at 16:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.