Ethan Holman's Website & Blog

Arduino basic police lights with LED's

This simple program uses 2 Red LED's and 2 blue LED's to simulate police lights. I used RGB LED's because that's all I had at the time, but any red/blue led will work fine. Check in the code below for which pins to attach the lights to.


void setup() {
  // Even numbers = blue, odd numbers = red
  pinMode(4, OUTPUT); // Blue LED
  pinMode(5, OUTPUT); // Red LED
  pinMode(6, OUTPUT); // Blue LED
  pinMode(7, OUTPUT); // Red LED
}

void loop() {

  // Flash blue lights 3 times
  for (int a=1; a<=3; a++) {
	digitalWrite(4, HIGH);
	digitalWrite(6, HIGH);
	delay(75);
	digitalWrite(4, LOW);
	digitalWrite(6, LOW);
	delay(40);
  }
  delay(80);
  
  // Flash red lights 3 times
  for (int a=1; a<=3; a++) {
	digitalWrite(5, HIGH);
	digitalWrite(7, HIGH);
	delay(75);
	digitalWrite(5, LOW);
	digitalWrite(7, LOW);
	delay(40);
  }
  delay(80);
}