Hi,
I haven't programmed for about 15 years so picked up my son's old arduino uno and wanted to try some basics. I have don't about 4 or 5 basic projects and I wanted to code a UK traffic light sequence - I have wired the arduino and LEDs on a breadboard and it is working fine - I can turn each LED on or off in a sequence, but the issue is that I can't turn 2 LEDs on at the same time - I am assuming it is a wiring issue as I used the same board from a previous project that ran 3 LEDs in sequence, and then I just wrote new code to control the LEDs but first I wanted someone to check my code in case something was wrong here:
int redLED=6;
int yellowLED=5;
int greenLED=4;
void setup() {
pinMode(redLED,OUTPUT);
pinMode(yellowLED,OUTPUT);
pinMode(greenLED,OUTPUT);
}
void loop() {
digitalWrite(redLED,HIGH);
delay(500);
digitalWrite(redLED,LOW);
digitalWrite(greenLED,HIGH);
delay(1000);
digitalWrite(yellowLED,HIGH);
delay(1000);
digitalWrite(greenLED,LOW);
digitalWrite(yellowLED,LOW);
digitalWrite(redLED,HIGH);
delay(1500);
}
Any ideas what is wrong?
digitalWrite(redLED,HIGH);
digitalWrite(greenLED,HIGH);
Will switch two leds on or off (depending on how they are wired). If that does not work, you have a power issue.
Welcome to the forum
Please post a schematic of your project. A 'photo of a hand drawn circuit is good enough.
here is a photo of the circuit.
White is ground
orange is red LED PIN
Red loops from RED LED to yellow
Green is yellow LED PIN
Grey loops from yellow to Green
orange is GREEN LED to PIN
There are resistors in the circuit but I took out the resistor on the Green LED as it was quite dull.
@roboakley Welcome to the Forum
It is very much easy to run multiple LED's at the same time there is no big codding for that only u need to pin to GND pin to the arduino GND and 5V pin to your Desired pin from which do u want to control it.
The code you have mentioned will do the following
Firstly for .5 Sec it will turn on red LED and turn off after 0.5 sec at the same time Green led will lighted up and then will remain on for 1 sec and then with blue led on after 1 sec yellow led will also on (2 led turning on at the same time) after gap of 1 sec green and yellow led turned off and only red led will be on and red will on for 1.5 sec and then repeat the first process.
It is impossible to see how it is wired from the 'photos, hence
Why u do this just easily do like this
Because you're missing current-limiting resistors
1 Like
Ok so I added a Ground to the green LED and it works - Thank you @krishna_agarwal !
I suspected it was not the code!
The only issue now is when the Green and Yellow are both lit the voltage is not sufficient on the yellow LED - so is this to do with the resistor?
I need to use another type of breadboard (waiting for delivery) with the Negative as the ground - but I get the diagram you sent is easier - thanks
...and more likely to damage your Arduino.
1 Like
Is it not the LED (without current-limiting resistor) that will get damaged first by drawing double of the rated current?
I have no idea, and no desire to find out
1 Like
As i have already done this and found that it dosen't damage the board and it depend on your LED that how much volt it can use to light up without damaging the board I have 5mm led and it can easily go to by 6v so it haven't damage.
You'll need deep pockets to support your gung-ho attitude, but please keep these opinions to yourself
Sorry if u found this rude but I do not right in ego I just want to tell that it depend's on LED that's only my point.
Sorry if u found it rude
I didn't find it rude, just ignorant.
Ignorance, unlike stupidity, can be cured.
It is the amount of current that flows through the LED and Arduino pin that will cause the problem, not the voltage
I can't help feeling that your grasp of electronics is not as strong as it could be.
2 Likes