Lesson 5 Temperature Detection by Thermistor

Share for us

Introduction

As mentioned in Lesson 4, thermistors are the most sensitive temperature sensors because their resistance changes acutely with temperature changes. Therefore, the thermistor sensor module measures temperature sensitively though it can output only analog signals. The module is often used to detect the temperature changes in ambient environment.

Components

– 1 * SunFounder Uno board

– 1 * USB data cable

– 1 * Thermistor module

– 1 * I2C LCD1602 module

– 1 * 3-Pin anti-reverse cable

– 1 * 4-Pin anti-reverse cable

– 1 * Dupont wire (F to F)

Experimental Principle

How a thermistor works: its resistance varies significantly with the ambient temperature. It can detect surrounding temperature changes in a real-time manner and send the temperature data to analog I/O port of the SunFounder board. What you need to do is convert the output to Celsius temperatures by simple programming and then display it on an LCD.

The schematic diagram of the module:

Experimental Procedures

Step 1: Build the circuit

Step 2: Program (Please refer to the example code in LEARN -> Get Tutorial on our website)

Note: Here you need to add a library(LiquidCrystal_I2C ). Refer to the description in Lesson 1 previously in the manual.

Step 3: Compile

Step 4: Upload the sketch to SunFounder Uno board

Now, you can see the current value of temperature displayed on the LCD, in both Celsius and Fahrenheit degrees.

Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display#define analogPin A0 //the thermistor attach to
#define beta 3950 //the beta of the thermistor
#define resistance 10 //the value of the pull-up resistorvoid setup()
{
  // set up the LCD’s number of columns and rows:
  lcd.init(); //initialize the lcd
  lcd.backlight(); //open the backlight
  Serial.begin(9600);
}void loop()
{
  long a =1023 – analogRead(analogPin); //read thermistor value
  Serial.print(“Raw reading “);
  Serial.println(a);
  //the calculating formula of temperature
  float tempC = beta /(log((1025.0 * 10 / a – 10) / 10) + beta / 298.0) – 273.0;
  float tempF = 1.8*tempC + 32.0;
  Serial.print(“Centigrade “);
  Serial.println(tempC);
  Serial.print(“Fahrenheit “);
  Serial.println(tempF);
  Serial.println(“”);  // Print a message of “Temp: “to the LCD.
  lcd.setCursor(0, 0);// set the cursor to column 0, line 0
  lcd.print(“Temp: “); // Print a message of “Temp: “to the LCD.
  lcd.print(tempC); // Print a centigrade temperature to the LCD.
  // Print the unit of the centigrade temperature to the LCD.
  lcd.write(char(223));
  lcd.print(“C”);//print the unit” ℃ “
  lcd.setCursor(0, 1);// set the cursor to column 0, line 1
  lcd.print(“Fahr: “);
  lcd.print(tempF);// Print a Fahrenheit temperature to the LCD.
  lcd.write(char(223)); // Print the unit of the Fahrenheit temperature to the LCD.
  lcd.print(” F”);//print the unit”°F”
  delay(200); //wait for 100 milliseconds