Skip to content

Commit 2104034

Browse files
committed
Implemented temperature display with NTC
1 parent c08d877 commit 2104034

File tree

4 files changed

+76
-5
lines changed

4 files changed

+76
-5
lines changed

engineering-notes/temperature-sensor.txt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,34 @@ Objective: Measure ambient temperature between 0°C to 100°C
66
- The D1 analog port has an impedance of 320k to ground
77
- The NTC is connected to the 3v3 supply
88

9-
Calculation with a 100k NTC (TTC05104)
9+
Calculations with a 100k NTC (TTC05104) https://www.taydaelectronics.com/datasheets/A-410.pdf
1010

1111
Resistance: 0°C 350k -> 492mV
1212
25°C 100k -> 785mV
1313
60°C 20k -> 970mV
1414
100°C 4.5k -> 1019mV
1515

16+
Calculate ADC voltage from NTC resistance:
17+
18+
Vadc = 3.3V*320/(NTC+320k)
19+
20+
Calculate NTC resistance from ADC voltage
21+
22+
NTC = Vadc/3.3V*100k-320k
23+
24+
ADC readings at different temperatures:
25+
26+
Freezer -22°C 266/252/247/235/228/225
27+
Fridge 8°C 687/792/856/763/634/629/632
28+
Living 25°C 775/792
29+
Oven 55°C 992/
30+
Oven 65°C 1015/
31+
Oven 99°C 1015
32+
33+
The beta calculation to get temperature from the NTC seems to be working nicely.
34+
Ref: https://www.jameco.com/Jameco/workshop/TechTip/temperature-measurement-ntc-thermistors.html
35+
36+
const float R0 = 100000; // Base resiatnce value at base temperature from data sheet
37+
const float B = 4400; // Beta (from ntc data sheet)
38+
const float T0 = 298.15; // base temperature 25°C in Kelvin (273.15 + 25)
1639

esp-dmx.ino

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ long last_looplat=0; // saved loop latency for display on serial port
8282
uint16_t seen_universe = 0; // universe number of last seen artnet frame
8383
int last_rssi; // Wifi RSSI for display
8484

85+
int temperature = 0; // temperature in deg c
86+
int tempAdc = 0; // temperature reading from ADC
87+
#define ANALOGPIN A0 //
88+
8589
#define NEOPIXEL
8690

8791
// Status codes for display
@@ -120,6 +124,44 @@ void setStatusLED(int color) {
120124
#endif
121125
}
122126

127+
128+
/*
129+
* Temperature measurements
130+
*/
131+
132+
// https://www.jameco.com/Jameco/workshop/TechTip/temperature-measurement-ntc-thermistors.html
133+
// definitions here for a TTC05104
134+
const float R0 = 100000; // Base resiatnce value at base temperature from data sheet
135+
const float B = 4400; // Beta (from ntc data sheet)
136+
const float T0 = 298.15; // base temperature 25°C in Kelvin (273.15 + 25)
137+
float betaNTC(float R) {
138+
float T;
139+
T = 1/(1/T0 + 1/B*log(R/R0));
140+
T = T - 273.15;
141+
return T;
142+
}
143+
144+
float ntcRes;
145+
int readTemperature () {
146+
// read the ADC
147+
int i = analogRead(ANALOGPIN);
148+
149+
// initialize the smooting on the first call
150+
if (tempAdc == 0) {
151+
tempAdc = i;
152+
} else {
153+
// smooth the ADC reading, the new reading get 10% weight
154+
tempAdc = ((tempAdc * 9) + i) / 10;
155+
}
156+
157+
// calculate the NTC resistance
158+
ntcRes = 330000000/tempAdc-320000;
159+
160+
// calculate temparature from NTC resistance
161+
temperature = int(betaNTC(ntcRes));
162+
}
163+
164+
123165
/*
124166
* Artnet packet routine
125167
*
@@ -236,7 +278,7 @@ void setup() {
236278
WiFi.begin(MYSSID, MYPASS);
237279
while (WiFi.status() != WL_CONNECTED) {
238280
Serial.print(".");
239-
delay(500);
281+
delay(2000);
240282
}
241283
Serial.println();
242284
#endif
@@ -296,7 +338,8 @@ void setup() {
296338
* Main loop for processing
297339
*/
298340
void loop() {
299-
341+
readTemperature();
342+
300343
// handle web service
301344
webServer.handleClient();
302345

@@ -309,7 +352,7 @@ void loop() {
309352
// Main processing here
310353
if (WiFi.status() != WL_CONNECTED) {
311354
// If no wifi, then show red LED
312-
setStatusLED(LED_RED);
355+
setStatusLED(LED_ORANGE);
313356
Serial.println("ESP-DMX loop: No wifi connection !!!");
314357
delay(100);
315358
} else {

statusLED.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// Color codes for LED, Format 0xrrggbb
99
#define LED_OFF 0x0000000
1010
#define LED_RED 0x0660000 // Initial boot
11+
#define LED_ORANGE 0x0553300 // Wifi lost
1112
#define LED_YELLOW 0x0666600 // Setting up Wifi
1213
#define LED_PINK 0x0660066 // Connected to wifi, ready for DMX
1314
#define LED_CYAN 0x0006666 // Observing DMX, but other universe

webui.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern int last_rssi;
3030
extern void setStatusLED(int);
3131
extern float fps;
3232
extern globalStruct global;
33+
extern int temperature;
3334

3435
/*
3536
* Set default config on initial boot if there is no configuration yet
@@ -233,6 +234,9 @@ void http_index() {
233234
page += "<tr><td>Artnet packets processed:</td><td>"; page += dmxUMatchCounter; page += "</td></tr>\n";
234235
page += "<tr><td>Artnet packet length:</td><td>"; page += global.length; page += " (channels)</td></tr>\n";
235236
page += "<tr><td>Status:</td><td>"; page += status_text[status], page += "</td></tr>\n";
237+
// page += "<tr><td>Device temperature:</td><td>"; page += temperature; page+= "/"; page += tempAdc; page+= "/"; page += ntcRes; page += "</td></tr>\n";
238+
page += "<tr><td>Device temperature:</td><td>"; page += temperature; page += "</td></tr>\n";
239+
page += "<tr><td>Device uptime (s):</td><td>"; page += millis()/1000, page += "</td></tr>\n";
236240
page += "</table>\n";
237241
page += http_foot();
238242

@@ -343,7 +347,7 @@ void http_restart () {
343347
if (webServer.method() == HTTP_POST) {
344348
Serial.println("POST (reset)");
345349
Serial.println("Resetting device");
346-
setStatusLED(0x0ff0000); // red
350+
setStatusLED(LED_RED); // red
347351
head = "<head><title>"+config.hostname+"</title><meta http-equiv='refresh' content='15;url=/'></head>\n";
348352
body += "<h1 style='align: center;'>Resetting ...</h1><p>\n";
349353
webServer.send(200, "text/html", head+body+foot);

0 commit comments

Comments
 (0)