Skip to main content

Microcontrollers

Chapter 7 Sensors and Sensor Calibration

In order to obtain information about the world around us, sensors must be used. Sensors take information about the external environment and convert (transduce) them into electrical signals. Possible electrical signals include voltage, current, and resistance. Devices with electrical properties dependent on a particular physical quantity are chosen (photo-sensitive resistors, temperature-sensitive transistors, piezoelectric ceramics) to measure that property. For example, temperature is the environmental input variable to a temperature sensor such as the TMP36. The output of the temperature sensor is a temperature-dependent voltage. The light level is the environmental input variable to a photoresistor. The output of the photoresistor is a light-level-dependent resistance.
Several types of sensors are listed below.
Some sensors provide digital data output. For example, a pushbutton is capable of generating a digital logic value of HIGH or LOW depending on whether or not the button is pressed. Simple digital sensors such as this can be directly connected to any pin on the ATmega328P that has been configured as an input pin.
Of sensors that provide digital data output, some have been built to send data using a serial communication protocol, as introduced in ChapterΒ 10. Making sense of this data will require consulting the sensor datasheet.
Many sensors, however, provide analog information, which may be in the form of a voltage output or a changing resistance. Sensors that output a voltage can interface directly with a microcontroller featuring an ADC (ChapterΒ 6) by connecting the sensor output to an appropriate ADC pin after confirming that the minimum and maximum voltage output values fall within the acceptable voltage input range. This is depicted in FigureΒ 7.0.1.
A sensor is depicted as a square with the letter V inside. One lead of the sensor is connected to VCC, another to GND, and a third lead is connected to a signal labeled "V_analog."
Figure 7.0.1. Schematic of how to connect a sensor that outputs an analog voltage signal.