Measure The Ambient Temperature With Raspberry Pi Pico And Grove Temperature Sensor Using Arduino IDE

Measure The Ambient Temperature With Raspberry Pi Pico And Grove Temperature Sensor Using Arduino IDE

Introduction

In this tutorial we shall see how to measure the ambient temperature with Raspberry Pi Pico and grove temperature sensor using Arduino IDE.

Video

Hardware Preparation

For this tutorial we will need the following components

component
DCIM\101MEDIA\DJI_0277.JPG

Building The Circuit

The connection between the devices are as shown

connection

Code

Below is the complete code that we have used in this tutorial


#include 
#include 
#include 
#include 

#define SENSOR_PIN             A0
#define REFERENCE_RESISTANCE   8000
#define NOMINAL_RESISTANCE     100000
#define NOMINAL_TEMPERATURE    25
#define B_VALUE                3950

// Define the connections pins
#define CLK 2
#define DIO 3

/**
  How many readings are taken to determine a mean temperature.
  The more values, the longer a calibration is performed,
  but the readings will be more accurate.
*/
#define READINGS_NUMBER 10

/**
  Delay time between a temperature readings
  from the temperature sensor (ms).
*/
#define DELAY_TIME 10

// Create °C symbol
const uint8_t celsius1[] = {
  SEG_A | SEG_B | SEG_F | SEG_G,  // Circle
  SEG_A | SEG_D | SEG_E | SEG_F   // C
};

const uint8_t SEG_pico[] = {
  SEG_A | SEG_B | SEG_E | SEG_F | SEG_G,           // P
  SEG_B | SEG_C,                                   // i
  SEG_A | SEG_D | SEG_E | SEG_F,                   // c
  SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F    // o
  };

// Create display object of type TM1637Display
TM1637Display display = TM1637Display(CLK, DIO);

Thermistor* thermistor = NULL;

// the setup function runs once when you press reset or power the board
void setup() {
  Serial.begin(9600);

  // Set the display brightness (0-7)
  display.setBrightness(5);
  
  // Clear the display
  display.clear();

  Thermistor* originThermistor = new NTC_Thermistor(
    SENSOR_PIN,
    REFERENCE_RESISTANCE,
    NOMINAL_RESISTANCE,
    NOMINAL_TEMPERATURE,
    B_VALUE
  );
  thermistor = new AverageThermistor(
    originThermistor,
    READINGS_NUMBER,
    DELAY_TIME
  );

  /* OR
    thermistor = new AverageThermistor(
      new NTC_Thermistor(
      SENSOR_PIN,
      REFERENCE_RESISTANCE,
      NOMINAL_RESISTANCE,
      NOMINAL_TEMPERATURE,
      B_VALUE
    ),
    READINGS_NUMBER,
    DELAY_TIME
  );
  */
}

// the loop function runs over and over again forever
void loop() {
  // Reads temperature
  const double celsius = thermistor->readCelsius();
  const double kelvin = thermistor->readKelvin();
  const double fahrenheit = thermistor->readFahrenheit();

  // Output of information
  Serial.print("Temperature: ");
  Serial.print(celsius);
  Serial.print(" C, ");
  Serial.print(kelvin);
  Serial.print(" K, ");
  Serial.print(fahrenheit);
  Serial.println(" F");

  
  display.setSegments(SEG_pico);
  delay(1000);
  display.showNumberDec(celsius, false, 2, 0);
  display.setSegments(celsius1,   2, 2);

  

  delay(100); // optionally, only to delay the output of information in the example.
}

Thank You

Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.

"Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for a better application."