Step 18Sensors
When you use mode to cycle through the options, you will be presented with one more - triggered shooting. The first screen displays a real-time readout of what the ADC is "seeing", this gives you a basic idea of what sort of values you're "hitting" and how changing the environment will affect them. Pressing the shoot button will let you set what the controller will trigger on. As the ADC goes up to 1024, the maximum you can enter is 1024. To the left of the numbers is the operator - you can set it to >( greater than), < (less than) or = (equal to). This allows a lot of flexibility with shooting, you can pick to take a picture when a light turns on or off, or if you are using a precisely controlled sensor (such as say a thermometer, god knows why) you can trigger from an exact reading.
I put in two LEDs on my controller to display whether the trigger is currently producing a match. This has two benefits. One, you can test out your sensors before you do the shoot and secondly you can avoid ambiguous conditions. For instance, microphones will often fluctuate around some central value (because sound is effectively a superposition of sine waves - see fourier analysis). This value is normally 512 ish on my ADC (as expected). If you have two lights displayed, you can be sure that as soon as you shoot, it'll trigger. If you have a red light only, then you can be more sure that you won't get a false shot. And of course, a green light means that the condition is met so you should adjust accordingly. With a sound sensor, adding a pot will let you alter the gain of the microphone so you can "filter" (you're changing the gain of the opamp) out quieter sounds.
Wire up an LED to pin 24 and another to pin 23 with a reisistor in series to limit the current. Go as dim as you feel you need, low power is important. I chose to have green on PC1 (23), red on PC2 (24.
Pressing shoot again lets you set a delay, up to 999ms (though you could always add in support for more). This is handy for taking pictures of impacts a few milliseconds after the event happens - creative control, you might say.
Pressing shoot a final time will set the device going. The ADC will update a bit more frequently and when the sensor gets a condition match, the preset delay starts and the picture is taken after that (with confirmation on the screen).
Sensors
There are two main sensors we can use. The first is light. This is terribly simple:
Connect a light dependent resistor or photodiode (faster reaction time generally) up to VCC and then in series with a resistor to ground. Connect a wire going from between the LDR and the resistor to the ADC input pin. Pick a resistor that matches the maximum resistance of your LDR (you can test it with a multimeter). You should end up with a value that ranges from almost 1024 to zero depending on the brightness of the light. If you put the LDR and resistor in the right way round, the value should be zero when you cover the component and large when you shine a bright light - a laser gives a very high value that is roughly constant.
Some applications of this include things exploding, laser tripwires or (the most fun) lightning.
Sound takes a bit more fiddling. For the sound sensor, i used an electret microphone. Electret condenser mics are found in just about anything that has records sound. They pick up a wide range of frequencies so are pretty good for this. The only problem is that they typically produce an output signal that is far too small to detect by the ADC (minimum of 5mV). So, we need to amplify it.
There are a lot of circuits online dealing with electret amplification, however, the method i found to be most reliable was using an Op-Amp. The ideal opamp has unlimited gain, so don't worry about it not being able to amplify enough (the average opamp has an open loop gain of somewhere around 10 to the 8)! I built a really simple non-inverting amplifier using a TL072 (shown in the schematic). The resistor going from the output to the non-inverting input controls the gain. I tried a gain of 100 - little to no effect. Upping this with a 470k resistor (gain of 470) i got slightly better results, clapping fairly loudly triggered the sensor. Upping this to 1MOhm produced excellent (if perhaps a bit too sensitive) results.
Remember that gain is Vout/Vin, controlled by the ratio of GAIN_CONTROL/R1, so 1M/1k gives a gain of 1000.
What i recommend is buying a 1M potentiometer and a 100K resistor. Put these in series between the output and the non-inverting input. This will be the gain control. The 100k minimum resistance provides a decent starting point, triggering on loud sounds. By upping it to 1.1M, you get a much higher sensitivity - triggering from whispers and the smallest sounds (you may find that it's hard to actually trigger on high sensitivity unless you've got a really quiet room - my computer fans were enough to set mine off). By all means fiddle until you get a decent resistance range. Sadly it is quite hard to get potentiometers over 1M cheaply, but you can buy up to 5M if you really want to push it.
The opamp can be powered from the +5V rail (as can the electret) or from a separate 9V battery. Power the electret from the 5V line, you can use more but be sure to check the datasheet of your opamp to see what the maximum output voltage will be - you don't ever want to give an input to the AVR of more than 6 volts - and it is a waste to give anything over 5 anyway (since the sensor is only 10-bit). Opamps have what is called a swing voltage, the range over which they'll produce an output. This is normally the input voltage minus a couple of volts either end. So, for me with a 5V power rail, i end up triggering on around 600-700 - the opamp simply doesn't produce a larger output. This is where adjustable gain comes into it.
You should adjust the gain so that the condition LED you want only just turns off/on (say you want >600, you'd change the pot slowly so that the green LED just turns off). This ensures you'll have a good chance of triggering properly.
Also, don't forget to put a resistor in series with the positive mic pin (between VCC). If you don't, you'll blow it.
You can simply copy the design below, shown as both schematic and breadboard. Other websites have reported much better results with a lot less gain, so take my results with a pinch of salt (i may be missing something obvious). Fiddle and see how you get on, the circuit is a well known opamp circuit and feel free to experiment, this is just a quick and dirty amplifier.
Diagrams are provided below for both sensors. Replace the GAIN_CONTROL resistor with a variable resistor or a potentiometer ideally. The opamp is powered by the 5V rail.
C2 is a bit hard to see, but it is 100n.
If you wish to test the ADC separately, there is source code for it - however - the ADC will show you its current value when you load up the trigger menu anyway.
sensors.sch194 KB| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|


























































