The Sketch

Below is a copy of the “sketch” used to drive the brains of the Arduino Nano used in this project. As I’ve said previously this sketch isn’t my work but has been kindly made public by the developer Mr LeeBert, he has given written permission for me to share it here.

To upload this “sketch” onto your Arduino you will first need to download and install a programme called Arduino IDE from here.
This software is free and once you’ve read the basic instructions, is pretty easy to use. Especially in cases like this where the code is already written.

const int FLASH_PIN = 3;           //assign pin 3 to FLASH TRIGGER
const int DELAY_PIN = A0;          //assign pin A0 to DELAY POT
const int SOUND_PIN = A2;          //assign pin A2 to TRIGGER INPU
const int THRESHOLD_PIN = A3;      //assign pin A3 to THRESHOLD POT
const int BUTTON_PIN = 2;          //assign pin 2 to start BUTTON
const int potONE = A0;             //assign pin A0 to potentiometer 1 - Delay
const int potTWO = A3;             //assign pin A0 to potentiometer 2 - Threshold
int camDEL;                        //declare camDEL variable
int camDELval;                     //declare camDELval variable
int BUTTON_STATE;                  //declare BUTTON_STATE variable
int THRESHOLD;                     //declare THRESHOLD variable
int THRESHOLDval;                  //declare THRESHOLDval variable
int TIMEOUT=500;                   //500 milliseconds
int pMin = 0;  //the lowest value that comes out of the potentiometer
int pMax = 1023; //the highest value that comes out of the potentiometer.

void setup()
{

  Serial.begin(115200);
 
  pinMode(BUTTON_PIN, INPUT);      // make button press pin input
  pinMode(FLASH_PIN, OUTPUT);      // make flash trigger pin output
  digitalWrite(FLASH_PIN, LOW);    // keep flash trigger pin low
  pinMode(DELAY_PIN, INPUT);       // make pot pin an input
}

volatile int v1 = 0;
volatile int v2 = 0;

void buttonWait(int buttonPin){
  int BUTTON_STATE = 0;
  while(1){
    BUTTON_STATE = digitalRead(BUTTON_PIN);
    if (BUTTON_STATE == HIGH) {
      return;
    }
  }
}

void loop()
{
      buttonWait(2);                                      // check if button is pressed, only continue when pressed.

      THRESHOLD=analogRead(potTWO);                       //read analogue value from potentiometer 2
      THRESHOLDval = map(THRESHOLD, pMin, pMax, 2, 500);  //map value from potTWO to be between 2 and 500 to increase accuracy
      Serial.println(THRESHOLDval);
      
      while (abs(v1 - v2) < THRESHOLDval) {               // if difference between two analog read exceeds threshhold, then exit loop and trigger flash
      v1 = analogRead(SOUND_PIN);                         // start analog read
      v2 = analogRead(SOUND_PIN);     }                   // acquire again
      
      camDEL=analogRead(potONE);                          //read analogue value from potentiometer 1
      //camDELval=camDEL/(5.);                              //divide value from potONE by 5 to increase accuracy
      delay(camDELval);                                   //delay for time value camDELval - delay between second drop and camera activation

      digitalWrite(FLASH_PIN, HIGH);                      // trigger flash
      delay(10);                                          // keep flash trigger high for 10ms
      digitalWrite(FLASH_PIN, LOW);                       // done triggering, reset back   

      v1 = v2;
 
      delay(500);
      BUTTON_STATE=LOW;
      
}