Learning with Arduino: How to use a Thermistor

A thermistor is a type of resistor whose resistance is dependent on temperature.
Thermistors are of two opposite fundamental types:
With Negative Temperature Coefficient, NTC, resistance decreases with temperature to protect against inrush overvoltage conditions.
With Positive Temperature Coefficient, PTC, resistance increases with temperature to protect against overcurrent conditions.
The purpose of this tutorial is to understand how to use a thermistor to create a reminder to turn on either your AC or your heat based on the temperature in your house.
Note: The temperature setting in this tutorial corresponds to a specific voltage that comes out of the Analog to Digital Convertor (ADC) Reading:
Analog to Digital Converter (ADC) reading = (Voltage at Pin / 5V) * 1023
Extra Tip: To select a ADC reading based on the temperature setting of your choice, use the Steinhart-Hart equation to convert the ADC voltage readings to a setpoint temperature.

Components:
Arduino Board
Breadboard
Thermistor
1 6” USB A/B cable
3 220 ohm resistor
2 LEDs
Hookup Wires

Directions:
1. Place your thermistor on the breadboard. Connect a wire from the 5V source to the thermistor. Place a 220 Ω resistor on the other pin of the thermistor. Connect a wire from the resistor to the A0 pin. Connect a wire from the other leg of the resistor to the ground of your arudino board.
2. Connect a wire from digital pin 9 to your breadboard and then place a 220ohm resistor and a blue LED on the breadboard. Be sure to ground the LED.
3. Connect a wire from digital pin 8 to your breadboard. Next,, place a 220ohm resistor and a red LED on the breadboard. Be sure to ground the LED.

 

THE CODE:
4. Open the Arduino software and create a new sketch. Upload the code (seen below) into the sketch.

// LEDS will indicate when the heat needs to be turned on and when the AC needs to be turned on.

//400=60 degrees farenheit
//525=80 degrees farenheit

int tempPin = 0;
int temp; // the analog reading from the sensor divider
int ACSensor = 9; // connect Blue LED to pin 9
int HEATSensor = 8; // connect Red LED to pin 8
int HEATon= 400;
int ACon= 525;
void setup(void) {
Serial.begin(9600);
}

void loop(void) {
temp = analogRead(tempPin);

Serial.print(“Temp = “);
Serial.println(temp); // reading the values

if (temp <= HEATon){ digitalWrite (ACSensor, LOW); digitalWrite (HEATSensor, HIGH); } else if (temp >= ACon){
digitalWrite (ACSensor, HIGH);
digitalWrite (HEATSensor, LOW);
}
else
{
digitalWrite (ACSensor, LOW);
digitalWrite (HEATSensor, LOW);
delay(10);
}
}

5. Connect a USB A/B cable from your computer to the Arduino. Click “Upload” in the Arduino program to run your sketch.
6. Finally, to test your code,  set both the AC and heat temperature setting to the current temperature setting in your house to light the LEDs.

corra02

Leave a Reply

Your email address will not be published. Required fields are marked *