KY-013 Analog Temperature Sensor module
Short description :
The KY-013 Analog Temperature Sensor module can measure ambient temperature based on the resistance of the thermistor on the board.
Working with (Compatible)
Arduino, ESP32, Nodemcu, ESP8266, Raspberry Pi, and ......
ARDUINO IDE CODE
Example description :
The code will return the temperature to Celsius, to get the temperature in Fahrenheit.
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);
}
Example 2 with OLED Display:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h> #include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(-1);
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 coefficients for thermistor
void setup() {
Serial.begin(9600); // initialize with the I2C addr 0x3C
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Clear the buffer.
display.clearDisplay(); // Display Text
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10,0);
display.println("ANALOG TEMPERATURE");
display.display();
delay(2000);
display.clearDisplay();
}
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);> // Display Text
display.setTextSize(.9);
display.setTextColor(WHITE);
display.setCursor(10,0);
display.println("Temperature: " +String (T)+" c" );
display.display();
delay(2000);
display.clearDisplay();
}