Difference between revisions of "Reading Temperature with AVR Breakout"
Line 6: | Line 6: | ||
Refer [[Reading Temperature with AVR ADC]] for basics of Atmega32 ADC and LM35 temperature sensor. | Refer [[Reading Temperature with AVR ADC]] for basics of Atmega32 ADC and LM35 temperature sensor. | ||
− | =Hook Up= | + | =Hook Up LM35= |
[[file:Avrbreakout_ADC_temp.png]] | [[file:Avrbreakout_ADC_temp.png]] | ||
==Code to Read Voltage== | ==Code to Read Voltage== |
Revision as of 13:49, 5 April 2016
In this tutorial we will set up and read the temperature from LM35 using ADC of Atmega32 AVR breakout.
Basics
Initially we will read a raw data from ADC. Atmega32 comes with 10-bit 8-channel inbuilt ADC. We will connect 10k Pot to channel 0, vary it and read the raw voltage. After that we will connect the LM35 temperature sensor to channel 0 and read the temperature as shown in hook up. We will display the converted value on terminal.
Refer Reading Temperature with AVR ADC for basics of Atmega32 ADC and LM35 temperature sensor.
Hook Up LM35
Code to Read Voltage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "adc.h" | |
#include "uart.h" | |
int main() | |
{ | |
int adcValue; | |
float volt; | |
ADC_Init(); /* Initialize the ADC module */ | |
UART_Init(9600); /* Initialize UART at 9600 baud rate */ | |
while(1) | |
{ | |
adcValue = ADC_GetAdcValue(0); // Read the ADC value of channel zero | |
volt = (adcValue*5.00)/1023; //10bit resolution, 5vReference | |
UART_Printf("ADC0 Value:%4d Equivalent Voltage:%f\n\r",adcValue,volt); // Send the value on UART | |
} | |
return (0); | |
} |
Code to Read Temperature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "adc.h" | |
#include "uart.h" | |
int main() | |
{ | |
int adcValue; | |
int temp; | |
ADC_Init(); /* Initialize the ADC module */ | |
UART_Init(9600); /* Initialize UART at 9600 baud rate */ | |
while(1) | |
{ | |
adcValue = ADC_GetAdcValue(0); // Read the ADC value of channel zero where the temperature sensor(LM35) is connected | |
/* Convert the raw ADC value to equivalent temperature with 5v as ADC reference | |
Step size of AdC= (5v/1023)=4.887mv = 5mv. | |
for every degree celcius the Lm35 provides 10mv voltage change. | |
1 step of ADC=5mv=0.5'c, hence the Raw ADC value can be divided by 2 to get equivalent temp*/ | |
temp = adcValue/2.0; // Divide by 2 to get the temp value. | |
UART_Printf("ADC0 Value:%4d Equivalent Temperature:%dC\n\r",adcValue,temp); // Send the value on UART | |
} | |
return (0); | |
} |