Loading...
 

ArduinoM0 Temperature Sensor Example

Precision Temperature Sensor

In this project we demonstrate how to read temperature measures using your Arduino Board.
This project makes use of Temperature Sensor (TMP36).
This sensor outputs 10 millivolts per degree centigrade on the signal PIN.
Measuring temperatures below freezing is possible thanks to a 500 mV offset (for example 25 degrees C = 750 mV, 0degrees C = 500mV).
We'll use some math formulas to convert the digital value read from the sensor to degrees.
The value converted is then shown in SerialMonitor.
NOTE:
The Arduino board M0 operates on 3.3V. The maximum voltage that the I/O pins can tolerate is 3.3V. The application of a voltage exceeding 3.3V may damage the board.

Hardware

  • Arduino board
  • Breadboard
  • Temperature Sensor (TMP36) (x1)
  • A bunch of wires

Circuit

Image
Put the temperature sensor in the breadboard. Link the ground PIN to Ground and the power PIN to Arduino 3.3V PIN.
The Signal PIN is the center one; connect it to Analog PIN A0 of your Arduino board.

Note:
In the picture is shown the circuit realized using an Arduino M0 Pro.

Code

The sketch code starts a Serial connection in order to read results using Serial Monitor.
It reads the raw datas coming from sensor and it converts it to a digital range from 0 to 1024.
Now it converts the result to a degree using a math formula.
The temperature result will now be sent to the Serial Monitor, available for reading.

//Define the Temperature Sensor Pin
int sensorPin = A0;

void setup() {
	//Start Serial connection to read results in Serial Monitor
	SerialUSB.begin(9600);
}

void loop() {
	//Get the sensor raw reading 
	//then convert it from a 0 to 1024 digital range
	float temperature = analogRead(sensorPin) * .004882814;
	
	//Convert the raw value to Celsius
	temperature = (temperature - .5) * 100;
	
	//Print the temperature value to Serial Monitor
	SerialUSB.println(temperature);
	
	//Read the temperature each second
	delay(1000);
}