Hello,
this is my first arduino project, and I'm very happy with the result. This circuit allows me to take high speed pictures, like this
I made a video explaining how I took this picture and put it onto Youtube.
This is the code for the arduino.
/*
High speed photography with an arduino
*/
//analog pins
#define SOUNDIN A0
#define SENSITIVITYPIN A1
#define DELAYPIN A2
//constants
#define SHORTCOMMAND 0
#define LONGCOMMAND 1
#define COMMANDSEPARATOR 10 //border between short and long commands
#define LIGHT 0
#define SOUND 1
//digital pins
#define FOCUSPIN 2
#define TRIGGERPIN 3
#define FLASHPIN 4
#define LIGHTPIN 5
#define LIGHTSOUNDTOGGLE 6
#define STARTSWITCH 7
#define LEDPIN 9
#define BEEPPIN 10
void setup() {
pinMode(FOCUSPIN, OUTPUT);
pinMode(TRIGGERPIN, OUTPUT);
pinMode(FLASHPIN, OUTPUT);
pinMode(LIGHTPIN, OUTPUT);
pinMode(LIGHTSOUNDTOGGLE, INPUT);
pinMode(STARTSWITCH, INPUT);
pinMode(LEDPIN, OUTPUT);
pinMode(BEEPPIN, OUTPUT);
ledOn();
turnLightOn();
}
/*
This is the logic of the device
1. Wait for the start switch to be pressed
2. Wait for voice command. Short command triggers lights outs. Long command cancels the whole procedure
3. Wait for voice command. Short command opens shutter. Long command cancels the whole procedure
4. Check what to do. This is either
a. Wait for sound. Any sound triggers flash
b. Wait for pass in light port. Any movement triggers flash
5. Close shutter
6. Turn on light
*/
void loop() {
if(start()) // 1. Wait for the start switch to be pressed
{
int command;
command = detectCommand(0);
if (command == SHORTCOMMAND) // 2. Wait for voice command. Short command triggers lights outs.
{
rogerBeep();
turnLightOff();
delay(500);
command = detectCommand(0);
if (command == SHORTCOMMAND) // 3. Wait for voice command. Short command opens shutter.
{
rogerBeep();
ledOff();
openShutter();
int delayTime = readDelay();
delay(200);
if (lightOrSound() == SOUND) //4. Check what to do
{
detectSound(0);
delay(delayTime);
flash();
}
else
{
// to be implemented
}
// 5. & 6. Close shutter, turn light on
closeShutter();
ledOn();
turnLightOn();
}
else // 3. Wait for voice command. Long command cancels the whole procedure
{
cancelBeep();
turnLightOn();
}
}
else // 2. Wait for voice command. Long command cancels the whole procedure
{
cancelBeep();
}
}
}
void rogerBeep()
{
digitalWrite(BEEPPIN, HIGH);
delay(200);
digitalWrite(BEEPPIN, LOW);
delay(500);
}
void cancelBeep()
{
for (int i = 0; i<3; i++)
{
digitalWrite(BEEPPIN, HIGH);
delay(200);
digitalWrite(BEEPPIN, LOW);
delay(200);
}
delay(500);
}
int lightOrSound()
{
if (digitalRead(LIGHTSOUNDTOGGLE)) return SOUND;
else return LIGHT;
}
void flash()
{
digitalWrite(FLASHPIN, HIGH);
delay(200);
digitalWrite(FLASHPIN, LOW);
}
void turnLightOn()
{
digitalWrite(LIGHTPIN, HIGH);
}
void turnLightOff()
{
digitalWrite(LIGHTPIN, LOW);
}
int readSensitivity()
{
int sensitivity = 0;
sensitivity = analogRead(SENSITIVITYPIN);
return map(sensitivity, 0, 1023, 540, 650);
}
int readDelay()
{
int delaytime = 0;
delaytime = analogRead(DELAYPIN);
return map(delaytime, 0, 1023, 0, 250);
}
boolean start()
{
while (digitalRead(STARTSWITCH));
return true;
}
void ledOn()
{
digitalWrite(LEDPIN, HIGH);
}
void ledOff()
{
digitalWrite(LEDPIN, LOW);
}
int detectCommand(int compensation)
{
int count = 0;
int countSilence = 0;
int treshHold = readSensitivity();
while (true)
{
int sensorValue = analogRead(SOUNDIN);
sensorValue = sensorValue + compensation;
if (sensorValue < 512) sensorValue = 1024 - sensorValue;
if (sensorValue > treshHold)
{
count++;
countSilence = 0;
}
else
{
//Check if this is the end of the command
countSilence++;
if (count > 0 && countSilence > 10)
{
if (count < COMMANDSEPARATOR) return SHORTCOMMAND;
else return LONGCOMMAND;
}
}
delay(5);
}
}
void detectSound(int compensation)
{
int treshHold = readSensitivity();
while (true)
{
int sensorValue = analogRead(SOUNDIN);
sensorValue = sensorValue + compensation;
if (sensorValue < 512) sensorValue = 1024 - sensorValue;
if (sensorValue > treshHold) return;
}
}
void openShutter()
{
digitalWrite(FOCUSPIN, HIGH);
delay(1000);
digitalWrite(TRIGGERPIN, HIGH);
}
void closeShutter()
{
digitalWrite(FOCUSPIN, LOW);
digitalWrite(TRIGGERPIN, LOW);
delay(1000);
}
This is definitely not my last arduino project! Love it.
Greetings
Cedric