lorawan/sodaq_one/temperature.ino
Nico Schottelius 95d8e8bfe5 update
Signed-off-by: Nico Schottelius <nico@wurzel.schottelius.org>
2016-10-27 18:14:29 +02:00

22 lines
410 B
C++

#include <Arduino.h>
/*
* Temp sensor:
* https://www.seeedstudio.com/Grove-Temperature-Sensor-p-774.html
*
** NCP18WF104F03RC
*/
float getTemperature(int pin) {
int a = analogRead(pin);
const int B=4250; // B value of the thermistor
float R = 1023.0/((float)a)-1.0;
R = 100000.0*R;
float temperature=1.0/(log(R/100000.0)/B+1/298.15)-273.15;
return temperature;
}