// Maurice Ribble // 4-12-2008 // http://www.glacialwanderer.com/hobbyrobotics // This code is designed to to tune (see PRINT_MESSAGE define) and // 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. // These enable the different types of triggers //#define ENABLE_LASER_TRIGGER #define ENABLE_SOUND_TRIGGER // The threshhold values for the different triggers. // 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 500 #define SOUND_THRESHHOLD 100 // This prints messages to the serial port. This is good to enable while determining // the threshholds for your trigger, but 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 0 #define SOUND_TRIGGER_ANALOG_PIN 1 void setup() { pinMode(CAMERA_FLASH_PIN, OUTPUT); digitalWrite(CAMERA_FLASH_PIN, LOW); pinMode(LASER_PIN, OUTPUT); digitalWrite(LASER_PIN, LOW); #ifdef ENABLE_LASER_TRIGGER digitalWrite(LASER_PIN, HIGH); // Turn on the Laser #endif #ifdef PRINT_MESSAGES Serial.begin(9600); // open serial #endif } void loop() { int soundVal; int laserVal; //////////////////////////////////////////////////////////// // SOUND TRIGGER //////////////////////////////////////////////////////////// #ifdef ENABLE_SOUND_TRIGGER 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 #endif // ENABLE_SOUND_TRIGGER //////////////////////////////////////////////////////////// // LASER TRIGGER //////////////////////////////////////////////////////////// #ifdef ENABLE_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 #endif // ENABLE_LASER_TRIGGER }