0

I have a breadboard connected to an Arduino Uno, 220k resistors connected to an led, of course it has a common ground and a pin connected to 5v. All pins are digital.

Now, I want led 1 to turn on for one second, the next led for two seconds and the next for three seconds, but that means, when the second led which has to be on for two seconds then the first led will come back on after one second has past on the second led, the third led would be on for three seconds, so the second led will also be on when two seconds pass and the first would be on when one second passes. So basically, all leds are on for their given duration.

How do I do this? I have been trying to do this since three days. It would be a pleasure if someone helps me out. Thanks.

int ledPin1= 2;
int ledPin2 = 4;
int ledPin3 = 7;

void setup(){
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  }

  void loop(){
  digitalWrite(ledPin1, HIGH);
  delay(500);
  digitalWrite(ledPin1, LOW);
  delay(500);

  digitalWrite(ledPin2, HIGH);
  delay(1000);
  digitalWrite(ledPin2, LOW);
  delay(1000);

  digitalWrite(ledPin3, HIGH);
  delay(1500);
  digitalWrite(ledPin3, LOW);
  delay(1500);
    }

So far this is the code. But it delays the whole program. Need leds on at given times.

2
  • 2
    What exactly is not working ? can you post the code you have tried so far ? Are you able to light On at least one LED ? (220k resistor seems much to me, usually it's somethink arround 330Ohm depending on the choosen LED)
    – Julien
    Commented Sep 16, 2016 at 17:52
  • Sorry 220 ohms, sorry my mind was somewhere else, yes I can switch on LED's and stuff but I need it in this pattern
    – Rusty Ryan
    Commented Sep 16, 2016 at 19:20

2 Answers 2

3

Using a 220k Ohm resistor will lead to approximatively 20µA to light the LED. This is not enough to light the LED, you should replace the resitor by one of value 330Ohm (220 to 470 could be OK depending of the LED)

1
  • Sorry, the resistor is 220ohms,
    – Rusty Ryan
    Commented Sep 17, 2016 at 5:22
1

Seems like you want a pattern like this ?

LED1 : 1 0 1 0 1 0 1 0 1 0 1 0 ... repeat
LED2 : 1 1 0 0 1 1 0 0 1 1 0 0 ... repeat
LED3 : 1 1 1 0 0 0 1 1 1 0 0 0 ... repeat

In which case you'll need something like this pseudo code

// set up the relevant pins as output etc
....
// set up a counter
counter = 0

loop
  toggle LED1
  if (counter modulo 2 == 0) then toggle LED2
  if (counter modulo 3 == 0) then toggle LED3

  counter++
  if counter > 11 then counter = 0 // your pattern repeats every 12 seconds

  delay for 1 second

Toggling the LED is just a case of checking if it is high or low and setting it to the opposite value.

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.