Thermistor Sensor
The thermistor module is most sensitive to environmental temperature and is generally used to detect the surrounding temperature. When the ambient temperature does not reach the set threshold, the DO pin outputs a high level. When the external temperature exceeds the set threshold, the module's D0 pin outputs a low level. The digital output D0 can be directly connected to a microcontroller, allowing it to detect the high or low levels and thus monitor the temperature changes in the environment. The analog output AO can be connected to the analog interface of the development board. By performing an AD conversion, a more precise value of the ambient temperature can be obtained.
Module Source
Purchase Link:
https://item.taobao.com/item.htm?abbucket=17&id=522574958332&ns=1&spm=a21n57.1.item.49.5585523cAHDUbW
Baidu Netdisk Download Link:
http://pan.baidu.com/s/1pL1DyuZ
Specifications
Operating Voltage: 3.3V-5V
Sensitivity: Adjustable sensitivity (via blue digital potentiometer) Output Type:
DO interface: Digital output
AO interface: Analog output
Reading Method: ADC and digital levels (0 and 1)
Pin Count: 4 Pin (2.54mm pitch header)
Hardware Connection
- Connect the Vcc pin of the sensor to the 5V power supply of the development board.
- Connect the GND pin to the GND of the development board.
- Connect the AO (analog output) pin to the A0 analog input pin of the development board.
- The DO (digital output) pin in this case is connected as needed; if required, you can configure a digital pin (such as pin 2) and set it to input mode.
Usage Method
- Calculate the Resistance Value:
- When the analog input pin reads a voltage, it needs to be converted to the resistance value of the thermistor. This typically involves using the analog input reading (which ranges from 0 to 1023) and the reference voltage of the development board to calculate the intermediate voltage in the voltage divider circuit.
- Then, use this voltage value and the known resistance value of the fixed resistor to calculate the resistance of the thermistor using Ohm's Law.
- Convert to Temperature:
- Use the specific temperature-resistance characteristics of the thermistor to convert the resistance value into temperature. This often involves looking up a table or using a formula such as the Steinhart-Hart equation to calculate the temperature.
Enter the code:
/******************************************************************************
* Test Hardware: LCSC ColorEasyDuino Development Board
* Version Number: V1.0
* Modified By: www.lckfb.com
* Modification Date: April 9, 2024
* Function Overview:
*****************************************************************************
* Open-source development board hardware and software information and related projects hardware and software information on official website
* Development board official website: www.lckfb.com
* Technical support resident forum, any technical problems are welcome at any time to exchange learning
* LCSC Forum: club.szlcsc.com
* Follow our Bilibili account: [立创开发板], stay toned to our latest news!
* We focus on cultivating Chinese engineers rather than profiting from board sales.
******************************************************************************/
const float BETA = 3950; // 热敏电阻的Beta系数
void setup() {
Serial.begin(9600);
}
void loop() {
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
delay(1000);
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28