Skip to content

Commit 9453c58

Browse files
committed
update NTC sensor.
1 parent 37fbb61 commit 9453c58

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

‎sensor/NTC/README.md‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
11
# NTC thermistor
22

3-
NTC thermistor Sensor
3+
NTC thermistor Sensor.
44

55
![](ntc.jpg)
66

77

8+
There are two connection methods for NTC resistors: NTC connected to VCC or GND, as shown in the figure.
9+
10+
![](ntc1.jpg)
11+
12+
13+
## description
14+
15+
- NTC_GND(adc, max, B=3780)
16+
- NTC_VCC(adc, max, B=3780)
17+
18+
Convert numerical values to Celsius temperature.
19+
20+
- adc, NTC input value, it can be voltage or ADC value.
21+
- max, maximum value for ADC, it can be voltage (usually Vcc) or ADC value.
22+
- B, B value of NTC resistor.
23+
24+
If using esp32 series chips, use ADC.read_uv() to get ADC value for best optimal accuracy.
25+
826

927
## example
1028

1129
```python
1230
from machine import ADC, Pin
1331

14-
ADC_TEMP = ADC(Pin(34))
15-
T = NTC(ADC_TEMP.read())
32+
ADC_T1 = ADC(Pin(34), atten=ADC.ATTN_11DB)
33+
ADC_T2 = ADC(Pin(33), atten=ADC.ATTN_11DB)
34+
35+
T1 = NTC_VCC(ADC_T1.read_uv()/1000, 3300)
36+
T2 = NTC_GND(ADC_T2.read_uv()/1000, 3300, B=3950)
1637
```
1738

1839
From microbit/micropython Chinese community.

‎sensor/NTC/ntc.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
mpy drive for NTC thermistor Sensor
33
44
Author: shaoziyang
5-
Date: 2020.12
5+
Date: 2024.4
66
77
http://www.micropython.org.cn
88
99
'''
1010
import math
1111

12-
def NTC(adc, B=3780, bits=12):
13-
t1 = math.log(adc/((1<<bits)-adc))/B + 1/298.15
14-
return 1/t1 - 273.15
12+
def NTC_GND(adc, max, B=3780):
13+
t1 = math.log(adc/(max-adc))/B + 1/298.15
14+
return 1/t1 - 273.15
15+
16+
def NTC_VCC(adc, max, B=3780):
17+
t1 = math.log((max-adc)/adc)/B + 1/298.15
18+
return 1/t1 - 273.15

‎sensor/NTC/ntc1.jpg‎

31.2 KB
Loading

0 commit comments

Comments
 (0)