Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The Steel Head 10K NTC thermistor is a temperature sensor whose resistance changes with temperature. Here's a simple Arduino code to read the sensor's output and display the temperature on the Serial Monitor using the Steinhart-Hart equation:
- To wire the Steel Head 10K NTC thermistor, connect one leg of the thermistor to the 5V pin on the Arduino and the other leg to the NTC_PIN (analog pin A0) on the Arduino. Connect a 10KΩ resistor between the NTC_PIN (analog pin A0) and the ground.
- This code will continuously read the sensor's output and print the raw readings, the calculated resistance, and the temperature in Celsius on the Serial Monitor. Make sure to adjust the R0, BETA, and SERIES_RESISTOR values according to your specific thermistor and the resistor used in the voltage divider circuit.
- */
- const int NTC_PIN = A0; // NTC thermistor connected to analog pin A0
- // Thermistor parameters
- const float T0 = 298.15; // Reference temperature in Kelvin (25°C)
- const float R0 = 10000.0; // Resistance at reference temperature (10K)
- const float BETA = 3950.0; // Beta constant for the thermistor (check datasheet)
- const float VOLTAGE_REF = 5.0;
- const float SERIES_RESISTOR = 10000.0; // Series resistor value (10K)
- void setup() {
- Serial.begin(9600);
- }
- void loop() {
- int sensorValue = analogRead(NTC_PIN);
- // Calculate the voltage across the thermistor
- float voltage = sensorValue * (VOLTAGE_REF / 1023.0);
- // Calculate the thermistor resistance
- float resistance = SERIES_RESISTOR * (VOLTAGE_REF / voltage - 1.0);
- // Calculate the temperature using the Steinhart-Hart equation
- float temperatureK = 1.0 / (1.0 / T0 + (1.0 / BETA) * log(resistance / R0));
- float temperatureC = temperatureK - 273.15;
- Serial.print("Sensor Value: ");
- Serial.println(sensorValue);
- Serial.print("Resistance: ");
- Serial.print(resistance);
- Serial.println(" Ohms");
- Serial.print("Temperature: ");
- Serial.print(temperatureC);
- Serial.println(" °C");
- delay(1000); // Wait 1 second between readings
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement