Chapter 4. Controlling Outputs Softly with Analog Outputs

Interacting with the environment in a digital way is very practical, and you'll use it in a different number of situations. In fact, we are very accustomed to these kinds of interactions and they are nothing really new.

In this chapter, we will see a very different kind of interaction that not only supports an on and an off state but also a number of different states between them. We will deal with analog outputs.

We will begin by fading an LED to later see a new circuit that controls the speed of a motor through an analog output.

Dealing with analog signals

As an introduction to the connection and programming of analog outputs, we will use the simplest circuit we have already seen, that is, we will connect an LED to our Arduino board but to deal with it analogically this time.

Before going into the details, I would like to introduce a couple of concepts that will help you when working with these kinds of signals.

The first thing you should know is that Arduino isn't really able to generate an infinite continuous analog signal, but instead, it uses a little trick to simulate it. Digital devices such as microcontrollers usually incorporate a peripheral called Digital to Analog Converter (DAC), which they use specially to perform this trick.

When working with a microcontroller, we pass a digital value to the DAC, and it converts it to an analog value but in a predefined range of possible values. The DAC is unable to generate an infinite set of output values; it has a finite input range of digital values and can generate a finite output range of analog voltages.

The number of steps the DAC can generate is called the resolution of the DAC. The Arduino DAC has an 8-bit resolution, so it accepts input values ranging from 0 to 255, which will be converted to analog values between 0V and 5V. If you divide the voltage range between the total number of steps the Arduino DAC accepts, you will conclude that every step of the input range increments the output voltage by almost 0.02V.

To perform this conversion, the DAC uses a method called Pulse Width Modulation (PWM) that consists of turning the output at very high frequencies on and off, resulting in a medium voltage that is the proportion of the on time with respect to the off time.

If you want to learn more about DACs and PWM, you can visit the corresponding pages on Wikipedia at http://en.wikipedia.org/wiki/Digital-to-analog_converter and http://en.wikipedia.org/wiki/Pulse-width_modulation.

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

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