HELP!! I am new to arduino Require basic 12 LED light function

Ok so I have been advised Arduino is the best product to use to power 12 LED lights (12V) via a 16 channel 12V relay board. The Leds are Techna 12Volt panel LED's.

Each LED needs to power on at random for 2 seconds, this needs to be on a continuos loop.

2 Questions

  1. Will the arduino have enough outputs to control 12 LEDS through the relay board

  2. What would the code be for this project.

any help on this is greatly appreciated.

An Arduino Uno will have enough outputs.

If you want someone to write a program for you please ask in the Gigs and Collaborations section of the Forum and be prepared to pay.

If you want to learn to program yourself the examples that come with the Arduino IDE are a good place to start. There are also many online tutorials. Also see the Useful Links Thread.

If you want more advice please post a link to the datasheet for your relay board.

...R

frankandbeanz:
Each LED needs to power on at random for 2 seconds, this needs to be on a continuos loop.

  1. What would the code be for this project.

You will have to be a LOT more specific when designing the sketch.

Are the lights on one at a time?
Is there delay between one light going off and the next light going on?
Is it the same 'random' pattern each loop?
Does the 'random' pattern have to go through all 12 lights before looping?

Something to get you started:

#define NUM_LEDS        12
#define TMR_CHANGEUP    2000L   //2000mS
int
    ledPins[NUM_LEDS] = 
    {
        2,3,4,5,6,7,8,9,10,11,12,13
    };

#define RELAY_OFF   LOW
#define RELAY_ON    HIGH

unsigned long
    timeNow,
    timeThen;
long
    randomNum,
    lastLED;
    
void setup() 
{
    byte
        i;
    for( i=0; i<NUM_LEDS; i++ )
    {
        pinMode( ledPins[i], OUTPUT );
        digitalWrite( ledPins[i], LOW );
            
    }//for
    
    randomSeed(analogRead(A0));

    //select a random LED and turn it on
    randomNum = random( NUM_LEDS );
    digitalWrite( ledPins[randomNum], RELAY_ON );
    lastLED = randomNum;    
    timeThen = millis();

}//setup

void loop() 
{
    timeNow = millis();
    
    if( (timeNow - timeThen) > TMR_CHANGEUP )
    {        
        digitalWrite( ledPins[lastLED], RELAY_OFF );
        timeThen = timeNow;
        randomNum = random( NUM_LEDS );
        digitalWrite( ledPins[randomNum], RELAY_ON );
        lastLED = randomNum;    
        
    }//if
    
}//loop

That should be " lastLED = randomNum;" in place of " lastLED = rand;"
There is also a problem using "NUM_LEDS + 1" as the upper limits on random. That will give you the 13th element of a 12-element array.

const byte NUM_LEDS =  12;
const unsigned long TMR_CHANGEUP = 2000;   //2000mS
const byte LEDPins[NUM_LEDS] =
{
  2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
};

// Relay modules are typically Active Low: A LOW signal
// turns them ON and a HIGH signal turns them OFF.
const bool RELAY_OFF = HIGH;
const bool RELAY_ON = LOW;

unsigned long TimeThen;
byte LastLED;

void setup()
{
  for (byte i = 0; i < NUM_LEDS; i++ )
  {
    pinMode(LEDPins[i], OUTPUT );
    digitalWrite(LEDPins[i], RELAY_OFF );
  }//for

  randomSeed(analogRead(A0));  // Leave A0 floating to get some entropy

  //select a random LED and turn it on
  byte thisLED = LEDPins[random(NUM_LEDS)];
  digitalWrite(thisLED, RELAY_ON);
  LastLED = thisLED;
  TimeThen = millis();

}//setup

void loop()
{
  unsigned long timeNow = millis();

  if ( (timeNow - TimeThen) > TMR_CHANGEUP )
  {
    TimeThen = TimeThen + TMR_CHANGEUP;
    byte thisLED = LEDPins[random(NUM_LEDS)];
    digitalWrite(LastLED, RELAY_OFF);
    digitalWrite(thisLED, RELAY_ON);
    LastLED = thisLED;
  }//if
}//loop

Thanks john. My understanding of random(max) was that max represented the "max - upper bound of the random value, exclusive".

and that it returns "a random number between min and max-1."

Now that I think about it I want a number between 0 and 11 inclusive. So, yes, you're right :slight_smile:

Thanks for noting the rand issue. That was my original variable name, which I subsequently changed but clearly missed an instance of.