What Next?293Experiment 34: Hardware Meets SoftwareExperiment 34: Hardware Meets SoftwareThroughout this book, in accordance with the goal of learning by discovery, I have asked you to do an experiment first, after which I’ve suggested the gen-eral principles and ideas that we can learn from it. I now have to change that policy, because the next experiment involves so much setup that it’s only fair to tell you what to expect before you begin the preparations.We are about to enter the realm of controller chips, often known as MCUs, which is an acronym for micro controller unit. An MCU contains some flash memory, which stores a program that you write yourself. The flash memory is like the memory in a portable media player, or the memory card that you use in a digital camera. It needs no electricity to power it. In addition, the chip has a processor which carries out the instructions in your program. It has RAM to store the values of variables on a temporary basis, and ROM, which tells it how to perform tasks such as sensing a varying voltage input and converting it into digital form for internal use. It also contains an accurate oscillator, so that it can keep track of time. Put it all together, and it’s a tiny computer that you can buy for under $5.Let’s suppose that you have a greenhouse where the temperature must never fall below freezing. You set up a temperature sensor, and you have two dif-ferent heaters. You want to switch on the first heater if the temperature falls below 38° Fahrenheit. But if, for some reason, that heater is broken, you want to switch on the second, backup heater when the temperature goes below 36° Fahrenheit.Programming a MCU to take care of this can be very simple indeed. You could even add extra features, such as a second temperature sensor, just in case the first one fails, and you could tell the chip to use whichever sensor gives a lower reading.Another application for a MCU would be in a fairly elaborate security system. The chip could monitor the status of various intrusion sensors, and can take various preprogrammed steps, depending on the sensors’ status. You could include delay intervals, too.Many MCUs have additional useful features built in, such as the ability to con-trol servo motors that turn to a specific angle in response to a stream of pulses. Servos are widely used in radio-controlled model boats, airplanes, and hobby robotics.Perhaps you are now wondering why, if MCUs can do all this, haven’t we been using them all along? Why did I spend so much time describing the develop-ment of an alarm system using discrete components, if one chip could have done everything?