Chapter 5. Reading from Analog Sensors

We have dealt with digital components up to now. They have only two possible states: ON or OFF. Not all electronics components are digital. Many electronic components are analog. These types of components can have any value among the possible infinite values. Dealing with analog components is different to dealing with digital components. Most of the electronic sensors available are analog. In this chapter, we will write programs to deal with analog components: temperature sensor and light sensor.

In this chapter, we are going to cover these topics:

  • Analog I/O
  • Reading from analog components
  • TMP36 temperature sensor circuit setup
  • Program to print temperature
  • LDR circuit setup
  • Program to check light intensity

Analog I/O

In digital electronics, there are only two possible values—ON or OFF. In real life, we can not describe everything as ON or OFF. Many entities can have a wide range of values. For example, weight cannot be described as ON or OFF. You need to specify a number to describe magnitude of weight. Weight can be 66 kg. It can be 65.9 kg. It can be 65.93472641 kg. All these are valid numbers to describe weight. The possible values for analog entities are infinite, unlike with digital systems. The same holds true for analog entities like length, temperature, air pressure, and so on. If we plot a graph of values over time, we get an analog signal wave. The disadvantage of analog information is it's susceptible to noise and information is lost during transmission due to distortion, non-linearities, and so on.

Most of the sensors are of analog type. They get information from the environment. Often the information is a unit or a scalar value of the environmental entity. Then they convert that value into corresponding voltage and generate that voltage on its data output pin. For example, the weight sensor gets information about weight in kilograms. The more weight it detects, the more voltage is generated on the sensor's output pin. A typical analog sensor sends a continuous raw analog signal on an output pin. BeagleBone has dedicated pins to take analog input. BeagleBone can read sensor output voltage through analog input pins and we can convert it back to the original unit in our program. The datasheet of that sensor needs to be referred in order to find out it's voltage range and how to convert the measured voltage to the original unit. Based on the calculated unit value, BeagleBone can respond using output devices, such as a glowing red LED when a higher than expected temperature is measured or playing the next video when corresponding values are captured at the infrared sensor (which is sent by IR remote control).

Like all computer systems, BeagleBone is a digital system. It cannot work on analog information directly. The voltage generated at an analog input pin has to be converted to digital for the BeagleBone to understand it. BeagleBone has a built-in Analog to Digital Converter (ADC) that converts captured variable voltage to scaled digital values. So, we get more of a range of values than just HIGH or LOW.

Regular General-Purpose Input/Output (GPIO) pins are not capable of reading analog information and converting to digital. BeagleBone has dedicated seven pins that can read from analog devices. These pins are capable of taking input only. They cannot be used for output purposes. BeagleBone SRM mentions them as AIN0-AIN6. Please check the following diagram for more details. The P9 header has seven analog input pins. It also has VDD_ADC and GND_ADC pins. These are VDD (voltage source) and GND is used to create analog circuits. This VDD pin is different from P9_3/P9_4 VDD pins because it provides 1.8V only. This is because BeagleBone ADC works at 1.8V logic level:

Analog I/O

Note

Warning

The BeagleBone ADC is capable of handling a maximum of 1.8V. It can get damaged if more voltage is given to analog input pins. Please read the sensor datasheet before you attach it to BeagleBone.

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

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