Introduction: LM35 Temperature Sensor With SAMD21 Xplained Pro
if you are familiar with arduino platform , this project will sound silly for you , but if you are working on another platform , this project will not be as easy as you think.
in this project I will show you how to build a temperature monitor based on LM35 and SAMD21 Xplained pro , and use 7 segment 4 digit Backpack from adafruit .
you will need for this project :
Step 1: Understanding and Setup the Code Configurations
LM35 is an anologue sensor , has 3 pins :
VCC (5V) , GND , OUT , output will give us 10mV for every 1C , so if you measure the voltage on the OUT pin and you get 100mV , that's mean the LM35 sense a temp of 10C
so we need to read an analog value , with SAMD21 Xplained pro there are many pins can handle that , and you can going to (ATMEL START) and select the pin to read analog value , for example I will choice PB00.
also I will set the ADC resolution to be 10bit ,and select the reference for the ADC (AREF) and prescaler for ADC clock.
atmel start allow you to select the ADC driver from Synchronous (polled) , Asynchronous (Callback/interrupt)
I will choice Synchronous driver "and you can select Asynchronous later and re-write the code , it's easy to do"
now if you don't have a 7 segment and you want to see the results on the serial terminal , you need to use stdio with UART driver to send and receive the data with you computer, for SAMD21 Xplained pro select:
Rx >>> PA23
And from the same window you can set the baud rate to be 9600
to control Adafruit 7 segment you nee to use I2C , add I2C driver from atmel start and choice the driver type ( I used Synchronous Driver , you canvisit my blog to see a full tutorial about how to connect this 7 segment module with SAMD21 Xplained pro , I re-write the code based on adafruit library.
set SDA >> PA08 , and SCL >>> PA09 and set the ADC clock speed to 100KHz.
Step 2: Testing the Code - Results
if you have atmel studio 7.0 so you can download the code from github and open it directly , no driver or external libraries required to run the code .
after you build the code and upload it to SAMD21 xpalined pro ,you can open the terminal window(or putty software) and see the results.
one thing I noticed during this project is LM35 resolution , the sensor is not accurate compared to other sensors " Resolution +-1C) so I got an average reading and update the results every 3 seconds "average not a perfect solution , but it works fine to me)
you can modify the code and modify the configuration from atmel start by uploading (.astart file) to atmel start and change the configuration to match your requirements
We have a be nice policy.
Please be positive and constructive.