MAKE AN ARDUINO TEMPERATURE SENSOR
(THERMISTER TUTORIL)
Hardware Required
R1) The value of R1 will depend on your thermistor. If you use the 100 K Ohms Thermistor, it will be 4.7K Ohms,
R2) The value of R2 is 100 K Ohms Thermistor,
C1) Electrolytic capacitors have a polarity & the value is 10uF 16V. Make sure the stripe on yours matches the one in the picture.
Arduino or Genuino Board
LCD Screen 16 x 2
LCD Screen 16 x 2
pin headers to solder to the LCD display pins
10k ohm potentiometer
220 ohm resistor
4.7 K Ohm Resistor
10 uF, 16 V Polarized Capacitor
100k NTC Thermister (3D Printer)
hook-up wires
THERMISTOR
i am using my 3D Printer Hot end Thermistor the resister value is 100 K Ohms.
SCHEMATICS
R1) The value of R1 will depend on your thermistor. If you use the 100 K Ohms Thermistor, it will be 4.7K Ohms,
R2) The value of R2 is 100 K Ohms Thermistor,
C1) Electrolytic capacitors have a polarity & the value is 10uF 16V. Make sure the stripe on yours matches the one in the picture.
CONNECT THE CIRCUIT
Connect the thermistor & resistor & capacitor to your Arduino like this
i am using 100 K Ohms NTC Thermistor, so my resistor is 4.7 K Ohms, and The Capacitor Value is 10uF 16V.
CODE FOR SERIAL MONITOR OUTPUT OF TEMPERATURE READINGS
#define THERMISTOR_PIN 0
#define NUMTEMPS 20
short temptable[NUMTEMPS][2] = {
{1, 841},
{54, 255},
{107, 209},
{160, 184},
{213, 166},
{266, 153},
{319, 142},
{372, 132},
{425, 124},
{478, 116},
{531, 108},
{584, 101},
{637, 93},
{690, 86},
{743, 78},
{796, 70},
{849, 61},
{902, 50},
{955, 34},
{1008, 3}
};
void setup()
{
Serial.begin(9600);
Serial.println("Starting temperature exerciser.");
}
void loop()
{
int rawvalue = analogRead(THERMISTOR_PIN);
int celsius = read_temp();
int fahrenheit = (((celsius * 9) / 5) + 32);
Serial.print("Current temp: ");
Serial.print(celsius);
Serial.print("C / ");
Serial.print(fahrenheit);
Serial.println("F");
Serial.print("Raw value: ");
Serial.println(rawvalue);
Serial.println(" ");
delay(1000);
}
int read_temp()
{
int rawtemp = analogRead(THERMISTOR_PIN);
int current_celsius = 0;
byte i;
for (i=1; i<NUMTEMPS; i++)
{
if (temptable[i][0] > rawtemp)
{
int realtemp = temptable[i-1][1] + (rawtemp - temptable[i-1][0]) * (temptable[i][1] - temptable[i-1][1]) / (temptable[i][0] - temptable[i-1][0]);
if (realtemp > 255)
realtemp = 255;
current_celsius = realtemp;
break;
}
}
// Overflow: We just clamp to 0 degrees celsius
if (i == NUMTEMPS)
current_celsius = 0;
return current_celsius;
}
This program will display Celsius and Fahrenheit and also Raw Value at the same time:
CODE FOR LCD OUTPUT OF TEMPERATURE READINGS
in this code help you to output the temperature readings to a 16X2 LCD Display:
#include <LiquidCrystal.h>
#define THERMISTOR_PIN 0
#define NUMTEMPS 20
short temptable[NUMTEMPS][2] = {
{1, 841},
{54, 255},
{107, 209},
{160, 184},
{213, 166},
{266, 153},
{319, 142},
{372, 132},
{425, 124},
{478, 116},
{531, 108},
{584, 101},
{637, 93},
{690, 86},
{743, 78},
{796, 70},
{849, 61},
{902, 50},
{955, 34},
{1008, 3}
};
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // set up the LCD's number of columns and rows:
void setup()
{
lcd.begin(16, 2); // Print a message to the LCD
}
void loop()
{
int rawvalue = analogRead(THERMISTOR_PIN);
int celsius = read_temp();
int fahrenheit = (((celsius * 9) / 5) + 32);
lcd.setCursor(0,0); // set the cursor to column 0, line 1
lcd.print("Temp = "); // Print a message to the LCD.
lcd.print(celsius);
lcd.print("C/"); // Print a message to the LCD.
lcd.print(fahrenheit);
lcd.print("F"); // Print a message to the LCD.
lcd.setCursor(0,1); // (note: line 1 is the second row, since counting begins with 0):
lcd.print("Raw value: "); // Print a message to the LCD.
lcd.print(rawvalue);
lcd.print(" "); // Print a message to the LCD.
delay(1000);
lcd.clear();
}
int read_temp()
{
int rawtemp = analogRead(THERMISTOR_PIN);
int current_celsius = 0;
byte i;
for (i=1; i<NUMTEMPS; i++)
{
if (temptable[i][0] > rawtemp)
{
int realtemp = temptable[i-1][1] + (rawtemp - temptable[i-1][0]) * (temptable[i][1] - temptable[i-1][1]) / (temptable[i][0] - temptable[i-1][0]);
if (realtemp > 255)
realtemp = 255;
current_celsius = realtemp;
break;
}
}
// Overflow: We just clamp to 0 degrees celsius
if (i == NUMTEMPS)
current_celsius = 0;
return current_celsius;
}
Video Tutorial of the Temperature Sensor :
Here’s a video so you can watch and see how it works:
Just leave a comment below if you have any questions about this project.And if you like our articles here & subscribe and we’ll let you know when we publish new articles.
No comments:
Post a Comment