Tuesday, May 11, 2010

Laser-activated camera trigger

I thought it would be cool to build a laser switch that triggered my camera’s shutter release anytime something went through the laser. I got the idea from Glacial Wanderer and decided to give it a try.

First, I procured a cheap laser, any laser will do but I took one from a simple laser-level found at The Home Depot. Since I had two of them, I tore one apart and swiped the laser element out of it.

Second, I had to program the Arduino to sense a voltage drop from the Photocell (when something went in between the laser and photocell) and turn off the laser so it doesn’t get in the picture. See schematic below.

And finally, send power to transistor-type switch which I had already built to trigger the camera.






The swiped laser was modified to fit inside a plastic tube. Drilling a hole in a piece of wood and mounting a plastic tube on it would do the trick. I painted it black to limit the light hitting the photocell.





Here is a picture of the Arduino connected to the breadboard.


A closeup of the electronic switch.





The way it works is, the laser is “turned on” as long as the beam is hitting the photocell. As expected, the photocell incurs more voltage as the laser beam is hitting it. It is connected to Analog pin 0 on the Arduino “listening” for a voltage drop. As soon as the voltage drops below the threshold, the code tells pin 5 to “turn off” the laser and send power to in 13 (which is attached to the switch mechanism. The laser begins to pulsate (which is how the code was designed) and pin 13 has enough voltage allow the transistor to light up the LED. I’ve attached the camera jack above the collector of the transistor and to the negative side of the diode so that when enough voltage flows through it “shorts” out the camera switch to take a picture.

The camera switch uses a standard 2.5 mm jack. You could could buy a switch for about $30, but after doing some research, I discovered the switch does nothing more than “short” itself out. See below.










Knowing this, I took a phone headset and cut the wires. Putting the two wires together creates a short-circuit and releases the shutter. It’s one of the simplest ways to create a shutter trigger for about $3.


Here is the code to upload to the microcontroller:

// ORIGINAL DESIGN by Maurice Ribble
// 4-12-2008
//Modified by Josiah Leverich

// 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 CAMERA_FLASH_PIN 13
#define LASER_PIN 5

// The analog pins being used
#define LASER_TRIGGER_ANALOG_PIN 0

void setup()
{
pinMode(CAMERA_FLASH_PIN, OUTPUT);
digitalWrite(CAMERA_FLASH_PIN, LOW);
pinMode(LASER_PIN, OUTPUT);
digitalWrite(LASER_PIN, LOW);

digitalWrite(LASER_PIN, HIGH); // Turn on the Laser


}

void loop()
{
int soundVal;
int laserVal;


laserVal = analogRead(LASER_TRIGGER_ANALOG_PIN);


if (laserVal <= LASER_THRESHHOLD)


{
digitalWrite(CAMERA_FLASH_PIN, LOW);
delay(10);
digitalWrite(CAMERA_FLASH_PIN, HIGH);

delay(100);
digitalWrite(CAMERA_FLASH_PIN, LOW);
digitalWrite(LASER_PIN, HIGH); // Turn laser back on after picture
}

}


Monday, May 10, 2010

Lightning-Activated Camera Trigger



















Distance-Activated Camera Trigger


This trigger was built to sense objects that are within a certain distance. The accuracy is rate fairly high between 2cm and 20 feet assuming the objects are solid and can reflect the signal. Using Processing software, I could read the data from the signal sent through the USB to illustrate the distance by the size of a blue circle. For more information, see Arduino Meets Processing.





The initial use of this sensor was to attach to a transistor-type switch to electronically release the shutter on my camera. See how the switch work here. I programmed the microcontroller to sense objects within four to twelve inches and send power to pin 13. The breadboard receives the power sending it to the base of the transistor. This in turn allows voltage to flow through and “flip the switch. Correctly placed leads from the camera jack shorts the circuit and releases the shutter. See prototype below. I used a LED to ensure the power was working correctly





Below is the schematic for the Arduino and the electronic switch.



The code to upload to the Arduino to interface with the Ping))) sensor is below.
It detect objects between four and twelve inches and sends power to pin 13.





/* Ultrasound Sensor
*------------------
*
* Reads values (00014-01199) from an ultrasound sensor (3m sensor)
* and writes the values to the serialport.
*
* Initial code design was by:
*
* copyleft 2005 Mackie for XLAB | DojoDave for DojoCorp
* Modified by Josiah Leverich 3/27/2009
*/
int ultraSoundSignal = 7; // Ultrasound signal pin
int val = 0;
int ultrasoundValue = 0;
int timecount = 0; // Echo counter
int ledPin = 13; // LED connected to digital pin 13

void setup() {
Serial.begin(9600); // Sets the baud rate to 9600
pinMode(ledPin, OUTPUT); // Sets the digital pin as output
}

void loop() {
timecount = 0;
val = 0;
long duration, inches, cm;
pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output

/* Send low-high-low pulse to activate the trigger pulse of the sensor
* -------------------------------------------------------------------
*/

digitalWrite(ultraSoundSignal, LOW); // Send low pulse
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(ultraSoundSignal, LOW); // Holdoff
/* Listening for echo pulse
* -------------------------------------------------------------------
*/

pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
val = digitalRead(ultraSoundSignal); // Append signal value to val
while(val == LOW) { // Loop until pin reads a high value
val = digitalRead(ultraSoundSignal);
}

while(val == HIGH) { // Loop until pin reads a high value
val = digitalRead(ultraSoundSignal);
timecount = timecount +1; // Count echo pulse time
}

/* Writing out values to the serial port
* -------------------------------------------------------------------
*/

ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue

Serial.write('A'); // Example identifier for the sensor
Serial.print(ultrasoundValue);
Serial.write(10);
//serialWrite(13);

/* Lite up LED if any value is passed by the echo pulse
* -------------------------------------------------------------------
*/

/* Delay of program
* -------------------------------------------------------------------
*/

delay(100);

// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
//pinMode(ultraSoundSignal, INPUT);
//duration = pulseIn(ultraSoundSignal, HIGH);

// convert the time into a distance
inches = microsecondsToInches(ultrasoundValue);
Serial.print(inches);
Serial.print("in, ");





if (inches >= 4 inches <=12){

digitalWrite(ledPin, HIGH);

delay(500);
digitalWrite(ledPin, LOW);
}
else {
digitalWrite(ledPin, LOW);
}

}


long microsecondsToInches(long microseconds)
{

return microseconds / 29;
}