Skip to content

Instantly share code, notes, and snippets.

@fxprime
Created October 26, 2019 09:35
Show Gist options
  • Save fxprime/c472a95ef13549ca20fd44d55396fec4 to your computer and use it in GitHub Desktop.
Save fxprime/c472a95ef13549ca20fd44d55396fec4 to your computer and use it in GitHub Desktop.
Temperature sensor module KY-013
int ThermistorPin = A0;
int Vo;
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 setup() {
Serial.begin(9600);
}
void loop() {
Vo = analogRead(ThermistorPin);
R2 = R1 * (1023.0 / (float)Vo - 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
Serial.print("Temperature: ");
Serial.print(T);
Serial.println(" C");
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment