• Tidak ada hasil yang ditemukan

Smarten Up!

Dalam dokumen Practical AVR Microcontrollers (Halaman 160-172)

Smarten Up!

This book deals with making things that are provided with embedded intelligence. My hope is that this book will inspire you to develop your own ideas to enhance projects discussed in these pages, and that you will go on to design and build your own projects for many years to come. If you’re new to electronics, or you’ve never dealt with programmable devices before, you may wonder why this approach is better than just using single-purpose devices. So, it seems only fair to prime the pump by looking at some basic ideas about embedded intelligence.

Why would we want it? What does it buy us? Where is it useful, and does it have a dark side?

So, in this chapter, we are going to look at the benefits of building in intelligence to things around us. We’re going to see why we do it, how we do it, and how to avoid some traps of overimplementation and assumption.

We’re also going to look at the benefits of connecting intelligent devices, and throughout we will look at some concrete examples applicable to home automation. Some of those ideas are incorporated into buildable projects later in this book.

Intelligent Devices

Clearly, since everything from jumbo jets, the cars we drive, festive lighting rigs, and even birthday cards now contains programmable controllers, there must be benefits to having microcontrollers built into things. But what exactly are those benefits? How is, say, a car with built-in intelligence superior to one without? And who reaps those benefits?

Well, some things are obvious when you see them: open the door of a modern car, and if it’s dark outside, the indoor light comes on for just the door you opened—not all the others doors too and the interior light (or lights) fades up to full brightness. Close the door and the inside light of the car doesn’t snap off, it slowly and stylishly fades out. But, it didn’t take a computer to do that; with some smart wiring and some very simple electronic or electromechanical components an old-style car control system could have done that.

But, how about this: your car is not feeling too well, you’ve inadvertently put some poor-quality fuel in it and the engine is not firing too smoothly: But, no problem, the engine control unit (ECU)—which is based around a microcontroller—is on the case.

Using its sensors, the ECU discovers that the engine is not running normally and it automatically adjusts the frequency and duration of the spark plug activations to optimize the firing to suit the poorer-quality fuel, and it does so very quickly—quite likely without you, the driver, ever being aware there was a problem. On an old-time car that did not have an ECU, such an adjustment would probably have meant a trip to the workshop to have a skilled mechanic equipped with various analyzers make the necessary adjustments. It’s even possible that you may have spluttered to a stop at the roadside and had to call for assistance, so the ECU’s ability to adjust to this new situation saved you a heap of trouble.

Here’s another example: picture a digital scale, such as you might use to weigh ingredients for cooking in the kitchen, or for weighing letters and packets to find out how much they are going to cost to send. An electronic scale uses a sensing device generically known as a strain gauge. This is an electronic component whose

resistance changes according to tiny changes in the amount of pressure placed on it—an extremely sensitive little gizmo.

CHAPTER 5 ■ SmARTEn UP!

As a strain gauge component ages, its characteristics change: in other words, the electrical resistance it offers at the point where it has no pressure on it (its zero point) will change quite a lot over its lifetime, due to usage and environmental factors such as humidity. If the output of the sensor were just displayed as is, you would not get a reliable measurement. So, in such products there is built-in intelligence which, when the device is powered up, reads the current “no load” resistance of the sensor, and automatically uses that as its zero point for the current weighing session. In other words, the scale’s zero point is automatically recalibrated every time it is powered up—much better and more convenient than the user having to reset the zero point each day, as would have been the case using older designs.

The central point about both of the previous examples is that the embedded intelligence makes the product concerned function more conveniently and with less need for any human intervention or adjustment. However, there are far more benefits from embedding intelligent devices than our examples so far have shown. In the following sections we’ll look at a fuller list of what embedded intelligence can deliver in the following areas:

Increased functionality

Adaptive behavior

Increased efficiency

Improved problem management

Capacity for repurposing

Greener products

Support from the mother ship

Increased Functionality

Why do some older people have such problems using things like phones and remotes? I have a theory: although they grew up in a world with TVs and radios and cars and telephones, they also grew up in a world in which these things did not have embedded intelligence.

Before we started building computing power into pretty much all commodity consumer devices (something that happened from the early 1990s onward) a button on a consumer device usually did just one thing. If you had a button on a TV that said “Power” you only pressed it to power the TV on and off. With embedded intelligence, our devices started to be able to do lots more things: For example, on a modern TV it’s just as likely that if you press the “Power” button for a short time, the TV will go into standby mode, whereas, if you press the power button for a longer time, it will power the TV off completely. Hold it down even longer and you get into a technician’s service menu! So, individual buttons can do different things according to context and different user actions. Modern consumer device rarely have single-function buttons—and my theory is that some older people just can’t get used to that! Nice theory. . .

Industry analysts (such as McKinsey1) believe that most of the advanced features of modern consumer goods are not used by most of the people who buy them. If this is true, or even partly true, then why do manufacturers keep on providing so many options and extras on their products? Simple answer, because with the advent of embedded intelligence in consumer products, it became easy (and relatively cheap) for them to do so.

In the days when there was no embedded intelligence, any additional functions in a product had to be provided by extra hardware. Take the example of an early digital-era alarm clock that played a tune when the set alarm time was reached. Such a product would have had a dedicated clock chip inside it, a chip that made the

1www.mckinseyquarterly.com/Consumer_electronics_gets_back_to_basics_2454.

CHAPTER 5 ■ SmARTEn UP!

alarm tone (probably it only just made one kind of buzz) and a chip to drive the display. If the manufacturer had wanted to offer an enhanced version of the product that played tunes rather than just buzzing, it would have had to add more chips to the product—adding to the manufacturing cost of each and every unit produced.

By contrast, in the modern equivalent of the alarm clock product, alarm tunes would be implemented in software; there would be no buzzer or “tunes” chip. That means that adding more tunes becomes just a matter of developing more software which is a one-off cost but does not add anything at all to the manufacturing cost of the product. This is why so many modern products have such a plethora of features and functions—they are implemented in software. If you’re a global corporation making several million of these clocks, this is a very attractive approach, since doing things in software has comparatively little effect on the per-unit production cost. Also, it’s known that “features” sell a product—the longer the list of features you can put on the packaging, the more attractive consumers will seem to find it (even if none of them ever use those features).

Similarly to the preceding example, it’s now common for products to be manufactured for use globally and for user interface texts, in lots of different languages, to be built in. Again, it’s far more cost-effective for manufacturers to do this because it’s just software. There is no need for additional chips or to produce country-specific versions of the product.

Adaptive Behavior

In a previous example we saw how the embedded intelligence in a car might compensate for poor-quality fuel—an example of adaptive behavior that products and projects can display when they have embedded intelligence. That was a fairly simple example, but the uses for adaptive behavior can get far more complex.

In microcontroller-based systems, adaptation of behavior is almost always driven by sensory or data inputs. The behavior of a product might be adapted in response to

• Environment: For example the microcontroller might have a sensor that tells it the outside air temperature. Or, it might have a rain sensor that tells it whether rain is falling. An intelligent MP3 player might use information from an ambient noise sensor to know when to increase the headphones volume to compensate for lots of outside noise.

• Performance: Sensors might allow the controller to assess performance of the entity it is controlling. As in the car example we looked at previously, the ECU was able to infer from sensor inputs that the engine was not firing optimally and take appropriate action to rectify the problem.

• Presence: Some devices only need to function when certain conditions are true. Lights are a good example. Often they only need to be on when someone is in the room. The weighing scales we looked at earlier are another example. The scales only need to stay powered on if there is something present to be weighed. If nothing is present to be weighed, they can power off after a while.

• User input: As in our previous example about functionality, a device might present all user information and user prompts in the Latvian language, if the user has indicated that as his preference.

• Location: Because more and more consumer products now feature a GPS receiver, devices have the ability to know precisely where in the world they are. This allows them to adapt their behavior accordingly. For example, a car might have headlights whose maximum beam-height can be adjusted by the car’s control system. Since the maximum legal “throw” of headlights varies from country to country, an intelligent car could automatically adjust the headlight height, based on GPS location, during a drive across Europe.

CHAPTER 5 ■ SmARTEn UP!

• Data received: The days of the truly stand-alone device are passing. Very often an intelligent device will need to work in concert with other intelligent devices. This means that it must be able to respond to data provided to it from external sources. Most sensors provide fairly limited information about one thing. Having the ability to receive various kinds of data from a whole range of other devices allows an intelligent product, or project, to perform as part of a coordinated set of devices, not just unilaterally.

Home automation systems are a prime example of this need for concerted activity through data sharing. It’s very useful to have a lighting controller that puts lights on only when someone is the room, but it’s even more useful if that controller has the intelligence to react to a message from the home security system that says the house is now in

“nobody’s home” mode. That sensor activation is probably just the cat, and she can see in the dark anyway! Let’s save some electricity.

The ability of devices with embedded microcontrollers to respond intelligently and adaptively to data received from peer devices is something we look at in more detail in some of the project sections.

Increased Efficiency

In these pollution- and energy-aware days, we all want to consume less energy. But, we also want our devices to do more things for us, to provide us with more information and to manage our resources more effectively.

Embedded intelligence is one of the means whereby these apparently conflicting desires can be met.

Efficiency, in this context, is not just about reducing the carbon footprint of devices: it’s also about getting things done better, faster, and cheaper. For example, by embedding microcontrollers in devices such as

dishwashers and washing machines, manufacturers have been able to make them consume less power and water, while giving equivalent or better results.

How does embedded intelligence deliver these benefits? It’s really a question of awareness and memory.

If the controlling software program in a device is aware of its environment it can respond appropriately. A nonintelligent control system will initiate just one action in the presence of any given set of inputs. An intelligent system can make inferences not only from its sensory inputs but also from data it has remembered or learned previously.

To take the electronic alarm clock example mentioned earlier, a nonintelligent version of this device will look at the time now, it will look at its set alarm time, and if they match, it will sound its bleeper. An intelligent version of the same device would be very likely to have additional abilities. For example, it might have the ability to sense the outside temperature and sound the alarm 30 minutes early if the outside temperature has fallen below freezing level overnight. It might also have the ability to randomly select among a collection of alarm tones so that the sleepy user does not become immune to the wake-up call. In a fully integrated home automation (HA) system, the clock might have the ability to send “alarm time reached” messages to other intelligent devices. For examples it might

Send a message to a home heating system 30 minutes before the alarm is to sound

• —so

that the home is warm when the user rises from bed, but the heating is not running unnecessarily early.

Cause other HA system components to turn on lights, open curtains, or make beverages.

If the user is disabled or infirm, it might automatically send a message to a pager or call

unit for a helper to assist with washing or dressing.

Cause an information display next to the user’s bed to light up, showing outside

temperature, house systems status, and so on.

Send a wake-up message via the house network to boot up the user’s PC so that she can

check her e-mail before she starts for work.

CHAPTER 5 ■ SmARTEn UP!

In essence, an intelligent alarm clock can behave just a little more like a thinking thing then a dumb machine, but it can also make things more efficient. If you set your alarm for a little later than usual, your heating system will come on later than usual, if you need help from someone after you get up, that person is not called until he is really needed, the information display comes on when you need it, not at some preprogrammed time that doesn’t synch with you waking up.

So, in addition to energy efficiency embedded, connected intelligence also delivers efficiency of other kinds in a way that nonintelligent devices would not be able to do.

Improved Problem Management

Embedded intelligence is—as we have seen—a way of enabling products and devices to work around problems that occur in normal operation, but there’s more . . .

A nonintelligent device needs to have fault-detection hardware built into it. For example, in an alarm clock made from standard logic chips, a “snooze” button which is stuck in the pressed position is likely to cause the clock to inexplicably stop working. The designer could have built in extra logic chips to detect if any of the buttons were stuck, but it would involve extra cost of materials and manufacture and increase the physical size of the circuitry required.

By contrast, stuck-down button detection in a software-controlled intelligent device is far easier and does not significantly affect the cost of each unit manufactured. Better yet, the software can put a message on the display (or send off a message to a superior system, in a connected environment) to flag up that there is a stuck button problem, making the fault easy to identify and rectify. This concept of preemptive problem management has been taken up enthusiastically by the automotive industry and, although not without its problems (as we shall see later in the “Downsides of Intelligent Devices” section) it has, in general, made modern vehicles far more reliable and easy to service.

With embedded intelligence, devices and systems can do more than identify problems when they occur;

they can also identify issues before they become problems. For example, some sophisticated home and office lighting management systems use embedded intelligence to collect statistics about the “on” time of individual lamps, or groups of lights. Coupled with the manufacturer’s data on lifetime of the lamps concerned, it becomes possible to raise “change lamp” alerts when lights approach their true end of life but before they actually fail. This is a much better approach than just slavishly changing the lamps on a fixed maintenance cycle when they could easily still have a lot of useful life remaining. Similar techniques can be used to deal intelligently with replacing batteries in various kinds of devices.

Capacity for Repurposing

As human beings we love to second-guess ourselves. We always have second thoughts about things we make.

In conventional electronics, when you build something, it can be quite hard to subsequently make substantial modifications to what it does or how it behaves. In many microcontroller projects you can endlessly alter, refine, adapt, reuse, or repurpose your creations, since a great many changes simply require making a modified version of the software and reprogramming the microcontroller with it. However, to realize the full benefits of this feature, you do have to think ahead a little bit at the time you design and create your project.

Outside Light—Without Intelligence

Let’s imagine a situation where we need to control a light fixed to the outside of a house. Without involving electronics, we could just fit a switch to turn the light on or off manually, as shown in Figure 5-1, in which we see the mains power source (a wall outlet probably), the switch (probably mounted on a wall near the door leading outside the house), and the light itself.

CHAPTER 5 ■ SmARTEn UP!

This approach, although simple, is not ideal. The light might be left on for whole days even when not needed, or we might forget to put it on and leave visitors or family members groping around outside in the dark looking for the door to the house. So, perhaps we might add a mechanical timer to make the light go on and off at preset times of the day (Figure 5-2)—probably sunset and sunrise.

AC

Figure 5-1. Outside light controlled by simple switch

AC

Figure 5-2. Outside light control by switch and/or timer switch

Again, this is not totally satisfactory because, as the daylight hours vary through the year, we would have to keep adjusting the timer’s on/off cycles too.

If we get electronics involved, we can use an ambient light sensor (used, in this case, as a darkness detector) to keep the light off when it’s daylight but turn it on when it gets dark—as shown in Figure 5-3, in which a mains-powered light-sensitive switch is used to allow power through when there is no light.

Dalam dokumen Practical AVR Microcontrollers (Halaman 160-172)

Dokumen terkait