Controlling LED Light Bars for my truck

My main question is about how to connect 12V relays to my Arduino, but first I’ll set up the usage scenario:

I’ve got a few LED light bars on my truck, and I’d like to have a number of modes for them. Specifically, I want:

  • Main light bar on
  • All light bars on
  • Main bar on with all others flashing

It’s not too many modes, but I figured hard-wiring the required circuit would be an absolute mess and a one-way street.

So far, I’ve created a prototype sketch using my Sparkfun Redboard (Uno replacement) which can turn on a red and a yellow LED when a button is pushed, and flash them both when another button is pushed. (see code below)

At this point, I’m lost as to how I connect my 12V automotive relays to the Arduino so that I can switch on/off the light bars. If it’s any help, the relay says “RTT7101-12V 40A 12VDC” and the light bar I’m trying to use right now is 18W, though I’m hoping to expand the system to all my light bars of various wattages.

My prototype sketch:

const int button1Pin = 2;  // pushbutton 1 pin (BLUE button)
const int button2Pin = 3;  // pushbutton 2 pin (YELLOW button)
const int ledRPin = 13;    // red LED pin
const int ledYPin = 12;    // yellow LED pin

void setup()
{
  // Set up the pushbutton pins to be an input:
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);

  // Set up the LED pin to be an output:
  pinMode(ledRPin, OUTPUT); 
  pinMode(ledYPin, OUTPUT);      
}


void loop()
{
  int button1State, button2State;  // variables to hold the pushbutton states


  button1State = digitalRead(button1Pin);
  button2State = digitalRead(button2Pin);

  if ((button1State == LOW)     // if we're pushing button 1
      && !                      // AND we're NOT
      (button2State == LOW))    // pushing button 2
                                // then...
  {
    digitalWrite(ledRPin, HIGH);    // turn ON the red LED
    digitalWrite(ledYPin, HIGH);    // turn ON the yellow LED
  }
  else
  {
    digitalWrite(ledRPin, LOW);     // turn OFF the red LED
    digitalWrite(ledYPin, LOW);     // turn OFF the yellow LED
  }

  if (button2State == LOW)      // if we're pushing button 2
                                // then...
  {
  for (int i=0; i < 15; i++)
  {
    digitalWrite(ledRPin, HIGH);    // turn ON the red LED
    delay(40);                      // wait 40 milliseconds
    
    digitalWrite(ledRPin, LOW);     // turn OFF the red LED
    digitalWrite(ledYPin, HIGH);    // turn ON the yellow LED
    delay(40);                      // wait 40 milliseconds

    digitalWrite(ledYPin, LOW);     // turn OFF the yellow LED
  }
  for (int l=0; l < 4; l++)
  {
    digitalWrite(ledRPin, HIGH);    // turn ON the red LED
    delay(40);                      // wait 40 ms
    digitalWrite(ledYPin, HIGH);    // turn ON the yellow LED
    delay(100);                     // wait 100 ms

    digitalWrite(ledRPin, LOW);     // turn OFF the red LED
    delay(40);                      // wait 40 ms
    digitalWrite(ledYPin, LOW);     // turn OFF the yellow LED
    delay(100);                     // wait 100 ms
  }
  }
  else
  {
    digitalWrite(ledRPin, LOW);     // turn OFF the red LED
    digitalWrite(ledYPin, LOW);     // turn OFF the yellow LED
  }
}

Are those relays part of the existing truck installation, or do you want to add independent light bars?

For driving 12V relays by a 5V Arduino you need a relay driver, maybe a transistor, diode and resistor for each relay, or a chip with multiple such drivers (e.g. ULN2003). Controlling such circuits works like controlling LEDs, with an Arduino output pin driving the logic level input of the driver instead of a LED.

Those relays need 12v on the coils, so the arduino will have to be a relay/switch of its own. But at that point the system is redundant, using an arduino to control 12v to a relay controlling another 12v. You can look into just using a power mosfet for arduino and lights, no relays.

Thanks both! I'll look into the solutions next weekend when I have time... ;D