Create a Police Light Effect with Arduino

Police-Light-Effect-with-Arduino

Create a Police Light Effect with Arduino

In this project, we will create a police light effect using Arduino and 10 LEDs. The setup includes 5 blue LEDs and 5 green LEDs, which will blink alternately in a “police-style” pattern. This is a fun and educational project for beginners to learn about basic Arduino programming and LED control.

Components Needed

  1. Arduino Board (e.g., Arduino Uno)
  2. 10 LEDs (5 blue and 5 green)
  3. 10 Resistors (220 ohms)
  4. Breadboard
  5. Connecting Wires
  6. USB Cable (for programming the Arduino)
  7. Power Source (optional for standalone operation)

Circuit Diagram

  1. Connect the blue LEDs to pins 2, 3, 4, 5, and 6 on the Arduino.
  2. Connect the green LEDs to pins 7, 8, 9, 10, and 11 on the Arduino.
  3. Attach a 220-ohm resistor in series with each LED to prevent excessive current.
  4. Connect the cathodes (negative terminals) of all LEDs to the Arduino’s GND pin.
  5. Ensure all connections are secure and neat on the breadboard.

Code

The following code will alternate the blinking of the blue and green LEDs in a police light pattern:



#define NUM_LEDS 5

// Blue LEDs connected to pins 2 to 6
int blueLeds[NUM_LEDS] = {2, 3, 4, 5, 6};
// Green LEDs connected to pins 7 to 11
int greenLeds[NUM_LEDS] = {7, 8, 9, 10, 11};

void setup() {
// Set all LED pins as outputs
for (int i = 0; i < NUM_LEDS; i++) {
pinMode(blueLeds[i], OUTPUT);
pinMode(greenLeds[i], OUTPUT);
}
}

void loop() {
// Blink blue LEDs in police pattern
for (int i = 0; i < NUM_LEDS; i++) {
digitalWrite(blueLeds[i], HIGH); // Turn on
delay(100); // Wait 100 ms
digitalWrite(blueLeds[i], LOW); // Turn off
delay(100); // Wait 100 ms
}

delay(1000); // Wait 1 second before switching

// Blink green LEDs in police pattern
for (int i = 0; i < NUM_LEDS; i++) {
digitalWrite(greenLeds[i], HIGH); // Turn on
delay(100); // Wait 100 ms
digitalWrite(greenLeds[i], LOW); // Turn off
delay(100); // Wait 100 ms
}

delay(1000); // Wait 1 second before repeating
}


Download the code

How It Works

  1. The LEDs are divided into two groups: blue and green.
  2. Each group of LEDs blinks in a sequential pattern, mimicking a police light effect.
  3. After one group completes its sequence, the other group starts.
  4. The delay(100) function creates the blinking effect, and the delay(1000) ensures a pause before switching to the next group.

Steps to Upload the Code

  1. Install the Arduino IDE on your computer.
  2. Connect your Arduino board to the computer using a USB cable.
  3. Open the Arduino IDE and paste the above code.
  4. Select the correct board and COM port under the “Tools” menu.
  5. Click the Upload button to transfer the code to the Arduino.

Testing the Circuit

  1. Power the Arduino using the USB cable or an external power source.
  2. Observe the blue LEDs blinking in sequence, followed by the green LEDs.
  3. The pattern will repeat indefinitely.

Troubleshooting

  • LEDs not lighting up: Check the wiring and ensure all connections are secure.
  • Incorrect blinking pattern: Verify that the LEDs are connected to the correct pins as specified in the code.
  • No response from Arduino: Ensure the correct COM port and board type are selected in the Arduino IDE.

Conclusion

This project demonstrates how to create a police light effect with Arduino using 10 LEDs. It’s a simple yet effective way to learn about Arduino programming and LED control. Feel free to modify the timing or add more LEDs to customize the effect further. Happy tinkering!

 

Leave a Reply

Your email address will not be published. Required fields are marked *