7

ENVIRONMENTAL MONITORING

image

Zombies are pretty frightening, but they’re not the only threat in a postapocalyptic world. More mundane risks like fire are especially serious if you can’t safely leave your compound (see Figure 7-1). In this chapter, I’ll show you how to build a fire alarm and a temperature alarm that alert you to environmental hazards—without alerting the zombies.

image

Figure 7-1: No smoking!

PROJECT 11: QUIET FIRE ALARM

Normally, you want a fire alarm to be as close to you as possible and as noisy as possible. But there’s one problem with loud alarms: zombies can hear. The last thing you want when escaping a burning building is to attract unwanted attention from passing zombies!

This project modifies a regular battery-operated smoke detector so that it registers an alarm on the Arduino display and sounds a much quieter buzzer, using the basic setup from “Project 4: Battery Monitor” on page 53. Figure 7-2 shows the smoke detector connected directly to the screwshield.

image

Figure 7-2: Testing the finished fire alarm. In your base, the detector will be connected to the Arduino by a long lead.

WHAT YOU WILL NEED

To make this project, you’ll need the Arduino and screwshield that you used in “Project 4: Battery Monitor” on page 53 as well as the following parts:

ITEMS

NOTES

SOURCE

image Smoke detector

Battery operated

Hardware store, Supermarket

image Cable

Double core and long enough to reach from the smoke detector to the Arduino

Scavenged speaker or bell cable is good for this.

image D1

1N4001 diode

Adafruit (755)

image R1

1 kΩ resistor

Mouser (293-1k-RC)

image LED1

Blue or white LED

Adafruit (301)

image C1

100 µF capacitor

Adafruit (753)

image Solid-core wire

2 inches (5 cm) long

Abandoned electronics, Adafruit (1311)

Be sure to use the LED colors I recommend, as I don’t suggest blue or white LEDs just because they look cool. For this project’s circuit to work, the LED needs to have a forward voltage of more than about 2V. Red and green LEDs often have a forward voltage of about 1.7V, but blue and white LEDs have a much higher forward voltage of around 3V, which is perfect.

CONSTRUCTION

To adapt the smoke detector to communicate silently with the Arduino, you’ll disconnect the detector’s buzzer from its circuit board and then change the signal that would go to the buzzer into a signal the Arduino can use. You’ll condition the buzzer signal by sending it through the circuit (Figure 7-3).

image

Figure 7-3: Schematic for the fire alarm

A typical smoke alarm is really loud because its buzzer is driven with the highest possible voltage the circuit can wring out of a little 9V battery. This means that for most alarms, the signal on the buzzer looks something like the chart on the left of Figure 7-4.

image

Figure 7-4: Taming the buzzer signal for Arduino is much easier than taming a zombie!

The buzzer is driven by an alternating current (AC) square wave, with a voltage that swings from +9V to –9V at roughly 600 times per second. This causes a piezo element to alternately expand and contract, generating the buzzing sound. But this voltage swing is too wild for the Arduino, which can be damaged by inputs greater than 5V or less than 0V.

The circuit to convert the buzzer signal begins with the diode D1, which completely prevents the negative voltages from reaching the rest of the circuit (diodes only allow current to flow in one direction). The resistor limits the current flowing to the LED, which limits the voltage across the LED to about 3V. The capacitor gets rid of any voltage spikes and smoothes out the signal to something like the chart on the right in Figure 7-4.

STEP 1: DISCONNECT THE BUZZER

First, disassemble the smoke detector. When you remove the lid, you should see a PCB and some wires (Figure 7-5).

image

Figure 7-5: Inside the smoke detector

In this smoke detector, the three leads going from the circuit board to the lid are the buzzer leads. Chop off the leads to the buzzer now, but don’t cut too close to the buzzer itself. Resources are scarce during an apocalypse, and you might want to repurpose that buzzer later.

NOTE

You can use the buzzer from your smoke detector to build “Project 16: Arduino Movement and Sound Distractor” on page 169. If you’ve ever been close to one of these smoke alarms when they sound, you’ll know just how distracting they are!

Your buzzer may have two leads or three leads. If it has three, follow Step 2 to determine which lead is which. If it has just two, these are the leads that you will connect to, and you can skip Step 2.

STEP 2: IDENTIFY THE LEADS

If your buzzer has three connections, then your smoke alarm uses a type of piezo buzzer called a self-drive piezo. The third connection is called the feedback connection and is used to make the piezo sound as loud as possible.

For this project, you just want the two drive connections on the smoke detector. Sometimes the wires are color coded; if so, the drive connections will probably be red and black, and the feedback connection might be white (see Figure 7-6) or some other color. But if you have a multimeter, then you can just check which wires are the drive wires and avoid guesswork. Figure 7-6 shows this process in action.

image

Figure 7-6: Identifying the smoke alarm buzzer wires

Strip the ends of all three wires and set your multimeter to its 200V AC range if it’s available on your meter, or at least the 10V AC range. (Yes, I mean AC, not the usual DC.) Connect the multimeter leads to any two of the three wires and measure the voltage as you hold down the contacts of the smoke alarm’s “test” switch. If the meter indicates about 9V, or anything above 4V or 5V, then these are the wires you are looking for; otherwise, try different pairs until you find the correct wires. Note that the project relies on the battery or batteries still being present in the smoke alarm.

STEP 3: SOLDER COMPONENTS TO THE SCREWSHIELD

This circuit has too many components to attach all of them to the screw terminals, so use the prototyping area on the screwshield to solder the components into place. Figure 7-7 shows the wiring diagram for the screwshield; the letters marked will be used later to describe just how to solder this together.

NOTE

For the sake of clarity, Figure 7-7 doesn’t include components from earlier Arduino-based projects that might be hanging off the screwshield.

image

Figure 7-7: Wiring diagram for the screwshield

Holding your screwshield so that it looks like Figure 7-7, push the component legs through from the top of the board. Note that the diode (labeled D1) and LED are polarized, meaning they only work when oriented a certain way. Point the diode’s stripe toward the top of the board. Then place the LED’s longer lead (the positive lead) toward the bottom of the board (Figure 7-7).

When you’ve pushed all the component leads through, flip the board over and solder the leads where they emerge from the hole. (If you are new to soldering, take a look at Appendix B, especially “Soldering a PCB” on page 234.) It may help to bend the leads slightly so that the components don’t fall out when the board is upside down. When all the components are soldered, the underside of the board should look like Figure 7-8.

image

Figure 7-8: Fixing the components in place

Now that the components are fixed, bend the leads and arrange them to make the connections, using Figure 7-9 and the steps below as a guide. (The connections described below are indicated in Figures 7-7, 7-9, and 7-10 with letters.)

1. Bend the top (negative) lead of the LED over so that it lies next to the top lead of C1 and the GND power line on the screwshield (A). Solder the LED lead where it crosses C1 and then where it meets the GND line. Cut off the excess LED lead and the remainder of the top lead of C2.

2. Bend the other LED lead over to run next to the top lead of R1 and the bottom lead of C1 (B). Solder the bottom LED lead at the junctions where it crosses R1 and C1 and cut off the remainders of both the C1 lead and the R1 lead you just soldered to. If there is any remaining LED lead after connecting to R1 and C1, cut that off too.

3. Cut a length of solid-core wire that is long enough to reach all the way from the end of the positive LED that you soldered in Step 2 as far as D3 on the top Arduino connector (C). Strip the ends of the wire (see “Stripping Wires” on page 227). Flip over to the top side of the board and push one stripped end of the wire into a hole next to where the positive LED lead connects to C1 and solder the wire to that junction. Solder the other end of the wire to the solder pad next to Arduino pin 3. Push the stripped end through the hole from the top and solder on the underside.

image

Figure 7-9: The underside of the screwshield, after soldering. The dashed lines indicate wires running on the top of the shield.

4. Bend the bottom lead of R1 over so that it crosses the top lead of D1 (D). Solder these leads together and cut off the excess wire.

5. Use another short length of solid-core wire (or if they are long enough, one of the leads you trimmed off R1) to connect the solder pad labeled X to the bottom GND power line on the screwshield (E).

When this is done, the underside of the board should look like Figure 7-9. The dotted lines represent the wires on the other side of the board.

Next, flip the board over and add a wire to link pin D3 (just marked 3 on the screwshield) of the Arduino to the junction of the capacitor, diode, and resistor. Solder that wire in place. When this is done, the top of the screwshield should look like Figure 7-10.

Now that the board is complete, reassemble the electronics by fitting the display shield back on top of the screw shield and the screw shield onto the Arduino.

image

Figure 7-10: The finished screwshield

STEP 4: CONNECT THE SMOKE DETECTOR TO THE ARDUINO

Finally, strip the buzzer wires if you haven’t done so already, and solder longer leads to them. To make the soldered connections stronger, you could use heatshrink as described in “Using Heatshrink” on page 235. Connect the smoke detector to pins W and X on the screwshield. The wire connecting the smoke detector to the Arduino can be any double-core cable, such as bell wire, but if you plan to use this alarm in your base, just use wires long enough to reach the mounting position. I found that the project worked just fine with 30 feet (10 m) of telephone extension cable.

SOFTWARE

If you want to make this project without any of the other Arduino-based projects in this book, then load the sketch Project_11_Smoke_Alarm from this book’s source files onto the Arduino now. If on the other hand, you’ve built one or more of this book’s earlier Arduino projects, then use the sketch All_Sensors and change the constants at the top to select the projects that you’ve made. See the comments section in that sketch for instructions on the correct changes to make.

NOTE

You’ll find a link to the source code for this book at http://nostarch.com/zombies/. See Appendix C in this book for instructions on loading the programs.

This code builds on the code from Project 4, so for more information on how the program as a whole works, please refer to “Software” on page 57. Here I will just describe the code specific to the fire alarm.

First, we define a new constant for pin D3 on the Arduino:

const int smokePin = 3;

This pin will act as an input for the signal from the smoke detector. After adding the smokePin constant, we add a new line of code to the setup function to initialize this pin as an input:

pinMode(smokePin, INPUT);

Next, we add a call to a new function called checkSmoke to the loop function. The checkSmoke function is defined as follows:

void checkSmoke()
{
  if (digitalRead(smokePin))
  {
    alarm("FIRE!!");
  }
}

The checkSmoke function contains the rest of the code for checking for a signal from the smoke detector and displaying the message and/or turning on the buzzer. To change the display and control the buzzer, call the alarm function, which you first met in “Project 6: PIR Zombie Detector” on page 72:

void alarm(char message[])
{
  lcd.setCursor(0, 1);
  lcd.print("           ");
  delay(100);
  lcd.setCursor(0, 1);
  lcd.print(message);
  if (!mute)
  {
    tone(buzzerPin, 1000);
  }
  delay(100);
}

Unless you press a button to mute (a holdover from Project 4), this function prints your message ("FIRE!!") to the LCD in lieu of that loud, zombie-attracting buzzer.

USING THE FIRE ALARM

Testing the smoke detector is simple: just hold down the contacts of the test button with a screwdriver (see Figure 7-6). This will cause the buzzer to sound and a message to appear on the LCD screen.

When you know the alarm works, place the sensor somewhere close enough to a potential fire that you’ll receive enough advance warning to put out the flames, or at least flee in an orderly manner. Creating a quiet smoke alarm won’t be worth much if you exit in a noisy panic and attract all the zombies on the block!

PROJECT 12: TEMPERATURE ALARM

Since your compound is zombie-proofed, you (hopefully) won’t have to change lodgings often, and over time, you’re sure to acquire some valuable climate-sensitive items. Depending on what you have cached away, you might want to make sure that a generator isn’t getting too hot or that your wine cellar isn’t too cold. To protect these assets that ensure your survival and are good to trade with other survivors, you need a temperature alarm that can notify you of extremes of heat or cold.

This is the final project that uses your now heavily laden Arduino, and Figure 7-11 shows the LCD screen reporting a high temperature in Celsius.

image

Figure 7-11: A fully laden Arduino, complete with temperature sensor (circled), movement detector, smoke alarm, and battery monitor

A three-pin temperature sensor is on the left of Figure 7-11, over the remains of the smoke alarm from Project 11. That sensor will send the Arduino temperature data, which the Arduino will then display as human-readable text.

WHAT YOU WILL NEED

To make this project, you’ll need the Arduino and screwshield that you used in “Project 4: Battery Monitor” on page 53 and the following parts:

ITEMS

NOTES

SOURCE

image TMP36

Temperature sensor

Adafruit (165)

image Three-core wire

To connect the sensor chip to the Arduino screwshield

Scavenged telephone cable or other three-core wire.

image Heatshrink

3 lengths of about an inch (25 mm)

Auto parts store

You could use electrical tape instead of heatshrink for this project, but I recommend heatshrink because it’s a lot tougher and not prone to unraveling.

CONSTRUCTION

Figure 7-12 shows the wiring diagram for the project. The LCD should be attached from an earlier project, so the only new part you’ll add is the TMP36 temperature sensor.

image

Figure 7-12: The wiring diagram for the temperature alarm

STEP 1: MAKE A LONGER LEAD FOR THE TMP36

To extend the lead of the TMP36, you could just solder a three-core wire to it. However, to make it a bit more durable, you can use heatshrink tubing on top of the soldered connections. Figure 7-14 shows the process.

image

Figure 7-14: Using heatshrink on the TMP36 lead

First, strip the wires of each lead and slip the cut lengths of heatshrink over the individual wires (Figure 7-14a). Next solder the wires to the leads of the TMP36 (Figure 7-14b). Slide the heatshrink up over the solder joint (Figure 7-14c) and finally apply a hair dryer or hot air gun to the heatshrink until it, well, shrinks (Figure 7-14d). If you have wide diameter heatshrink, then you could place this around the whole sensor and individual leads to make this build more durable.

NOTE

For more information on using heatshrink, see the “Using Heatshrink” on page 235.

STEP 2: ATTACH THE TEMPERATURE SENSOR LEAD TO THE SCREWSHIELD

Attach the wires from the temperature sensor to the screwshield (Figure 7-11). You don’t have to use the GND connection shown; any of the GND terminals on the screwshield will do.

SOFTWARE

If you want to make this project on its own, without any of the earlier Arduino-based projects, then open the sketch Project_12_Temperature from this book’s source files and load it on to your Arduino now. If, on the other hand, you built one or more of the earlier Arduino projects, then use the sketch All_Sensors and change the constants at the top to select the projects that you have made. See the comments section in this sketch for instructions on this.

NOTE

All the source code for this book is available from http://www.nostarch.com/zombies/. See “Installing the Antizombie Sketches” on page 248 for instructions on installing the programs.

This code follows the same pattern as Project 4, so for more information on how the program as a whole works, please refer to “Software” on page 57. Here, I’ll just describe the code specific to this project.

First, a new constant is defined for the Arduino pin that will act as an analog input for the TMP36:

const int tempPin = A2;

Two more constants are defined to set the maximum and minimum temperatures allowed before an alarm is triggered. These are floats rather than ints because they represent decimal numbers rather than whole numbers.

// Project 12 constants
// these can be in C or F
const float maxTemp = 45.0;
const float minTemp = -10.0;

As the comments above the constants state, these temperature values can be in either Celsius or Fahrenheit. The units that the temperature is measured in are decided by a new function you’ll define.

The main loop function now includes a call to checkTemp, too. This function is defined as follows:

void checkTemp()
{
  float t = readTemp();
  if (t > maxTemp)
  {
    alarm("HOT", t);
  }
  else if (t < minTemp)
  {
    alarm("COLD", t);

  }
}

The checkTemp function first calls readTemp to measure the temperature and then compares that with the maximum and minimum temperatures. If the temperature is too high or too low, then the alarm function is called. Note that this version of the alarm function has an additional parameter that is used to display the temperature on the LCD screen.

The readTemp function is where the raw analog input reading from the TMP36 is converted into a temperature.

float readTemp()
{
  int raw = analogRead(tempPin);
  float volts = raw / 205.0;
  float tempC = 100.0 * volts - 50;
  float tempF = tempC * 9.0 / 5.0 + 32.0;
  // One of the following two lines must be uncommented
  // Either return the temperature in C or F
  return tempC;
  // return tempF;
}

The raw value returned by analogRead is a number between 0 and 1023, where 0 indicates 0V at the analog input pin and 1023 indicates 5V. This voltage is calculated by dividing the raw value by 205 (205 is roughly 1023/5).

The temperature in degrees Celsius is then calculated using the formula described in “TMP36 Temperature Sensor” on page 133, as the voltage multiplied by 100 with 50 subtracted from the result. The temperature in degrees Fahrenheit is also calculated.

Finally, one of these two values has to be returned. In this version of readTemp, the line to return tempF is commented out, so the temperature in Celsius will be returned. If you want to flip this, then comment out the line return tempC and un-comment return tempF so that the last three lines of the function look like this:

  // return tempC;
  return tempF;
}

To test the sensor, try changing the value of the maxTemp constant to just above the room’s temperature, load the updated sketch onto the Arduino, and then squeeze the temperature sensor between your fingers to warm it up. Watch the LCD, and the readout should change.

USING THE TEMPERATURE ALARM

There’s a limit to how much distance you can put between your temperature sensor and your Arduino. You could make the lead you attach to the TMP36 as long as 20 feet (7 m), but the sensor will become less and less accurate as the lead gets longer due to electrical noise on the line and the resistance of the wire.

Leave the sensor near the item you want to stay at a certain temperature and watch the LCD. If that wine cellar just won’t stay cool enough, try setting up the sensor in different rooms in your base until you find one with the right climate. If there isn’t a good room for the wine, just put the sensor back on your generator, invite the other survivors in your area over for a drink, and have an antizombie strategy meeting.

Now that you have a bunch of sensors to warn you of dangers in your base, in the next chapter, you’ll combine the Arduino projects with a Raspberry Pi to make a control center.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset