Arduino Police Strobe Light

by Rezz on October 4, 2011

Arduino Police Strobe Light effect, another simple variation of blink code.

Parts List;
1) 2x 5mm red LED
2) 2x 5mm blue LED
3) 1x Arduino
4) 4x 330Ω resistor
5) 1x 10kΩ potentiometer
6) Jumper wire

Instruction;
1) Connect all LED as diagram below, make sure cathode lead of LED at ground wire.

2) Connect all 330Ω resistor to anode lead of LED.

3) Connect all jumper wire to digital pin 12 and 11.

4) Connect 10kΩ potentiometer as shown and center lead connect to analog 0 pin.

Upload this code to your arduino

/*
  Police Strobe Light
  Create police strobe light effect with speed control of the blink.
 
  Coded by: arduinoprojects101.com
 */
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
int sensorValue = 0;        // value read from the pot
int timer = 0;              // delay value

void setup() {
  // initialize the digital pin 12, 11 as an output.
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map sensorValue reading to match timer delay between 10ms to 500ms
  timer = map(sensorValue, 0, 1023, 10, 500);

  digitalWrite(12, HIGH);
  delay(timer);
  digitalWrite(12, LOW);
  delay(timer);
  digitalWrite(12, HIGH);
  delay(timer);
  digitalWrite(12, LOW);
  digitalWrite(11, HIGH);
  delay(timer);
  digitalWrite(11, LOW);
  delay(timer);
  digitalWrite(11, HIGH);
  delay(timer);
  digitalWrite(11, LOW);
}

This arduino projects, is another variation of blink code. delay value controlled by timer constant.

const int analogInPin = A0;
declare where analog input pin from 10kΩ potentiometer, that is analog pin 0 (A0).

sensorValue = analogRead(analogInPin);
reading analog value from analogInPin (A0), analog input reading will give 0 to 1023 integer value.

timer = map(sensorValue, 0, 1023, 10, 500);
timer constant use to control speed of the light strobe blinking. map is use to match analog reading (0~1023) with delay (10ms-500ms). If analog reading is 0, this will map 10ms as delay time, if analog reading is 511, this will map 250ms as delay time and so on.

Leave a Comment

Previous post:

Next post: