Go Down

Topic: Multiple LED timers (Read 920 times) previous topic - next topic

ThisPerson

Hi, I'm new to Arduino and I'm looking for someone to help me improve a code to include more pins so that all LED turn off after some hours has passed and turn on after some time. I have little knowledge of coding.

This is the code I'm trying to modify:

Code: [Select]
int ledPin = 13;                 // LED connected to digital pin 13

void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()
{
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(1000);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(1000);                  // waits for a second
}


I'm trying to use pins 6-13, thanks

PaulRB

Hello,

Tell us more about these slowly changing patterns of leds you want. How independantly will they switch on/off, for example. There may be some easy ways to achieve what you want.

Paul

ThisPerson

I want the Arduino to act as a timer and turn on/off all of the LEDs at the same time. For example, I'll set the Arduino so that it keeps all of the LEDs on during 6:00 AM to 5:00 PM and turn them off at 5:01 PM to 5:59 AM.

PaulRB

#3
Apr 19, 2016, 04:26 pm Last Edit: Apr 19, 2016, 04:31 pm by PaulRB
Then that is easy. You could even run all the leds off the same Arduino pin, using a transistor.

However, there are a couple of problems with your idea. Firstly, the Arduino does not know the time, so you will need to set that somehow each time you turn it on or press reset. Secondly, Arduino will not keep time well and will drift away from the correct time within a few days, maybe hours.

What you need is a Real Time Clock module. They are cheap on eBay. Get a ds3231 based module rather than a ds1307. They are around the same price and much more accurate.

Paul

ThisPerson

I don't know how to code though so I cant figure out how to make it work with the clock module and the LEDs.

Delta_G

I don't know how to code though
What a perfect time to learn then.  There are tons of resources that describe doing just exactly the sort of thing you want to do.  Seems like a few hours in the language reference learning what the different keywords and commands look like and do followed by a few minutes with Google and you'd likely have this one solved.
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

jgarbasi

This is a simple code that should suit  your request, if I understood it .

Change the values of LOWERPIN and UPPERPIN to increase/decrease the limits


Code: [Select]

//
// simple blink program
// 7 leds bound to D6 thru D13 outputs
//
#define LOWERPIN 6
#define UPPERPIN 13
int i ;
void setup()
{
  for (i=LOWERPIN; i<=UPPERPIN; i++) {
  pinMode(i, OUTPUT);      // sets the digital pin as output
  }
}

void loop()
{
  for (i=LOWERPIN; i<=UPPERPIN; i++) {
  digitalWrite(i, HIGH);   // sets the LED on
  }

  delay(1000);                  // waits for a second
 
  for (i=LOWERPIN; i<=UPPERPIN; i++) {
  digitalWrite(i, LOW);    // sets the LED off
  }

  delay(1000);                  // waits for a second
}


Regards,

Jean-Paul

Go Up