I've always wondered this, how exactly are sensors interpreted by/for the microcontroller? Like lets use an example of a Heat Sensor...how exactly is something like say.....an Arduino interpreting the data? I mean using a LM35 Precision Centigrade Temperature Sensor which is pretty common but small at the same time.
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
I'm not familiar with the Arduino, but in general microcontrollers interface with a sensor in one of two ways -- either as a voltage (using the ADC for input) or via a serial bus such as I2C or SPI.
The LM35 outputs a voltage proportional to the temperature in degrees Centigrade, so you would interface its output to the ADC input of the Arduino.
The raw output of the LM35 is 10 mv/degree C, so 2 degrees C would be 20 mv, 100 degrees C would be 1 volt, and room temperature (22 deg C) would be 0.22 volts. Assuming a 10-bit ADC with a reference voltage of 3.3 volts, 0.22 v would be represented as 0.22/3.3*1024 or a count of 68.
Note that you are not using very much of the range of the ADC, even at 100 deg C. You could increase the voltage of the LM35 by adding a rail-to-rail op-amp with a gain of 5 which would allow you to measure 0 to 65 deg C and use the full range of the ADC. 0 deg would still be 0, 65 deg C would be 0.65*5/3.3*1024 or a count of 1008, and 22 deg C would be 0.22*5/3.3*1024 or a count of 341.
In order to measure temperatures below 0 deg C with the LM35, it would be necessary to provide a negative bias to the output (see the LM35 datasheet for details).
For a microcontroller to act on a signal, it has to be turned into a sequence of numbers that represent the signal. Most commonly, the signal is a voltage and it is periodically sampled with a A/D (analog to digital converter). That produces a number proportional to the voltage every time it does a conversion. Most microcontrollers have A/Ds built in.
Small cheap micros may have 8 bit A/Ds, 10 bits is quite common, but 12 bits isn't too unusual either. After that, it gets difficult to construct the A/D accurately enough with the same process used to make the digital microcontroller. Past 12 bits therefore usually requires external A/Ds that interface digitally to the micro, such as via SPI or IIC, or less commonly today a bunch of parallel bits.
Once you have the analog signal represented as a sequence of numbers, you can apply all sorts of techniques to it. In fact, this is specifically what DSPs (digital signal processors) are optimized to do. Ordinary micros can do this too, but are slower at performing some of the fancy filtering operations. They are generally used in control applications as apposed to signal processing applications. For example, a micro might convert the voltage from a temperature sensor to a number in it's A/D, then use that number to decide how hard to run a fan.
Some temperature sensors output a voltage that can be fed into an ADC (much as tcrosley has suggested) but there are also devices with digital interfaces (e.g. DS18S20 which boasts a 1-wire digital interface) that return the temperature in degrees Celsius.
A Google search can provide multiple tutorials about interfacing the DS18S20 with an Arduino.