Lesson 4 Analog Temperature Sensor

Share for us
Share on facebook
Share on twitter
Share on pinterest
Share on whatsapp

Introduction

A temperature sensor is a component that senses temperature and converts it into output signals. By material and component features, temperature sensors can be divided into two types: thermal resistor and thermocouple. Thermistor is one kind of the former type. It is made of semiconductor materials; most thermistors are negative temperature coefficient (NTC) ones, the resistance of which decreases with rising temperature. Since their resistance changes acutely with temperature changes, thermistors are the most sensitive temperature sensors.

The Analog Temperature Sensor module uses an NTC thermistor, thus measuring temperature sensitively. It also has a built-in comparator LM393 which enables the module to output both digital and analog signals at the same time. The module can be used for temperature alarm and temperature measurement.

Components

– 1 * SunFounder Uno board

– 1 * USB data cable

– 1 * Analog temperature sensor module

– 1 * 4-Pin anti-reverse cable

Experimental Principle

There is a comparator LM393 on the analog temperature sensor module. You may set a threshold by the potentiometer on it. When you touch the thermistor, the value of A0 decreases. Once the value is lower than the threshold, D0 will output high level and the indicator LED on the analog temperature sensor module and that attached to pin 13 of the SunFounder Uno will go out. You can check the value of A0 and D0 on Serial Monitor. 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)

Step 3: Compile

Step 4: Upload the sketch to SunFounder Uno board

Now, touch the thermistor, and the LED on the analog temperature sensor module and that attached to pin 13 of the SunFounder Uno will go out. 

 Code

//Analog Temperature Sensor
const int digitalPin = 7; // Analog Temperature Sensor pin D0 to pin7
int analogPin = A0; // Analog Temperature Sensor pin A0 to pin A0
const int ledPin = 13; // pin 13 built-in LED light// variables will change:
boolean Dstate = 0; // variable for reading status of D0
int Astate = 0; // variable for reading status of A0
void setup()
{
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output:
pinMode(digitalPin, INPUT); // initialize Analog Temperature Sensor D0 pin as an input
Serial.begin(9600); // initialize serial communications at 9600 bps}void loop()
{
Astate = analogRead(analogPin); // read Analog Temperature Sensor A0 value (set point)
Dstate = digitalRead(digitalPin); // read state of Analog Temperature Sensor D0
Serial.print(“D0: “);
Serial.println(Dstate);//print the value of D0
Serial.print(“A0:”);
Serial.println(Astate);//print the value of A0
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (Dstate == HIGH) // check if Analog Temperature Sensor D0 is HIGH
{
// turn LED on:
digitalWrite(ledPin, LOW);
}
else
{
// turn LED off:
digitalWrite(ledPin, HIGH);
}
delay(1000); // controls speed of Analog Temperature Sensor and Serial Monitor display rate