// Matic Subelj // 13.9 .2012 // This code is designed to run a sound sensor and a laser sensor. // Both of these sensors are used to trigger a flash. // It should be easy to add additional sensors if you want, depending on the type of your Arduino. // The threshhold values for the different triggers with potentiometer control. // These may need to be changed depending on evironment and sensors being used. // Using PRINT_MESSAGES can help determine the correct value for these. #define LASER_THRESHHOLD 20 + analogRead(potPin) #define SOUND_THRESHHOLD 100 + analogRead(potPin2) // This prints messages to the serial port. This is good to enable while determining // the threshholds for your trigger, these communications are very slow and // when using these sensors to actually take pictures this should be turned off. #define PRINT_MESSAGES // The digital pins being used #define CAMERA_FLASH_PIN 4 #define LASER_PIN 5 // The analog pins being used #define LASER_TRIGGER_ANALOG_PIN 5 #define SOUND_TRIGGER_ANALOG_PIN 1 // this constant won't change: const int buttonPin = 11; // the pin that the pushbutton is attached to const int buttonPin2 = 3; // the pin that the pushbutton2 is attached to const int ledPin = 13; // the pin that the LED is attached to const int potPin = A2; // the pin that the Potentiometer for Laser trigger threshhold is attached to const int potPin2 = A3; // the pin that the Potentiometer for Sound trigger threshhold is attached to // Variables will change: int buttonPushCounter = 0; // counter for the number of button presses int buttonState = 0; // current state of the button int lastButtonState = 0; // previous state of the button int button2State = 0; // current state of the button int lastButton2State = 0; // previous state of the button boolean button2_mode = false; void setup() { // initialize the button pin as a input: pinMode(buttonPin, INPUT); pinMode(buttonPin2, INPUT); // initialize the LED as an output for armed/disarmed status light: pinMode(ledPin, OUTPUT); // initialize FLASH trigger pin as an output: pinMode(CAMERA_FLASH_PIN, OUTPUT); digitalWrite(CAMERA_FLASH_PIN, LOW); pinMode(LASER_PIN, OUTPUT); digitalWrite(LASER_PIN, LOW); digitalWrite(LASER_PIN, LOW); #ifdef PRINT_MESSAGES Serial.begin(9600); // open serial #endif } void loop() { // PushButton is used to enable/disable the rest of the code so you can prepare the DSLR rig. // read the pushbutton input pin: buttonState = digitalRead(buttonPin); // compare the buttonState to its previous state if (buttonState != lastButtonState) { // if the state has changed, increment the counter if (buttonState == HIGH) { // if the current state is HIGH then the button // wend from off to on: buttonPushCounter++; Serial.println("on"); if (buttonPushCounter % 2 != 0) { if(button2_mode) { Serial.println("B1 Pressed turning off laser.. switchin to sound"); digitalWrite(LASER_PIN,LOW); } else { Serial.println("B1 Pressed turning off sound.. switchin to laser"); digitalWrite(LASER_PIN,HIGH); } } } else { // if the current state is LOW then the button // wend from on to off: Serial.println("off"); } } // save the current state as the last state, //for next time through the loop lastButtonState = buttonState; button2State = digitalRead(buttonPin2); // compare the buttonState to its previous state if (button2State != lastButton2State) { // if the state has changed, increment the counter if (button2State == HIGH) { Serial.println("button2 pressed. switchin mode.."); button2_mode = !button2_mode; if(button2_mode) { Serial.println("B2 Pressed turning off laser.. switchin to sound"); digitalWrite(LASER_PIN,LOW); } else { Serial.println("B2 Pressed turning off sound.. switchin to laser"); digitalWrite(LASER_PIN,HIGH); } } } // save the current state as the last state, //for next time through the loop lastButton2State = button2State; // turns on the LED every four button pushes by // checking the modulo of the button push counter. // the modulo function gives you the remainder of // the division of two numbers: if (buttonPushCounter % 2 == 0) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); int soundVal; int laserVal; //////////////////////////////////////////////////////////// // SOUND TRIGGER //////////////////////////////////////////////////////////// if(button2_mode) { soundVal = analogRead(SOUND_TRIGGER_ANALOG_PIN); if (soundVal > SOUND_THRESHHOLD) { digitalWrite(CAMERA_FLASH_PIN, HIGH); #ifdef PRINT_MESSAGES Serial.println("Flash Triggered!!!"); #endif delay(100); digitalWrite(CAMERA_FLASH_PIN, LOW); } #ifdef PRINT_MESSAGES Serial.print("Sound: "); Serial.println(soundVal, DEC); #endif } else { //////////////////////////////////////////////////////////// // LASER TRIGGER //////////////////////////////////////////////////////////// laserVal = analogRead(LASER_TRIGGER_ANALOG_PIN); if (laserVal < LASER_THRESHHOLD) { digitalWrite(CAMERA_FLASH_PIN, HIGH); digitalWrite(LASER_PIN, LOW); // Turn off laser during picture #ifdef PRINT_MESSAGES Serial.println("Flash Triggered!!!"); #endif delay(100); digitalWrite(CAMERA_FLASH_PIN, LOW); digitalWrite(LASER_PIN, HIGH); // Turn laser back on after picture } #ifdef PRINT_MESSAGES Serial.print("Laser: "); Serial.println(laserVal, DEC); #endif } } }