1. Trang chủ
  2. » Công Nghệ Thông Tin

Practical Arduino Cool Projects for Open Source Hardware- P27 ppt

10 239 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

C H A P T E R 13    Weather Station Receiver The incredible popularity of home weather stations shows that it’s not just farmers who are interested in the weather. Many people want to be able to track and record weather events within their local environment rather than relying on a state or national weather service that may not have adequate local details. Home weather stations typically consist of two major parts: the sensors that sit outside your home and measure temperature, wind speed and direction, humidity, rainfall, and barometric pressure; and the display unit that lives inside your home so you can read the external temperature while sitting around the fire warming your feet and deciding whether it’s too cold to go fishing. Generally, the external sensors connect together with cables, with one sensor also acting as a transmitter to send updates wirelessly to the display unit. Figure 13-1. La Crosse weather station installed on a roof 239 CHAPTER 13  WEATHER STATION RECEIVER Many weather stations transmit their data at approximately 433MHz using a band reserved for low- power unlicensed use, which is ideal from a hacker’s perspective because 433MHz receiver modules are commonly available for about $10 and can be easily interfaced with an Arduino to let you eavesdrop on the data feed. In fact, it’s not just weather stations that use this approach: many short-range wireless devices work on the same 433Mhz band, so the techniques used in this project can be just as easily applied to intercepting data from other devices such as domestic power-consumption monitoring systems. Best of all, there’s no modification required to the original device because it just transmits its data as usual, not even aware that it’s being received and interpreted by another device. This project is essentially an exercise in listening to an unknown wireless data feed and converting the raw stream of data into values that make sense. Figure 13-2. Weather station sensors and transmitter being installed Once you can receive the data and process it in your Arduino, there are a wide range of things you can do with the information: you can simply display it as it updates, or you can log the readings and generate reports of trends over time, or you can even use it as the basis for making decisions such as sending rainfall data to an irrigation system to minimize water usage. For this project we used a weather station from La Crosse, a popular brand that seems to be available in many parts of the world, but the same approach should work with other brands, as long as you can work out the data format.Many weather stations (including the La Crosse model we used) come with a serial interface on the display unit to feed data to a PC, but by doing the work directly in an Arduino with a receiver module, you don’t even need the display unit at all and gain far more control over what you can do with the data. And because many weather station sensors are available individually, you might find you can buy just the sensors you want and save some money compared to buying a complete system while also gaining the flexibility of managing the data through an Arduino. You can see the required parts in Figure 13-3 and the schematic in Figure 13-4. 240 CHAPTER 13  WEATHER STATION RECEIVER Parts Required 1 Arduino Duemilanove, Arduino Pro, Freeduino, Seeeduino, or equivalent 1 Prototyping shield 1 RXB1 433MHz receiver module (also known as ST-RX04-ASK) 2 680R resistors 1 1K resistor 1 Red LED 1 Green LED 1 100nF monolithic capacitor 1 33cm hookup wire 1 Weather station. For our system we used a complete La Crosse (www.lacrossetechnology.com) WS-2355 Weather Station package, but you can also buy sensor modules individually including: Integrated thermo/hygro/transmitter module, part number WS-2300-25S • Rainfall sensor, part number WS-2300-16 Wind speed and direction sensor, part number TX20 Source code available from www.practicalarduino.com/projects/weather-station-receiver. • As an absolute minimum you will need a transmitter module either purchased individually or provided as part of a kit. The other sensors then use cables to connect to the transmitter module, which reads values from them and transmits the readings on their behalf. 241 CHAPTER 13  WEATHER STATION RECEIVER Figure 13-3. Parts required for Weather Station Receiver Figure 13-4. Schematic of Weather Station Receiver 242 CHAPTER 13  WEATHER STATION RECEIVER Instructions Test and Install the Weather Station Before you do anything else, you should start by assembling your weather station following the manufacturer’s instructions and make sure it works with the original receiver/display module. You don’t need to actually fit it to your roof yet, but at least plug it all together, put in the batteries, and check that the receiver sees values coming back from the sensors. La Crosse systems start up in a “rapid-update” mode where they transmit sensor data very frequently for the first 15 minutes or so of operation to make it easy to test. After that, they drop back to a power-saving mode where they only send updates about every five minutes, so if it looks like things are working initially and then the updates unexpectedly stop, don’t panic. The system hasn’t broken. It has probably just gone into low-power mode and you need to wait longer for each set of data to come through. You can switch it back to rapid-update mode by popping out a battery from the transmitter and putting it back in again, but each time you do that you then need to press the reset button behind the receiver/display module so it can reassociate with the transmitter. Each transmitter sends a station ID as part of every update. The ID changes randomly each time it powers up, so after it is reset the receiver watches for the first station ID it sees and latches onto it. It then only accepts updates containing that particular ID until the next time it is reset. Understanding the Circuit La Crosse systems transmit their updates on the unlicensed 433MHz band, so this project uses a shield with a 433MHz receiver module (shown in Figure 13-5) to feed the raw data stream to the Arduino where the bitstream is then processed and decoded in software. The shield is, therefore, quite simple and will work perfectly well with other 433MHz projects, while the software is relatively complex and does all the heavy lifting. You can use this exact same shield to process data from a wide variety of devices simply by changing the software on the Arduino. Figure 13-5. RXB1 433MHz receiver module The schematic shows that, electrically, it’s quite a simple system, but there are a few design decisions that might seem counterintuitive. Let’s take a moment to follow through the circuit and understand how it works. 243 CHAPTER 13  WEATHER STATION RECEIVER Most of the work is done by the RXB1 module, which only needs power, ground, and an antenna connected, and it will automatically start pumping a raw bitstream out the data pin for any transmissions it happens to pick up. It has two ground pins and two +5V pins that are connected internally on the module, so you can use whichever one happens to be more convenient for the physical layout of your device. Notice that the receiver module has a 100nF capacitor (usually marked with a “104” on the body) connected directly across the ground and +5V pins. This is known as a “smoothing” or “decoupling” capacitor. It makes sure the receiver module has a clean source of power and minimizes the effect of variable current draw on other parts of the circuit. Decoupling capacitors are often not strictly necessary and the circuit might work perfectly well without one, but they fall into the “good design principle” category so it’s worth understanding why we used one in this project. The power drawn by active components can fluctuate very rapidly. The result of this fluctuation can be voltage “ripple” induced in the supply because the voltage will tend to drop slightly when higher current is drawn, and rise again when the current draw decreases. Putting a small capacitor across the supply rails helps to minimize this effect by storing power when the voltage is high and discharging it back into the circuit when the voltage falls, decreasing the overall fluctuation. To use a mechanical analogy, you can think of it as being a bit like adding mass to an object like a car: more mass gives it more inertia, which makes it tend to maintain its existing position or velocity and respond more slowly to forces attempting to push it in different directions. Decoupling capacitors likewise help stabilize the supply voltage and prevent it fluttering around at the slightest provocation, which can potentially decrease the performance of the circuit. The actual value of a smoothing capacitor is usually not particularly critical so you can substitute a different part with a nearby value if that’s what you happen to have handy, but don’t fall into the trap of thinking that bigger is always better. Depending on the frequencies involved, a capacitor that is too large might not be able to follow the transients quickly enough and, therefore, give minimal benefit. A capacitor that is too small, on the other hand, will not store enough energy to ride out the low-voltage part of a ripple and will fully discharge its energy before the voltage begins to rise again. In some circuits it can be necessary to use several smoothing capacitors of different capacities connected in parallel to damp out ripple occurring at different frequencies. It’s a good principle to place decoupling capacitors as close as possible to the device they are protecting, and many circuits using high-speed logic have a capacitor mounted next to every single active component. Typical computer motherboards can have hundreds of them. When you look at the schematic for such a circuit it may look redundant to have dozens of identical capacitors all connected in parallel between ground and VCC in different places, but by having each smoothing capacitor physically located next to an active component on the board they each help to decouple the associated component from supply fluctuations. This approach provides an overall capacitance value equivalent to a large capacitor, while maintaining the frequency-response benefits of a small capacitor. As a general rule of thumb a 100nF capacitor is a good value to use in a typical digital circuit, and you’ll find that many experienced engineers and experimenters buy 100nF monolithic capacitors by the hundred so they always have plenty on hand to use in just about everything they build. The second design decision is one that might seem a bit backward at first: connecting the indicator LEDs between Arduino outputs and +5V. What this means is that to turn on one of the LEDs the associated output must be set low; to turn it off, the output must be set high. This seems to be the opposite of what you might expect, particularly if you come from a software background and years of experience have drilled into your head that TRUE, 1, HIGH, and ON are conceptually similar and mean “yes,” while FALSE, 0, LOW, and OFF are conceptually similar and mean “no.” Sending an output high to turn it off and low to turn it on just feels intuitively wrong. You’ll come across this “inverted” logic in many circuits, and there are good electrical reasons for it. In this particular project it would work just as well with the LEDs connected through to ground so that the outputs could be driven high to turn them on, but we want to get you into good habits as early as 244 CHAPTER 13  WEATHER STATION RECEIVER possible even if it does feel a little uncomfortable at first. And this gives us a good excuse to explain why many engineers prefer to do it this way! The output pins on a chip such as an ATMega CPU are rated to source (supply) or sink (accept) up to a certain limited amount of current. Sourcing current means supplying current to pass out through the pin of the chip and then through the load (a resistor and an LED in this case) to ground. Sinking current means having current come from the +5V supply and then through the resistor and LED, then into the pin, and from there straight to ground inside the IC (see Figure 13-6). Figure 13-6. Sourcing versus sinking current In many chips the sink current rating is considerably higher than the source rating because inside the chip itself there is a relatively large transistor that switches the pin directly to ground, and sinking current to ground, therefore, puts very little load on the IC itself. When switched low, the pin basically becomes simply a short-circuit to ground and quite high currents can pass through it without affecting the rest of the chip. Many chips can, therefore, sink much more current than they can source. In the case of an ATMega we don’t get this particular benefit because it’s limited to 40mA per pin plus a combined limit of a total of 200mA across all the I/O pins, and the sink and source current ratings are identical. Most of the time you would never even notice or care if loads you control cause micro variations in the internal voltage of the CPU, but sometimes it can come back to bite you when you least expect it. For example, when measuring the level of an analog input the IC uses a carefully calibrated internal reference voltage for its ADC (Analog-to-Digital Converter) circuitry, but if you’re also switching an LED or other load at the same time, the supply rail could experience enough jitter that the readings on the analog input will degrade. Not having a consistent reference voltage can seriously impact analog inputs because, for the CPU, it’s like trying to measure something with a ruler made of rubber: if everything is holding still you can use it just fine, but if the ruler is being alternately stretched and contracted very rapidly by even a small amount it’s very hard to get a good reading. So having external loads connected to their own supply rails (possibly even with independent smoothing capacitors) and just using the CPU to switch them to ground is generally a good habit to get into, even when you’re dealing with relatively low-current loads such as LEDs. The third design choice that might seem strange is the value of the current-limiting resistors on the debug LEDs. Most LEDs are designed to operate at a current of around 15 to 20mA and drop about 1.8V. 245 CHAPTER 13  WEATHER STATION RECEIVER For a 5V supply, a typical value for a current-limiting resistor in many circuits would be somewhere in the region of 220 to 330R. However, we’ve specified 680R resistors, which will result in a current limit of just 5mA. The reason once again is to limit the load on the CPU by drawing no more current than we absolutely must. Because those LEDs are purely for debug purposes and not for general day-to-day use of the device, there’s no need to make them full brightness. A typical LED will still glow quite strongly on just 5mA of current. If you are using LEDs as part of a user interface you would normally tune them up to full brightness using resistors around 330R, but for our purposes that’s just not necessary. Instead, we elected to save a little bit of load at the expense of LEDs that aren’t as bright as normal. The mantra to keep in your head is that you shouldn’t use power if you don’t really need it. Use just the minimal amount to get the job done and not a milliwatt more. The result will generally be a more stable overall system with less voltage fluctuations, and decreased chance of interference or other unwanted interaction between different parts of the circuit. The fourth puzzling design choice is the inclusion of the 1K resistor to connect the data pin of the receiver module to the input pin of the Arduino. Once again, this is something that is entirely optional, but it falls into the “good design principle” category: the 1K resistor is low enough in value that it won’t impede the flow of data, but it provides a bit of extra safety by acting as a current-limiter between the two different parts of the system. With the 1K resistor in place, the current flowing between the receiver and the CPU can never be more than a few milliamps, even if one or the other has a major malfunction. The circuit will work perfectly fine with a direct jumper in place instead of the resistor, but for an extra few cents it’s a tiny bit of extra insurance that’s worth putting in. It’s definitely a good habit to get into with your own designs. If you can decouple parts of a circuit simply by including an extra resistor here and there without decreasing the performance of the system, then you might as well do it. Assemble the Receiver Shield Fit the RXB1 433MHz receiver module to the prototyping shield and connect one of the ground pins (2, 3, or 17) to GND on the shield. Note that even though the module only has a total of 8 pins, the manufacturer numbers them as if the board was fully populated from end to end as a SIP (Single Inline Package) device, so the first four pins from the left are numbered 1 through 4, and the four pins on the right are numbered 14 through 17. Pins 5 through 13 simply don’t exist on the package (see Figure 13-7). Figure 13-7. RXB1 pinout 246 CHAPTER 13  WEATHER STATION RECEIVER On the SparkFun prototyping shield we used for this project, the RXB1 gave us a bit of a problem because it is the equivalent of 17 pins long while the pad area on the shield is only 16 pins long. However, this problem was easily solved by bending pin 17, the ground pin on the extreme right end, up out of the way. Because the ground connection is replicated on pins 2, 3, and 17, we can just use one of the other ground pins instead and leave pin 17 unconnected. Keep in mind, though, that sometimes there is a good reason for radio-frequency devices to provide several ground connections such as to squelch internal ground loops. Leaving the extra ground pin unconnected could marginally decrease the sensitivity of the receiver, but in our testing it worked just fine with only one ground connection. The RXB1 receiver is a 5V module and pulls a tiny 3mA in operation, so connect either of the VCC pins (4 or 14) directly to the +5V connection on the shield. On our prototype we used pin 4. Also install the 100nF monolithic capacitor between the adjacent GND and VCC pins (3 and 4, respectively) as a decoupling capacitor to help keep the supply rail clean as discussed previously. In Figure 13-8 the smoothing capacitor looks like a tiny yellow egg on the left. Figure 13-8. RXB1 receiver mounted on shield To keep things neat, we also installed a PCB-mount header for the antenna connection, visible at the extreme left in Figure 13-8. You don’t actually need to do this, and you could choose to solder the antenna directly to the board if you prefer. Next install the debugging LEDs and their dropper resistors. The green LED connects to Arduino digital I/O pin 6, and the red LED connects to I/O pin 7. Install the two LEDs on the shield and connect the anode (longer) leads to +5V. The other side of the LEDs needs to be connected to Arduino pins 6 and 7 via 680R resistors to limit the current through them, so solder a 680R resistor between each of the cathode (shorter) LED leads and the respective I/O pads on the shield. Note that it doesn’t actually matter whether you have the dropper resistor on the +5V side of the LED or on the ground side: on our prototype board we connected the LEDs directly to +5V and then used the resistors to connect the other side of the LED to the Arduino pin, simply because it made mechanical sense when laying out the board. However, you could just as easily have them installed in the other order (see Figure 13-9). Data received by the RXB1 module is made available on both pins 15 and 16. Given the orientation of the receiver module it would seem to make sense to connect one of those DATA pins to an Arduino digital I/O pin somewhere down that end of the shield, perhaps pin 2 or pin 3. For many projects using the RXB1 module you can do that and it will work perfectly well, but this project is a little different because the software in the Arduino will be detecting transition edges in the received signal and measuring the timing to convert the raw signal into data. Unfortunately, that means we can’t just open a serial connection and read values from the data line. Instead we have to connect it to pin 8, which has special functionality because it’s connected to pin PB0 on the ATMega CPU. This pin is also designated ICP1, for Input Capture Pin. The ATMega supports extremely accurate timing of signal transitions on ICP1, down to the region of only a couple of clock cycles—perhaps a microsecond or so. We’ll make use of that capability in the program to decode the data stream. 247 CHAPTER 13  WEATHER STATION RECEIVER Figure 13-9. The LED on the left and the LED on the right are functionally equivalent circuits Install a 1K resistor with one end connected to receiver pin 15 or 16 and the other end running across to Arduino digital pin 8 (see Figure 13-10). Figure 13-10. LEDs, dropper resistors, data connection resistor, and power connections in place 248 . number WS-2300-16 Wind speed and direction sensor, part number TX20 Source code available from www.practicalarduino.com /projects/ weather-station-receiver. • As an absolute minimum you will. through an Arduino. You can see the required parts in Figure 13-3 and the schematic in Figure 13-4. 240 CHAPTER 13  WEATHER STATION RECEIVER Parts Required 1 Arduino Duemilanove, Arduino. reserved for low- power unlicensed use, which is ideal from a hacker’s perspective because 433MHz receiver modules are commonly available for about $10 and can be easily interfaced with an Arduino

Ngày đăng: 03/07/2014, 20:20

Xem thêm: Practical Arduino Cool Projects for Open Source Hardware- P27 ppt

TỪ KHÓA LIÊN QUAN

Mục lục

    Contents at a Glance

    About the Technical Reviewers

    Practical Electronics for Software Developers

    Current, Voltage, and Power

    Ohm’s Law and Current Limiting

    Test and Investigate Appliance Remote

    Assemble Reed Relay Shield

    Connect Reed Relay Shield to Remote Control

    Create Reed Relay Control Program

    Test Reed Relay Shield and Sketch

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN