Arduino Police Lights (ATMega 2650 Version) **New Flash Patterns!**

by Wally_Z in Circuits > Arduino

20169 Views, 45 Favorites, 0 Comments

Arduino Police Lights (ATMega 2650 Version) **New Flash Patterns!**

2009-Dodge-Charger-police-car-1.jpg
**DISCLAIMER**
I do not and will not take responsibility for anyone who gets in trouble for this, by either imitating emergency personnel, or using without a permit/lisence.



Updates!
-I have shortened the code
-Changed 16 LED's to 8
-Changed/added more flash patterns
-Renamed variables

As promised, this is the ATMega 2650 version of the police lights I originally did on my Duemilanove. 

What you will need:

4x red LED's (high brightness) You will want extra bright red LED's because the ones I used are not very bright compared to the blue
4x blue LED's (high brightness)
8x 100 ohm resistors
1x ATMega 2650 (The revision version does not matter)
22AWG wire
1x breadboard

Optional: 
You can use transistors to use a lot of lights and not have to have as much code, or as many outputs being used. Just replace the LED's with the transistors you want to use. I plan on using blue LED light strips with transistors to make this as easy as possible.

Or even use shift registers and have a HELL of a lot of LED's hooked up.

The Hardware

015.JPG
The final result:

Considering you have installed the MEGA drivers and can program it, I will show you how to make awesome looking police lights.

First, you want to grab your breadboard, and some wire. You want to have it hooked up similar to the way I have it hooked up I the first picture. This makes it look better, stay together better, and make it easier to hook it up.

You will notice that the way I hooked it up looks a little weird, don't fret. I have it programmed to use these pins so you don't have to figure them all out.

I know I don't provide a schematic, but it would be a HUGE pain to draw one up, and it would not look very good or understandable with this many outputs. I figured you can see how to hook it up enough to actually hook it up. Follow my Duemilanove version if you can't figure this out. This is just double the outputs of what that is.

The Code

the-matrix.jpg
Now that you have it all hooked up, you will want to paste the code into your Arduino IDE. You can change this code any way you want to make it look more like police lights, or even like an oversized Nightrider if you use all red LED's. So feel free to modify it, you don't have to say that I wrote the code, just mention me for giving you the idea or the base to branch your project off of.

Patterns:
-Flash one side 3 times
-Flash the other side 3 times
-Flash one side one time, then the other side one time, (alternating happening 7 times)
-Flash one side twice, then the other side twice (happens 6 times)

Feel free to mess with the timings, or how many cycles it does of each to your liking.

The code:

/*
This sketch will flash 8 LED's in certain patterns. The "for" statement really helped cut down on the code (It cut the size in half).
This project is meant for the blue lights I will be using in my vehicle as a volunteer firefighter, so the variables are named as such.
*/

//Declaring the front lights
const int GrillTopLeft = 5;
const int GrillTopRight = 6;
const int GrillBottomLeft = 7;
const int GrillBottomRight = 8;

//For the lights in by the rear-view mirror, just use the outputs for the REAR LED's so it looks awesome, and you don't have to use 4 more outputs.

//Declaring the rear lights
const int TaillightLeft = 9;
const int ReverselightLeft = 10;
const int ReverselightRight = 11;
const int TaillightRight = 12;

void setup() {
   //Declares the front LED's as output
  pinMode(GrillTopLeft, OUTPUT);
  pinMode(GrillTopRight, OUTPUT);
  pinMode(GrillBottomLeft, OUTPUT);
  pinMode(GrillBottomRight, OUTPUT);

  //Declares the rear LED's as outputs
  pinMode(TaillightLeft, OUTPUT);
  pinMode(ReverselightLeft, OUTPUT);
  pinMode(ReverselightRight, OUTPUT);
  pinMode(TaillightRight, OUTPUT);
}   

void loop() {
  
  for(int x=0; x < 2; x++){  //Nested for structure. It makes the whole light flashing loop cycle 3 times.
  for(int x=0; x < 4; x++){  //First LED's flash 3x
  digitalWrite(GrillTopLeft, HIGH);
  digitalWrite(GrillTopRight, LOW);
  digitalWrite(GrillBottomLeft, HIGH);
  digitalWrite(GrillBottomRight, LOW);
  digitalWrite(TaillightLeft, HIGH);
  digitalWrite(ReverselightLeft, LOW);
  digitalWrite(ReverselightRight, HIGH);
  digitalWrite(TaillightRight, LOW);
  delay(50);
  digitalWrite(GrillTopLeft, LOW);
  digitalWrite(GrillTopRight, LOW);
  digitalWrite(GrillBottomLeft, LOW);
  digitalWrite(GrillBottomRight, LOW);
  digitalWrite(TaillightLeft, LOW);
  digitalWrite(ReverselightLeft, LOW);
  digitalWrite(ReverselightRight, LOW);
  digitalWrite(TaillightRight, LOW);
  delay(50);
}
 
  //Makes the other LED's flash 3x
  for(int x=0; x < 4; x++){
  digitalWrite(GrillTopLeft, LOW);
  digitalWrite(GrillTopRight, HIGH);
  digitalWrite(GrillBottomLeft, LOW);
  digitalWrite(GrillBottomRight, HIGH);
  digitalWrite(TaillightLeft, LOW);
  digitalWrite(ReverselightLeft, HIGH);
  digitalWrite(ReverselightRight, LOW);
  digitalWrite(TaillightRight, HIGH);
  delay(50);
  digitalWrite(GrillTopLeft, LOW);
  digitalWrite(GrillTopRight, LOW);
  digitalWrite(GrillBottomLeft, LOW);
  digitalWrite(GrillBottomRight, LOW);
  digitalWrite(TaillightLeft, LOW);
  digitalWrite(ReverselightLeft, LOW);
  digitalWrite(ReverselightRight, LOW);
  digitalWrite(TaillightRight, LOW);
  delay(50);
  }
  }
  //Beginning the alternating flashes
  for(int x=0; x < 8; x++){
  digitalWrite(GrillTopLeft, HIGH);
  digitalWrite(GrillTopRight, LOW);
  digitalWrite(GrillBottomLeft, HIGH);
  digitalWrite(GrillBottomRight, LOW);
  digitalWrite(TaillightLeft, HIGH);
  digitalWrite(ReverselightLeft, LOW);
  digitalWrite(ReverselightRight, HIGH);
  digitalWrite(TaillightRight, LOW);
  delay(50);
  digitalWrite(GrillTopLeft, LOW);
  digitalWrite(GrillTopRight, LOW);
  digitalWrite(GrillBottomLeft, LOW);
  digitalWrite(GrillBottomRight, LOW);
  digitalWrite(TaillightLeft, LOW);
  digitalWrite(ReverselightLeft, LOW);
  digitalWrite(ReverselightRight, LOW);
  digitalWrite(TaillightRight, LOW);
  delay(50);
  digitalWrite(GrillTopLeft, LOW);
  digitalWrite(GrillTopRight, HIGH);
  digitalWrite(GrillBottomLeft, LOW);
  digitalWrite(GrillBottomRight, HIGH);
  digitalWrite(TaillightLeft, LOW);
  digitalWrite(ReverselightLeft, HIGH);
  digitalWrite(ReverselightRight, LOW);
  digitalWrite(TaillightRight, HIGH);
  delay(50);
  digitalWrite(GrillTopLeft, LOW);
  digitalWrite(GrillTopRight, LOW);
  digitalWrite(GrillBottomLeft, LOW);
  digitalWrite(GrillBottomRight, LOW);
  digitalWrite(TaillightLeft, LOW);
  digitalWrite(ReverselightLeft, LOW);
  digitalWrite(ReverselightRight, LOW);
  digitalWrite(TaillightRight, LOW);
  delay(50);
  }
 
  for(int x=0; x < 5; x++){
   
  for(int x=0; x < 2; x++){
  digitalWrite(GrillTopLeft, HIGH);
  digitalWrite(GrillTopRight, HIGH);
  digitalWrite(GrillBottomLeft, LOW);
  digitalWrite(GrillBottomRight, LOW);
  digitalWrite(TaillightLeft, LOW);
  digitalWrite(ReverselightLeft, LOW);
  digitalWrite(ReverselightRight, HIGH);
  digitalWrite(TaillightRight, HIGH);
  delay(50);
  digitalWrite(GrillTopLeft, LOW);
  digitalWrite(GrillTopRight, LOW);
  digitalWrite(GrillBottomLeft, LOW);
  digitalWrite(GrillBottomRight, LOW);
  digitalWrite(TaillightLeft, LOW);
  digitalWrite(ReverselightLeft, LOW);
  digitalWrite(ReverselightRight, LOW);
  digitalWrite(TaillightRight, LOW);
  delay(50);
}
  for(int x=0; x < 2; x++){
  digitalWrite(GrillTopLeft, LOW);
  digitalWrite(GrillTopRight, LOW);
  digitalWrite(GrillBottomLeft, HIGH);
  digitalWrite(GrillBottomRight, HIGH);
  digitalWrite(TaillightLeft, HIGH);
  digitalWrite(ReverselightLeft, HIGH);
  digitalWrite(ReverselightRight, LOW);
  digitalWrite(TaillightRight, LOW);
  delay(75); //Changed from 50ms because it was too fast, and hard to see.
  digitalWrite(GrillTopLeft, LOW);
  digitalWrite(GrillTopRight, LOW);
  digitalWrite(GrillBottomLeft, LOW);
  digitalWrite(GrillBottomRight, LOW);
  digitalWrite(TaillightLeft, LOW);
  digitalWrite(ReverselightLeft, LOW);
  digitalWrite(ReverselightRight, LOW);
  digitalWrite(TaillightRight, LOW);
  delay(75); //Changed from 50ms as well.
  }
  }
}