# Lesson 9 Thermistor

##### Share for us

Introduction

thermistor is a type of resistor whose resistance varies significantly with temperature.

Components

– 1*Raspberry Pi

– 1*Network cable (or USB wireless network adapter)

– 1*Thermistor

– 1*Resistor (10K)

– Several jumper wires

Experimental Principle

When the temperature increases, the thermistor resistance decreases; when the temperature decreases, the thermistor resistance increases. It can detect surrounding temperature changes in real time.

Experimental Procedures

Step 1: Connect the circuit

Step 2: Edit and save the code(see path/ Rpi_UniversalStartKit /09_thermistor/ thermistor.c)

Step 3: Compile the code

gcc  thermistor.c  -lwiringPi

Step 4: Run the program

./a.out

Press Enter, if you touch the thermistor, you can see current temperature value displayed on the screen change accordingly.

thermistor.c

``````#include <wiringPi.h>
#include <stdio.h>

typedef unsigned char uchar;
typedef unsigned int  uint;

{
//10:CH0
//11:CH1
uchar i;
uchar dat1=0, dat2=0;

digitalWrite(ADC_DIO,1);    delayMicroseconds(2); //CH0 10

digitalWrite(ADC_DIO,0); delayMicroseconds(2); //CH0 0

for(i=0;i<8;i++)
{

}

for(i=0;i<8;i++)
{
}

return(dat1==dat2) ? dat1 : 0;
}

int main(void)
{

if(wiringPiSetup() == -1){
printf("setup wiringPi failed !");
return 1;
}

while(1){

delay(400);
}

return 0;
}
``````

Python Code

``````#!/usr/bin/env python
import time

def init():

def loop():
while True: