EsploraTemperatureSensor

Read the temperature sensor and get the temperature in in Farhenheit or Celsius.

Esplora Temperature Sensor

This sketch shows you how to read the Esplora's temperature sensor. You can read the temperature sensor in Farhenheit or Celsius.

Hardware Required

  • Arduino Esplora

Circuit

Only your Arduino Esplora is needed for this example. Connect the Esplora to your computer with a USB cable and open the Arduino's Serial Monitor.

Temperature to send data to your computer from the Esplora
Temperature to send data to your computer from the Esplora

Code

To send data to your computer, you need to open a serial connection. use Serial.begin() to open a serial port at 9600 baud on the Esplora.

The Esplora.readTemperature() function gets the value from the temperature sensor. It will give you the temperature in degrees Celsius or degrees Fahrenheit, depending on your choice. It takes one parameter, DEGREES_C for Celsius or DEGREES_F for Fahrenheit.

To send the values to the Serial Monitor, you call Serial.print(). When the Esplora is connected, and the Serial Monitor is open, you should start to see values reported like this:

1Temperature is: 22 degrees Celsius, or 72 degrees Fahrenheit.
2Fahrenheit = (9/5 * Celsius) + 32
3Temperature is: 21 degrees Celsius, or 72 degrees Fahrenheit.
4Fahrenheit = (9/5 * Celsius) + 32
1/*
2
3 Esplora Temperature Sensor
4
5 This sketch shows you how to read the Esplora's temperature sensor
6
7 You can read the temperature sensor in Farhenheit or Celsius.
8
9 Created on 22 Dec 2012
10
11 by Tom Igoe
12
13 This example is in the public domain.
14
15 */
16#include <Esplora.h>
17
18void setup() {
19
20 Serial.begin(9600); // initialize serial communications with your computer
21}
22
23void loop() {
24
25 // read the temperature sensor in Celsius, then Fahrenheit:
26
27 int celsius = Esplora.readTemperature(DEGREES_C);
28
29 int fahrenheit = Esplora.readTemperature(DEGREES_F);
30
31 // print the results:
32
33 Serial.print("Temperature is: ");
34
35 Serial.print(celsius);
36
37 Serial.print(" degrees Celsius, or ");
38
39 Serial.print(fahrenheit);
40
41 Serial.println(" degrees Fahrenheit.");
42
43 Serial.println(" Fahrenheit = (9/5 * Celsius) + 32");
44
45 // wait a second before reading again:
46
47 delay(1000);
48}

Contribute to Arduino

Join the community and suggest improvements to this article via GitHub. Make sure to read out contribution policy before making your pull request.

Missing something?

Check out our store and get what you need to follow this tutorial.