-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92b6be5
commit f8a072e
Showing
2 changed files
with
52 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "../adc/adc.h" | ||
|
||
namespace temperature { | ||
// #define TEMP_PIN A0 | ||
#define TEMP_VOLAGE 3.3 | ||
|
||
int adc_channel; | ||
|
||
// https://arduinomodules.info/ky-013-analog-temperature-sensor-module/ | ||
|
||
float R1 = 10000; // value of R1 on board | ||
float logR2, R2, T; | ||
float c1 = 0.001129148, | ||
c2 = 0.000234125, | ||
c3 = 0.0000000876741; | ||
//steinhart-hart coeficients for thermistor | ||
|
||
void init(int adc_ch) { | ||
adc_channel = adc_ch; | ||
// pinMode(TEMP_PIN, INPUT); | ||
} | ||
|
||
float read() { | ||
int v = adc::read(adc_channel) * 1024.0; | ||
// int v = analogRead(TEMP_PIN); | ||
|
||
R2 = R1 * (1023.0 / (float)v - 1.0); // calculate resistance on thermistor | ||
logR2 = log(R2); | ||
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)); // temperature in Kelvin | ||
T = T - 273.15; // convert Kelvin to Celcius | ||
// T = (T * 9.0)/ 5.0 + 32.0; //convert Celcius to Farenheit | ||
return T; | ||
} | ||
} | ||
|
||
/* | ||
example: | ||
void setup() | ||
{ | ||
Serial.begin(9600); | ||
initialize_temp(); | ||
} | ||
void loop() | ||
{ | ||
Serial.print("Temperature:\t\t"); | ||
Serial.println(read_temp()); | ||
delay(1000); //waiting a second | ||
} | ||
*/ |
This file was deleted.
Oops, something went wrong.