Go Down

Topic: High speed photography with arduino nano (Read 5890 times) previous topic - next topic

cbnation

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.

Youtube.

This is the code for the arduino.

Code: [Select]

/*
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


xFinaLx

This is really cool! I have the same camera and I really want to build one of these now! Do you have a Flickr or anything where you post your high-speed photos?

focalist

What is particularly nice is that you don't need a special camera of any sort, as long as you can lock the focus and do a 'bulb' exposure, any camera will work for stop motion.. The key is the flash is your 'shutter'.

I am trying to build a high power LED strobe for macro stopmotion and other effects.. Arduino makes this kind of thing easy enough to do over a weekend.  I've also used Arduino as an automatic bracketing timer for HDR exposures.

Arduino and cameras.. A match made in geek heaven...
When the testing is complete there will be... cake.

cbnation

Some more examples can be found on Flickr. The ones from the lamp need better lighting,  but I'm happy with the first results.

Devonian

Nice project.
I made something similar a long time ago but without Arduino.
Maybe I will re-visit it...

Possible the best flashgun for this is still the Vivitar 285 with variable power (flash speed/duration)

Nigel.

focalist

#6
Apr 16, 2012, 06:00 pm Last Edit: Apr 16, 2012, 06:06 pm by focalist Reason: 1
SOOO much better and IMMENSELY more dangerous:

http://www.glacialwanderer.com/hobbyrobotics/?p=490

Air-Gap ARC flash, DIY.... this is one very inspirational project.  Sure it can kill you.. but it gets the shot!  Inspiring in it's dedication to setting out and accomplishing something that ought not to be attempted in the first place.  

So many geek props I can't even begin to praise it enough...heh
When the testing is complete there will be... cake.

a.d

This looks like a nice build - I've been working on something similar on and off for the last few years but have never got to the point that you have - actually finishing it!

You say you're not happy with your lightbulb smashing photos - have you tried lighting these in a dark field manner? You just need some tracing paper and a piece of black card.

cbnation

Hi a.d,

what do you mean exactly with "in a dark field manner"?

The pictures are taken in the dark and the flash, triggered at the right moment, is the only light there is. I have set my flash to the lowest power to make the light flash as short as possible. I could try to go for more light, but that means also longer light and perhaps blurry pictures.

Anyway, I ran out of light bulbs at the moment. :P I asked all my colleagues and friends to give all non-working light bulbs to me so should have a new supply soon.

focalist

#9
Apr 17, 2012, 03:59 pm Last Edit: Apr 17, 2012, 04:04 pm by focalist Reason: 1
Frosted bulbs might be more visible, but maybe not as dramatic visually.

Light and Dark field lighting is a term from microscopy, ultra macro... Never heard the term used in this context, but the concept applies.  For your purposes,it just means sidelit at about a 15 degree angle.

http://www.microscan.com/technology/machine%20vision%20lighting/brightfieldanddarkfieldlighting.aspx


When the testing is complete there will be... cake.

alexhb

wow! amazing results! love the little details, such as the power LED going out and the foot pedal.... looking forward to more of your work!
"#define QUESTION ((bb) || !(bb))  - Shakespeare."

a.d

#11
Apr 18, 2012, 04:26 pm Last Edit: Apr 18, 2012, 04:46 pm by a.d Reason: 1
what do you mean exactly with "in a dark field manner"?


It's a studio lighting method to highlight the edges of transparent objects relatively easily - As focalist says the terms light field and dark field are used in microscopy, with slightly different meaning (as far as I understand it). This is a photo I took a few years ago using the technique - I have a more recent one with the filament lit, but it's not on the Internet and I can't find it.

In essence, place your object and frame up your shot. Now, cut a piece of black card so that it only just fills the viewfinder and place it behind the object as the background. Finally, use a large sheet of tracing paper and attach this to the back of the black background card to use as a diffuser. You can also use a softbox or bounce the flash of a (photographically) neutral wall.

When you take the photo, it should light the edges. Tada!

I'll draw a diagram and upload it in a minute.

a.d

#12
Apr 18, 2012, 04:38 pm Last Edit: Apr 18, 2012, 04:48 pm by a.d Reason: 1
Here's that diagram. I apologise for the quality, it was scanned on the photocopier at work.

As a bonus, here's an article with a really good photo that demonstrates what I mean.

cbnation

Thank you very much for the explanation. I didn't know the technique. Will try it out.

JMtB

Hi Cedric!
This comes very close to what I hope to have one day, being the main reason why I started to llok into Arduino.
Great video, great you shared the code, but is there a diagram somewhere that you wish to share so other can build a similar device?

Go Up