Experiment 4 - Temperature Sensor
Experiment 4 - Temperature Sensor
Components required:
Software Hardware
Arduino UNO Board
Arduino UNO Cable
Tinkercad Temperature Sensor
Arduino IDE (To be installed in Laptop) LED (Red-1, Green-1, Blue-1)
LCD Display (16*2)
Resistors – 5 (220Ω each)
Jumper wires
Pre-Requisites:
Pre-Lab:
A thermistor is a type of temperature sensor that changes its resistance with temperature
variations. Specifically, we will be using an NTC (Negative Temperature Coefficient)
thermistor, which has a higher resistance at lower temperatures and lower resistance at
higher temperatures. By measuring the resistance of the thermistor, we can determine
the temperature.
2. How is the thermistor connected to the Arduino Genuino UNO?
The thermistor is connected to the Arduino Genuino UNO using two wires. One end of
the thermistor is connected to the 5V pin of the Arduino, and the other end is connected
to an analog input pin (e.g., A0). Additionally, a resistor (typically 10k ohms) is
connected in parallel with the thermistor, with one end connected to the analog input
pin and the other end connected to ground.
3. How can we convert the analog reading from the thermistor into temperature
values?
We can convert the analog reading from the thermistor into temperature values using
either the Steinhart-Hart equation or a lookup table. The Steinhart-Hart equation is a
mathematical formula that relates the resistance of the thermistor to temperature. A
lookup table, on the other hand, maps specific resistance values to corresponding
temperature values.
4. What is the purpose of the resistor connected in parallel with the thermistor?
The resistor connected in parallel with the thermistor forms a voltage divider circuit. It
helps to create a known reference voltage for the analog input pin of the Arduino. This
allows us to accurately measure the voltage across the thermistor and calculate its
resistance, which is then used to determine the temperature.
To improve accuracy, we can calibrate the thermistor by comparing its readings with a
known temperature source. This allows us to create a more accurate mapping between
resistance and temperature. Additionally, ensuring a stable power supply and
minimizing noise interference can also improve the accuracy of temperature
measurements.
In-Lab:
Program:
void setup()
{
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4, OUTPUT);
}
void loop()
{
int baselineTemp = 30;
int sensor_data = analogRead(A0);
float voltage = sensor_data * (5.0 / 1024.0);
float celsius = (voltage - 0.5) * 100;
float fahrenheit = ((celsius*9) / 5 + 32);
Serial.print(celsius);
Serial.print(" C, ");
Serial.print(fahrenheit);
Serial.println(" F");
if (celsius < baselineTemp)
{
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
Procedure:
Give the connections to the Arduino board as shown in the connection diagram.
Open Arduino IDE in the computer
Create new file File_--→ New
Type your program and Save it in appropriate location in your computer.
Compile your program by clicking Verify option in the menu.
Once the program compiled successfully, connect the Arduino board to the computer
using USB cable.
After connecting, go to Tools ----→Board ---→ Select Arduino/Genuino Uno option
After selecting board, go to Tools ----→Port ---→ Select Arduino Uno COM port 3
(name may appear differently for other computers).
**Note: that this port option will be displayed only when board is connected to computer
Now upload the program to the Arduino board by clicking Upload option.
Observe the output.
Connection Diagram:
Results:
1. What is a thermistor?
A thermistor is a type of temperature sensor that changes its resistance with temperature
variations.
3. How can we convert the analog reading from the thermistor into temperature
values?
We can convert the analog reading from the thermistor into temperature values using
either the Steinhart-Hart equation or a lookup table.
Program:
// Defining pin
#define temp A5
#define led 13
void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(led, OUTPUT);
pinMode(temp, INPUT);
Serial.begin(9600);
lcd.clear();
lcd.print("Temperature: ");
}
//Global Variable
float pre_temp = 0;
void loop()
{
float temperature = 0;
temperature = (analogRead(temp) * 0.48828125) - 49.95;
if(pre_temp != temperature)
{
lcd.setCursor(0,1);
lcd.print(" ");
}
lcd.setCursor(0,1);
lcd.print(temperature);
lcd.print(" C");
pre_temp = temperature;
}
Results: