Published © MIT

Capturing The Water Drops With Arduino

Make your first high-speed photos of water drops with an Arduino.

BeginnerFull instructions provided1 hour4,720
Capturing The Water Drops With Arduino

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Laser Module KY-008
×1
LM393 Light Sensor Module
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×3
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
PTS 645 Series Switch
C&K Switches PTS 645 Series Switch
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

7_-_circuit_en_Tdr3x4foaz.png

Code

Untitled file

Arduino
//#define DBG_MODE

const byte BUTTON_PIN = 2;
const byte FOCUS_PIN = 3;
const byte SHUTTER_PIN = 4;
const byte FLASH_PIN = 5;
const byte SENSOR_PIN = 6;
const byte RESISTOR_PIN = A5;

const unsigned int FOCUS_DELAY = 100;
const unsigned int SHUTTER_DELAY = 100;
const unsigned int FLASH_DELAY = 10;

const unsigned int FIRE_DELAY_MIN = 1;
const unsigned int FIRE_DELAY_MAX = 500;

boolean prevButton, currButton;
boolean prevSensor, currSensor;
boolean allowFlash;
unsigned long fireDelay;

void openShutter() {
  #ifndef DBG_MODE
    digitalWrite(FOCUS_PIN, HIGH);
    delay(FOCUS_DELAY);
    digitalWrite(SHUTTER_PIN, HIGH);
    delay(SHUTTER_DELAY);
    digitalWrite(SHUTTER_PIN, LOW);
    delay(FOCUS_DELAY);
    digitalWrite(FOCUS_PIN, LOW);
  #else
    digitalWrite(LED_BUILTIN, HIGH);
  #endif
}

void fireFlash() {
  #ifndef DBG_MODE
    digitalWrite(FLASH_PIN, HIGH);
    delay(FLASH_DELAY);
    digitalWrite(FLASH_PIN, LOW);
  #else
    digitalWrite(LED_BUILTIN, LOW);
  #endif    
}

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(FOCUS_PIN, OUTPUT);
  pinMode(SHUTTER_PIN, OUTPUT);
  pinMode(FLASH_PIN, OUTPUT);
  pinMode(SENSOR_PIN, INPUT);
  
  #ifdef DBG_MODE
    pinMode(LED_BUILTIN, OUTPUT);
  #endif
  
  
  digitalWrite(FOCUS_PIN, LOW);
  digitalWrite(SHUTTER_PIN, LOW);
  digitalWrite(FLASH_PIN, LOW);

  prevButton = digitalRead(BUTTON_PIN);
  prevSensor = digitalRead(SENSOR_PIN);
  allowFlash = false;
}

void loop() {
  currButton = digitalRead(BUTTON_PIN);
  if (prevButton != currButton) {
    prevButton = currButton;
    if (currButton == LOW) {
      allowFlash = true;
      prevSensor = HIGH;
      fireDelay = map(analogRead(RESISTOR_PIN), 0, 1023, FIRE_DELAY_MIN, FIRE_DELAY_MAX);
      openShutter();
    }
    else {
      delay(50);
    }
  }

  currSensor = digitalRead(SENSOR_PIN);
  if (prevSensor != currSensor) {
    prevSensor = currSensor;
    if (currSensor == HIGH) {
      if (allowFlash) {
        allowFlash = false;
        delay(fireDelay);
        fireFlash();
      }
    } 
  }
}  

Credits

Comments