Go Down

Topic: Arduino controlled Strobe Light (Read 4143 times) previous topic - next topic

szeitz

Hello, I have a basic strobe light setup with my arduino. Right now it is running with only 1 LED, but that could easily be changed with a PSU and more LEDs and some transistors. Or even to an actual strobe bulb, with some additional parts.

Anyways, I am new to Arduino and it's language, so the code is likely messy and ugly :) and not all is my own, I combined what I read about the example codes and some on the net.

It has a switch connected, so you could turn the flashes off and on, also there is a pot to set the speed the output is flashed, the treshold of the pot could easily be changed  in the code.

Would be nice to add another switch, while holding that switch it would burst the output with the max set in the code. Didn't get that far yet, so any suggestions are welcome :)

I guess it could be usefull for other newbies like my self and maybe some that want to build a cheap strobe light around the atmega chip.

Here is the code:

Code: [Select]
/*
  Arduino Controlled (LED)Strobe
  This code was made from various example codes that come with the Arduino IDE and some of my own.
 
  - It has an LED connected to Pin 13 (could use the output with some NPN transistors to hook up an LED arrey)
  - There is a 10K pot connected to Analog 0 (for controlling the off time)
  - There is a switch connected to pin 2 as an input with a 10K resistor (pressing the switch turns on the Strobe, long pressin it turns it off)
  - Can as well monitor the output on the serial monitor
 
*/

const int sensorPin = A0;    // select the input pin for the potentiometer
const int ledPin = 13;      // select the pin for the LED
const int  buttonPin = 2;   // select the input pin for the switch
int sensorValue = 0;  // variable to store the value coming from the sensor
int outputValue = 0;

int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button


void setup() {
  // declare the ledPin as an OUTPUT and declare the buttonPin as an INPUT:
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT); 
   Serial.begin(9600);
}

void loop() {
 
  buttonState = digitalRead(buttonPin);
   if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter);
    }
    else {
      // if the current state is LOW then the button
      // wend from on to off:
      Serial.println("off");
    }
  }
  // save the current state as the last state,
  //for next time through the loop
  lastButtonState = buttonState;
 
  if (buttonPushCounter % 2 == 0) {
   
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);   
  outputValue = map(sensorValue, 0, 1023, 25, 1000);
  // 25 is the minimum off time, 1000 is the maximum off time
  // (I think it's in ms, changing these values will change
  //  the behaviour of the pot controllin the speed
 
  Serial.print("sensor = " );                       
  Serial.print(sensorValue);     
  Serial.print("\t output = ");     
  Serial.println(outputValue);  // turn the ledPin on
 
  digitalWrite(ledPin, HIGH); 
  // stop the program for <sensorValue> milliseconds:
  delay(30);         
  // turn the ledPin off:       
  digitalWrite(ledPin, LOW);   
  // stop the program for for <sensorValue> milliseconds:
 
  // print the results to the serial monitor:
  Serial.print("sensor = " );                       
  Serial.print(sensorValue);     
  Serial.print("\t output = ");     
  Serial.println(outputValue);   
  delay(outputValue);                 
} else {
  digitalWrite(ledPin, LOW);
}
}


robtillaart


add another potmeter:

first potmeter should control the frequency : 1..10000 times per sec
second potmeter should control the duty cycle: the ration between on and off :  1..100%

just an idea
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up