File tree Expand file tree Collapse file tree 3 files changed +32
-7
lines changed
Expand file tree Collapse file tree 3 files changed +32
-7
lines changed Original file line number Diff line number Diff line change 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
1230from 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
1839From microbit/micropython Chinese community.
Original file line number Diff line number Diff line change 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'''
1010import 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
You can’t perform that action at this time.
0 commit comments