Chapter 3. Interacting with the Environment the Digital Way

Now it's time to start working hands on with our Arduino boards by connecting electronic circuits to them and programming the microcontrollers to interact with the external circuitry.

In this chapter, we are going to deal with digital outputs, as it is the simplest way to interact with the outside world, and we will learn about the necessary code to drive them.

Let's begin with some considerations regarding digital and analog signals, move on to the circuit assembly, and finish by writing some code to make the microcontroller command the external circuit.

Digital versus analog signals

When working with electronics signals, you will constantly see references to digital and analog signals, and it is important that you differentiate between the two and know how to make Arduino deal with every type of signal.

A digital signal is one that takes only two clearly different states—no more, no less. To give you an example, switching a light on and off can be a typical case of a digital signal. You just have these two states, and it is on or it is off; it can't be both at the same time and nor can it have any other possible state in between.

In opposition to digital signals, analog ones are those that have a theoretically infinite number of possible values between a minimum and maximum one. Looking for an example relative to light, such as the one given for digital signals, we can think of the light coming from the sun through a window. It has a minimum, when there is no sun in the night, and a maximum, when the sun is just in front of your window. However, between these two extreme values, there are an infinite number of them, differentiating one another in a very small increment as long as the sun goes from the minimum position to its maximum.

When working with computers and microcontrollers, digital signals are often represented by the 0 and 1 value, 0 being the value used for the off state and 1 for the on state, which makes them perfect to be represented as binary digits.

In the Arduino language, we even have two more convenient constants to reference these two states, HIGH and LOW, as you may remember from the Blink code example we saw in the previous chapter. In any case, we will see more about this in this chapter.

On the other hand, when dealing with analog signals from the point of view of a computer, we usually represent them as real numbers, or floating-point numbers in computer science jargon, but we will talk in more detail about this in Chapter 4, Controlling Outputs Softly with Analog Outputs.

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

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