# Lesson 13 Temperature Monitoring and Alarm

##### Share for us

Introduction

In this lesson, we will use a thermistor and a buzzer to make a temperature monitoring and alarm system.

Components

– 1*Raspberry Pi

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

– 1*Thermistor

– 1*Buzzer

– 1*NPN transistor (8050)

– 1*Resistor (1KΩ)

– 1*Resistor (10KΩ)

– Jumper wires

Experimental Principle

We use an ADC0832 to convert the analog temperature collected by the thermistor to digital temperature. When the result is greater than 200 degrees Celsius, the buzzer will alarm.

Experimental Procedures

Step 1: Connect the circuit

Step 2: Edit and save the code(see path/Rpi_UniversalStartKit /13_tempMonitor/tempMonitor.c)

Step 3: Compile the code

gcc  tempMonitor.c  -lwiringPi

Step 4: Run the program

./a.out

Press Enter, if use a lighter to burn the thermistor, you will hear the buzzer alarm.

C Code

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

typedef unsigned char uchar;
typedef unsigned int  uint;

#define     Beep      3

void beepInit(void)
{
pinMode(Beep, OUTPUT);
digitalWrite(Beep, 0);
}

void beep(void)
{
digitalWrite(Beep, 1);
delay(200);
digitalWrite(Beep, 0);
delay(200);
}

{
//10:CH0
//11:CH1
uchar i;
uchar dat1=0, dat2=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;
}

beepInit();

while(1){
beep();
}
}

return 0;
}``````

Python Code

``````#!/usr/bin/env python
import RPi.GPIO as GPIO
import time

BeepPin = 15

def printMsg():
print 'Press Ctrl+C to end the program...'

def beepInit():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(BeepPin, GPIO.OUT)
GPIO.output(BeepPin, GPIO.LOW)

def beep():
GPIO.output(BeepPin, GPIO.HIGH)
time.sleep(0.2)
GPIO.output(BeepPin, GPIO.LOW)
time.sleep(0.2)

def loop():
while True: