STEP 3: MAKE THE CAMERA SAFE!
Before you have rendered the camera module safe, treat it the same way you would a small but vicious rodent. Don’t handle it directly. If you need to move it around or flip it over, poke it with something like a plastic pen. Otherwise, you might injure yourself, and you need to be in top condition to stay ahead of the zombies.
Identify the flash module’s capacitor. The capacitor will be a large metallic cylinder with two leads connecting it to the PCB. The capacitor stores all the energy that is rapidly discharged into the flash to set it off. In Figure 9-5, the entire flash module has been removed from the camera body to make it easier to see the capacitor, but follow the capacitor discharge steps below without removing the whole PCB if you can.
Figure 9-5: Discharging the capacitor
To discharge the flash module’s capacitor, bend the legs of your 100 Ω resistor so they are roughly as far apart as the legs of the capacitor. Gently grip the body of the resistor with pliers (with insulated handles) and touch the resistor leads across the capacitor leads. If the capacitor is charged, there will probably be a very small spark. Hold the resistor in place for a second or so to make sure the capacitor actually discharges.
Now, check whether the capacitor is empty by measuring the voltage with your voltmeter set to its maximum DC voltage range. (The voltage range needs to be 500V or more.) It doesn’t matter if there are a few volts left in the capacitor, but if you see more than 10V, then discharge it a bit longer with the resistor. Once the voltage is below 10V, it is safe for you to handle the PCB without fear of electrical shock.
STEP 4: ATTACH LEADS TO THE TRIGGER CONTACTS
Solder about 6 inches (15 cm) of double-core wire to the flash contacts, as shown in Figure 9-6. In the camera I used, there was a handy plastic peg that allowed the two contacts to be kept well apart. If this is not the case for your camera, then you may need to wrap the soldered contacts in electrical insulating tape or put heatshrink over the contacts to keep them apart.
Figure 9-6: Leads soldered to the trigger contacts
STEP 5: REASSEMBLE AND TEST THE MODIFIED FLASH MODULE
Fit the front cover of the camera back on, allowing the double-core wire to escape through one side of the camera. If you need more space to snake the wires out, use a pair of diagonal cutters to cut a hole in the plastic cover.
Test this flash before repeating the procedure for the other two cameras. The trigger contacts of these cameras are sometimes at 400V, so for safety, use a screwdriver with an insulated handle.
Turn on the flash switch for the camera. You should see a charging light or LED come on. The camera will probably make a whining noise as the flash charges. This sound is created by the capacitor filling up. When you think the charging is complete (or after, say, 10 seconds), use the screwdriver to connect the two trigger leads, as shown in Figure 9-7.
The camera should flash when you connect the leads with the screwdriver. Hurray! That’s one camera ready for action. Before moving on to Step 6, repeat Steps 2 through 5 for the other two cameras.
Figure 9-7: Testing the modified camera
STEP 6: CONNECT THE CAMERAS TO THE RELAY SHIELD
Fit the relay shield onto your Arduino, making sure that all the pins of the shield engage properly with the sockets on the Arduino.
Figure 9-8 shows how the cameras are wired up to the relay shield.
Figure 9-8: Attaching leads from the cameras to the relay shield’s trigger contacts
Each relay on the relay shield has three screw terminals: NO, COM, and NC. When the relay is not activated, the terminals NC and COM are connected, but when the relay is activated, COM becomes connected to NO. This means that the leads to each camera need to go into the COM and NO connections of each relay. It does not matter which way around the leads go.
When your cameras are connected to their relays, attach the battery clip–to–barrel jack adapter to the Arduino, as shown in Figure 9-9.
Figure 9-9: Attaching the battery lead to the Arduino
Before attaching the battery itself, however, you need to upload the software for the project, so you may as well power the Arduino from the USB lead while you program it.
SOFTWARE
All the source code for this book is available at http://www.nostarch.com/zombies/. Visit the link provided there and download the code now, if you’ve not done so already. See Appendix C for instructions on how to install the Arduino sketch.
The Arduino sketch for this project is called Project_15_Flasher, and it’s in the source file directory of the same name. I’ll walk you through this sketch now.
To begin, we define a constant integer array, flashPins:
const int flashPins[] = {7, 6, 5};
The flashPins array defines the Arduino pins used to trigger each of the flash modules. Change these pin numbers if your relay shield uses different pins to control the relays.
Next, we define two more constants, which you can alter to adjust the zombie distractor:
const long overallDelay = 20; // seconds
const long delayBetweenFlashes = 1; // seconds
The overallDelay constant determines how many seconds elapse between each flashing cycle. This value is set to 20 seconds by default. Note, this delay needs to be long enough to enable the capacitor inside the camera to recharge.
The delayBetweenFlashes value sets the gap between each of the flashes being triggered in a cycle. This is set to one second by default. Note that both constants are long rather than int. That’s because int constants have a maximum value of +/–32,767, which would give a maximum delay of 32.767 seconds; that might not be long enough to keep a zombie distracted while you escape. Fortunately, the long data type has a maximum value of over +/–2,000,000. You can run a long way in 2,000 seconds!
Now we add a setup function:
void setup()
{
pinMode(flashPins[0], OUTPUT);
pinMode(flashPins[1], OUTPUT);
pinMode(flashPins[2], OUTPUT);
}
The setup function sets all the relay pins to be digital outputs.
With the pinMode functions in place, we add a short loop function:
void loop()
{
flashCircle();
delay(overallDelay * 1000);
}
This loop function calls the flashCircle function and waits for overallDelay seconds before starting the whole process again.
Let’s look at the flashCircle function definition now:
void flashCircle()
{
for (int i = 0; i < 3; i++)
{
digitalWrite(flashPins[i], HIGH);
delay(200);
digitalWrite(flashPins[i], LOW);
delay(delayBetweenFlashes * 1000);
}
This function loops over the flash pins and gives each a HIGH pulse for 200 milliseconds, setting off the flash. There is then a pause before the next flash, set by delayBetweenFlashes. The value of delayBetweenFlashes is multiplied by 1,000 because in Arduino, the delay function’s parameter is in milliseconds.