Being able to add a level of smartness to projects can greatly extend their usefulness (and make them more interesting). The smartness usually involves some level of electronics - today the number of options available to do that is much greater than it ever was before, and more importantly, well within the average hobbyists budget.

To explore what can become possible with various levels of complexity I'm going to use the example of a display table. The general idea is a coffee table with a recessed rectanglar area covered by glass or plastic that is used to display small objects - a fossil collection for example.

Discrete Electronics

By discrete electronics I mean the use of components such as resistors, capacitors and transistors as well as higher level components such as comparators, op-amps, timers and gate level (and, or, not) digital logic.

One immediate extra feature that can be added is some additional lighting to make the objects under the glass clearer to see. The simplest circuit would involve a power supply, a switch and a lamp. Turn the switch on, the lamp lights up and the objects are easier to see (Instant On Lighting - just like Arthur 2). This would be a bit pointless when the ambient light level is bright enough already so you might add a photoresistor so the light only comes on when the ambient light level is low enough.

Rather than using a single light source, you may have multiple with each shining on a specific object of interest. Rather than have them all come on at the same time you could attach a sequence of buttons that would trigger an individual light highlighting a single object. You might also add some timing circuitry so that the lights go out after a certain amount of time until another button is pressed.

Each extension of functionality makes the controlling circuit more complex (and requires that you rebuild the circuit for each step). Any option you didn't think of in the initial design is going to be very expensive (in terms of time and hassle) to implement.

Microcontrollers

A microcontroller is simply a small CPU and a collection of higher level periphials in a single chip. Unlike the CPU in your normal computer a microcontroller will often have memory (both RAM and ROM) built in (and will not be able to access any off chip memory). This built in memory is generally small in size (very, very small compared to a normal desktop - measured in kilobytes rather than megabytes). Microcontrollers have no operating system and only run a single program (the one that is stored in their permanent memory).

The two main families of microcontrollers in use today (in hobby circles at least) are the Microchip PIC and Atmel AVR.

K150 PIC Programmer

Loading code on to a microcontroller requires a special purpose programmer that will burn the code into the permanent storage area of the chip. For both of the popular families there are a range of cheap (and/or simple to build yourself) programmers available that are easy to use and have good software support on all the main operating systems.

Code for microcontrollers is written and prepared on your normal desktop computer which will generate an image file that is passed to programmer to burn onto the chip. The code can be written in assembly language or a higher level language such as C or BASIC. Both families provide a full IDE that can be used to prepare code in assembly or C, support for additional languages is usually provided by third parties.

Arduino

A very quick and easy way to get involved with microcontrollers is to use a pre-built module which provides the support circuitry for the CPU (clock, power supply, input/output protection) as well as a simple programming interface. One of the most popular modules available is the Arduino which is based on the Atmel AVR ATmega series of controllers. There are a number of versions of this board for a range of providers (the Arduino is an Open Source Hardware so the full specification and circuit diagram is freely available). All Arduino models provide a programming interface (either an RS232 serial connection or USB) and have a well defined set of input and output capabilities.

If you were to use a microcontroller instead of discrete electronics in the display table you would wire the lights to a set of digital outputs and your buttons to a set of digital inputs. Controlling the behaviour of the lights with respect to the buttons is completely controlled by the software. This means that there will be minimal, if any, changes to the circuit to modify the overall behaviour. You could even experiment with fancier effects (such as fading the lights in and out rather than immediately turning them on and off or entering a random sequence of highlights after period of inactivity). All in all moving to a microcontroller allows much more flexibility at a very low cost.

Single Board Computers

A single board computer is a general purpose computer (much like your desktop) provided on a small circuit board (usually around the size of a credit card or slightly larger) and a handful of general input and output pins. The wildly popular Raspberry Pi and the more mature BeagleBoard projects are classic examples of these types of systems.

The BeagleBoard

These boards are about equivalant in performance to a desktop computer from the early 2000's and generally run the Linux operating system allowing for a wide range of free open source software to be included in your project.

Although overkill for simple button and light control these devices allow for much more complex inputs and outputs to be handled. In our display table example you might use a Raspberry Pi and an LCD to display information about the currently highlighted object (history, provenance, and similar types of items for example). Add a network connection and you could google for recent articles about items of that type as well. Attach a webcam and you could use image processing software to detect that a face is looking at the table and trigger the lights from that input. Depending on the complexity of the software you could even detect which item they were looking at and use that instead of buttons. There are a wide range of devices you can use with these devices - open source drivers for the Microsoft Kinect for example will allow you to add motion control to your project.

Combinations

In many projects you would use a combination of the above. A microcontroller chip generally cannot drive outputs directly so you would need some discrete electronics to provide voltage level conversion or to drive heavier current loads.

The microcontroller itself is limited in memory and processing capacity so performing more complex decision making or interfacing with more higher level devices (such as USB cameras, ethernet or WiFi networks or data storage devices) can be difficult if not impossible.

A single board computer handles higher level devices and more complex programs but tends to have limited low level IO (analog to digital, digital to analog, comparators or PWM for example). The overhead of a full operating system can make precise timing of low level control very difficult as well. Using a microcontroller to perform these low level tasks and communicating with the computer over a serial connection provides you with the best of both worlds.

The Garage Lab Motor Controller

Over a series of posts I'm going to describe the PIC processor and use it in the core of a controller board capable of driving two motors (with speed and direction control), two servos and provides a handful of digital inputs and outputs. The board is designed to be controlled by any external computer that has an RS232 interface.

The code for the board will be fairly simplistic, enough to respond to commands from an external controller rather than being a fully autonomous controller in it's own right. The code could be modified for that purpose if needed.

A full tutorial on programming and interfacing the PIC is beyond the scope of this site but I will be providing plenty of links to more suitable sites that can bring you up to speed. The goal is to provide a concrete project that can be used to experiment with and put the lessons learned into practice - the end result will be a circuit (and software) that can be modified for use in a range of different projects. I hope you enjoy the series and find it useful.