I chose this project and am using an arduino because I am interested in photography and also thought it would be really fun to learn how to use an arduino. I think the trigger is pretty fast as is (the colored vials were photographed before they even hit the water). But since this is my first project, I am really interested in how I could wire/ program things better, so that I can use the knowledge for future projects.
Riva- Thanks for the suggestion. Right now though I am not sure what you mean (just got home and haven't looked into it yet).
Also I was wondering, would using serial.println cause any delays in the process?
Below is my code. Thanks!
/* Laser triggered flash using pot for delay
*/
int photocellPin = A0; //photocell and 10k pulldown resistor
int photocellReading; //value of photocell reading
int LEDpin = 11; //activate optoisolator
int laser = 3; //activate transistor, complete current to laser
int delayPot = A5; //get value from potentiometer to adjust delay from 0-1023 ms, gets recorded to delatTimer
int sensorValue = 0; //phototransistor sensor value
int sensorMin = 1023; //minimum sensor value
int sensorMax = 0; //maxiumum sensor value
int delayTimer = 0; //delay timing of flash
void setup(void)
{
Serial.begin(9600);
pinMode(13, OUTPUT); //LED light, on when calibrating
pinMode(11, OUTPUT); //Power to optoisolator to trigger FLASH OR ACTION
digitalWrite(11, LOW); //turn off current to optoisolator
digitalWrite(13, HIGH); //turn on Arduino LED while measuring high/low light
digitalWrite(laser, HIGH); //turn on laser
while (millis() < 5000) //during the first 5 seconds determine light range
{
sensorValue = analogRead(photocellPin);
Serial.println("Calibrating");
if (sensorValue >sensorMax) //determine max sensor value
{
sensorMax = sensorValue;
}
if (sensorValue < sensorMin) //determine min sensor value
{
sensorMin = sensorValue;
}
}
digitalWrite(13, LOW); //turn off LED, indicates calibration is complete
Serial.print("Max sensor Value = "); //print max sensor value
Serial.println(sensorMax);
Serial.print("Min sensor Value = "); //print min sensor value
Serial.println(sensorMin);
sensorMin = sensorMin - 2; //adjust min sensor value TRY REMOVING
Serial.print("New sensorMin");
Serial.println(sensorMin);
}
void loop()
{
sensorValue = analogRead(photocellPin); //read photocellPin;
delayTimer = analogRead(delayPot); //get delay before triggering flash from pot value
Serial.println(delayTimer); //print delay taken from pot
if (sensorValue < sensorMin) //if light to phototransistor is reduced, begin flash procedure
{
Serial.print("FLASH Analog reading = "); //display sensorValue
Serial.println(sensorValue);
digitalWrite(laser, LOW); //turn off laser so beam is not in photo
Serial.print("Now delaying"); //delay from potentiometer setting
Serial.println(delayTimer);
delay(delayTimer);
Serial.println("delayed");
digitalWrite(11, HIGH); //current to optoisolator, trigger flash
delay(100); //keep current going to make sure flash is triggered
digitalWrite(11, LOW); //turn off flash trigger
digitalWrite(laser, HIGH); //turn laser back on
delay(500);
Serial.println("READY"); //ready for next photo
}
else
{
}
}