Skip to content

Instantly share code, notes, and snippets.

@jfgomez86
Created February 24, 2017 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfgomez86/4aa99ca163d9c17b2bee27b745a9280b to your computer and use it in GitHub Desktop.
Save jfgomez86/4aa99ca163d9c17b2bee27b745a9280b to your computer and use it in GitHub Desktop.
Just a simple code to measure temperature with a 503 NTC Thermistor. (http://imgur.com/a/zog8f)
// include the library code:
#include <LiquidCrystal.h>
#include <math.h>
#define BUTTON_PIN A0
#define THERMISTOR_PIN A1
#define SERIES_RESISTOR 56000.0f
#define SAMPLE_SIZE 100
#define KELVIN 273.15f
#define R0 50000.0f
#define T0 298.5f // 25C
#define B 4204.0f // +- 2%
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
float temperature() {
float reading, average_reading, temp;
average_reading = 0;
for (uint8_t i=0; i < SAMPLE_SIZE ; i++) {
average_reading += float(analogRead(THERMISTOR_PIN));
}
average_reading = average_reading / SAMPLE_SIZE;
reading = SERIES_RESISTOR / (1023.0f / average_reading - 1);
temp = 1.0f/(1.0f/T0+(1.0f/B)*log(reading/R0)) - KELVIN;
return temp;
}
void readTemp() {
lcd.setCursor(0, 1);
lcd.print(temperature());
}
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Temperature C:");
}
void loop() {
bool display_on;
display_on = true;
if (millis() % 2000 == 0) readTemp();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment