Since I wasn't up to retesting the HDR function at Wayside today, I've decided to do a little bench work and incorporate a light sensor. It seems that light-based triggers are a common project for people interfacing a camera to a microcontroller, and for very good reason.. both infrared and visible light triggering can be very useful in photography. No exceptions here, and we're going to use a very simple and flexible interface which will allow for use of several types of sensors with minimal headaches.
The circuit itself really could not be more simple:
Basically, we're just going to create a voltage divider. Think of it this way: the balance between adjustment resistor and the sensor controls how much of the 5 volts goes to the analog port and how much gets dumped to ground. We'll use a variable resistor (a potentiometer) for the Adjustment Resistor, to obtain some working values. This adjustment resistor will account for varying response curves of various components, and allow us to tweak our build a bit. We'll be coming back to that adjustment resistance in the future.
For our first run at this, I'll use an Infrared Phototransistor. This is sold by Radio Shack as part of an emitter/detector pair with part number 276-0142. I try to use very common and inexpensive components.. nearly any part I use is available at Radio Shack or other hobby electronics retailers. Keep the emitter around, we'll be having some fun with that too. Virtually any phototransistor will work, they just vary in terms of sensitivity and frequency range.
The phototransistor from the Radio Shack emitter/detector pair is about as basic as you can get, peaks out sensitivity-wise around 850nm, and is easy to use. Simply put, configured as we have got it, the phototransistor will allow a varying voltage to reach the microcontroller's Analog Pin 0 based upon the amount of light falling on it. For the initial value of the adjustment resistor, I had a 15k ohm handy, which was enough for starters. The 15k resistor was replaced with a potentiometer to judge the effects with a number of different sensors, as we'll see.
Now all we need is a little code to test it out. Happily, the Arduino IDE has "AnalogInSerialOut" as the first sketch in the code snippet library. We'll just load that up and open the Serial monitor to see the values being produced. That's all the usefulness we'll get from the sketch at the moment, but it's an easy interface to visualize the data so you can test. Of course, you can write your own sample-and-send-to-serial sketch also.. but I am tremendously lazy and am happy with kludges as long as they work. For reference, a "kludge" is a term used to discuss technical solutions which are by no means pretty or the right way- but they work. In some ways, Arduino is a huge kludge- it'll get the job done, but a purist may look on with disgust because we aren't developing in Assembler. In the end, if our project works.. it's the right answer, in my opinion. Maybe if this were a commercial product, but I see no reason to make life any harder than we have to for ourselves.
No comments:
Post a Comment