Chapter 8

Analog Arduino

WHAT’S IN THIS CHAPTER?

  • The real world is analog
  • Using DACs and ADCs
  • Pulse width modulation
  • Sensing distance with ultrasound
  • Understanding piezo electricity by making noise

WROX.COM CODE DOWNLOADS FOR THIS CHAPTER

The wrox.com code downloads for this chapter are found at www.wrox.com/remtitle.cgi?isbn=1118454766 on the Download Code tab. The code is in the Chapter 8 download and individually named according to the names throughout the chapter.

The physical world is not digital. The voltage between two points doesn’t change only between the two levels of HIGH and LOW. It can take any value, most times it is too small to be measured in any way. However, microcontrollers cannot sense every value out there.

They can read values between 0 Volts and 5 Volts (or 3.3 Volts if you were using 3.3 Volts logic, like with the Arduino Due) through an internal peripheral. This small part of the chip is called Analog to Digital Converter (ADC). In some cases, the microcontroller of your choice might not have an internal ADC, in which case you will have to add an external one to your circuit if you need it. An ADC transforms a voltage into a number of type integer that you can then read into a variable and use as part of your programs.

What characterizes an ADC is its so-called bit depth, or the number of bits it uses to convert analog values into numbers. The ADC inside Arduino’s microcontroller has a bit depth of 10 bits. With those bits you can represent 1,024 different ...

Get Professional Android Open Accessory Programming with Arduino now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.