Вы находитесь на странице: 1из 10

Name : Deep Shah

Introduction :

There are 3 temperature sensors , 1 button and 3 leds used in the project .Consider the
temperature sensors are installed in the boggies of the train.Initially the temperature of the sensors
are set to 30 degrees and you change the degree of the sensor by just clicking on the up and down
keys,then the data pin of the sensor is connected to the pin of the microcontroller to take the input
from snesor to the microcontroller.

As the there only one to one connection between the microcontoller and the sensor and we
need to pass 40 bits ,so the bits are passed serially one after the other to the microcontroller.

After data is received to microcontroller from sensor ,it will check temperature
differences of the all the 3 sensors ,if the difference is greater then 7, then the buzzer will
ring and if the fire is in compartment 1 then LED1 will glow or in compartment 2 then LED2
will glow else LED3 will glow ,so the buzzer will notify that something is burning and the LED
will specify compartment number of the train where the fire is rising.

Resources used for project :

We have used Proteus 8 Professional IDE to develop our project. Following components have been
used:

1. 8051 Microcontroller :
ROM-less, 128B RAM, 4x8 bit I/0, 3x16 bit Timers, Full Duplex UART.
2. Temperature sensor :
Humidity & Temperature sensor(DHT11).
3. Buzzer :
Generic buzzer symbol.
4.Button :
SPST(Single pole single throw) push button.
5.LED :
Animated LED model(Blue).

Working of Project:

1.Working of Temperature sensor:


It is a temperature and humidity sensor DHT11 which senses the temperature and
humity. It is a single row 4-pin package and operates from 3.5 to 5.5V power supply.It can
measure temperature from 0-50 C with an accuracy of 2C and relative humidity ranging
from 20-95% with an accuracy of 5%. The sensor provides fully calibrated digital outputs for
the two measurements.

The sensor sends 40 bits (5 bytes) of data continuously in the data line.Note that
while transmitting bytes, the sensor sends the most significant bit first.

The representation of 40 bits is done as follows:

data (40-bit) = Integer Byte of RH + Decimal Byte of RH + Integer Byte of Temp. +


Decimal Byte of Temp. + Checksum Byte

The last byte is the checksum byte which is used to make sure that the data transfer
has happened without any error.If all the five bytes are transferred successfully then the
checksum byte must be equal to the last 8 bits of the sum of the first four bytes, i.e.,

Checksum = Last 8 bits of (Integer Byte of RH + Decimal Byte of RH + Integer Byte of Temp. +
Decimal Byte of Temp.)

The three control lines are referred to as Vcc , Gnd and Data:

1. Vcc

This Vcc line is used for power supply to the temperature sensor.As the sensor operates
from 3.5 to 5.5V power supply so it will require a pin that gives power to the sensor.

2. Gnd

This pin is used to connect to conncect the sensor to the low voltage.

3. Data line

It is used to pass 40 bit data to the microcontroller . The data is passed serially bits by
bits to the microcontroller as there is only 1 pin to pass the data .

2.Working of buzzer :
As mentioned above there are 3 temperature sensors ,one for each compartment ,so the
microcontroller will take the temperature from the sensors and calculate the difference in the
temperature and if the difference is greater than 7 ,then the buzzer will starting ringing and if you
need to stop the buzzer then there is also a button to switch if off.

comp12 = abs(I_Temp - I_Temp2);


comp23 = abs(I_Temp2 - I_Temp3);
comp13 = abs(I_Temp - I_Temp3);
if(comp12>7 || comp23>7 || comp13>7){
buzz1=0;
}
if(comp12<=7 && comp23<=7 && comp13<=7){
buzz1=1;
}

3.Working of LEDs :

There are 3 LEDs used in the project and they are named after the compartment name. So
till now there was only buzzer which can notify that there is fire in the train but we wont know
where is the actual location ,so to get the location of the fire we thought of using LEDs , So if the
temperature of comparment 1 is higher and in rest compartment the temperature is lower then that
is obvious that there is fire in compartment 1 , so if the difference is greater then 7 then it will check
for the maximum temperature between the compartments and if the temperature is maximum for
compartment 1 then LED1 will glow and respectively for all the compartments.

if(max==I_Temp && comp12>7){


led1=1;
led2=0;
led3=0;
}
if(max==I_Temp2 && comp23>7){
led2=1;
led1=0;
led3=0;
}
if(max==I_Temp3 && comp13>7){
led3=1;
led1=0;
led2=0;
}
if(I_Temp==I_Temp2 && I_Temp2==I_Temp3 && comp12<=7 && comp23<=7 && comp13<=7){
led1=0;
led2=0;
led3=0;
}

Code :

/* Main.c file generated by New Project wizard


*
* Created: Fri Mar 31 2017
* Processor: 80C31
* Compiler: Keil for 8051
*/
#include <reg51.h>
#include <stdio.h>
#include<string.h>
#include <stdlib.h>
sbit DHT11=P2^0;
sbit DHT12=P2^1;
sbit DHT13=P2^2;
sbit buzz1=P1^0;
sbit led1=P3^2;
sbit led2=P3^1;
sbit led3=P3^0;
int max=0;
int I_RH,D_RH,I_Temp,D_Temp,CheckSum;
int I_RH2,D_RH2,I_Temp2,D_Temp2,CheckSum2;
int I_RH3,D_RH3,I_Temp3,D_Temp3,CheckSum3;
int comp12,comp23,comp13;
void timer_delay20ms() /* Timer0 delay function */
{
TMOD = 0x01;
TH0 = 0xB8; /* Load higher 8-bit in TH0 */
TL0 = 0x0C; /* Load lower 8-bit in TL0 */
TR0 = 1; /* Start timer0 */
while(TF0 == 0); /* Wait until timer0 flag set */
TR0 = 0; /* Stop timer0 */
TF0 = 0; /* Clear timer0 flag */
}
void timer_delay30us() /* Timer0 delay function */
{
TMOD = 0x01; /* Timer0 mode1 (16-bit timer mode) */
TH0 = 0xFF; /* Load higher 8-bit in TH0 */
TL0 = 0xF1; /* Load lower 8-bit in TL0 */
TR0 = 1; /* Start timer0 */
while(TF0 == 0); /* Wait until timer0 flag set */
TR0 = 0; /* Stop timer0 */
TF0 = 0; /* Clear timer0 flag */
}
void Request() /* Microcontroller send start pulse or request */
{
DHT11 = 0; /* set to low pin */
timer_delay20ms(); /* wait for 20ms */
DHT11 = 1; /* set to high pin */
}
void Response() /* Receive response from DHT11 */
{
while(DHT11==1);
while(DHT11==0);
while(DHT11==1);
}
int Receive_data() /* Receive data */
{
int q,c=0;
for (q=0; q<8; q++)
{
while(DHT11==0); /* check received bit 0 or 1 */
timer_delay30us();
if(DHT11 == 1)/* If high pulse is greater than 30ms */
c = (c<<1)|(0x01); /* Then its logic HIGH */

else/* otherwise its logic LOW */


c = (c<<1);

while(DHT11==1);
}
return c;
}
void Request2() /* Microcontroller send start pulse or request */
{
DHT12 = 0; /* set to low pin */
timer_delay20ms(); /* wait for 20ms */
DHT12 = 1; /* set to high pin */
}
void Response2() /* Receive response from DHT11 */
{
while(DHT12==1);
while(DHT12==0);
while(DHT12==1);
}
int Receive_data2() /* Receive data */
{
int q,c=0;
for (q=0; q<8; q++)
{
while(DHT12==0); /* check received bit 0 or 1 */
timer_delay30us();
if(DHT12 == 1) /* If high pulse is greater than 30ms */
c = (c<<1)|(0x01); /* Then its logic HIGH */

else/* otherwise its logic LOW */


c = (c<<1);

while(DHT12==1);
}
return c;
}
void Request3() /* Microcontroller send start pulse or request */
{
DHT13 = 0; /* set to low pin */
timer_delay20ms(); /* wait for 20ms */
DHT13 = 1; /* set to high pin */
}
void Response3() /* Receive response from DHT11 */
{
while(DHT13==1);
while(DHT13==0);
while(DHT13==1);
}
int Receive_data3() /* Receive data */
{
int q,c=0;
for (q=0; q<8; q++)
{
while(DHT13==0); /* check received bit 0 or 1 */
timer_delay30us();
if(DHT13 == 1) /* If high pulse is greater than 30ms */
c = (c<<1)|(0x01); /* Then its logic HIGH */
else /* otherwise its logic LOW */
c = (c<<1);

while(DHT13==1);
}
return c;
}
void main(void)
{
unsigned char dat[20];
led1=0;
led2=0;
led3=0;
while (1){
Request(); /* send start pulse */
Response(); /* receive response */

I_RH=Receive_data(); /* store first eight bit in I_RH */


D_RH=Receive_data(); /* store next eight bit in D_RH */
I_Temp=Receive_data(); /* store next eight bit in I_Temp */
D_Temp=Receive_data(); /* store next eight bit in D_Temp */
CheckSum=Receive_data();/* store next eight bit in CheckSum */
Request2(); /* send start pulse */
Response2(); /* receive response */

I_RH2=Receive_data2(); /* store first eight bit in I_RH */


D_RH2=Receive_data2(); /* store next eight bit in D_RH */
I_Temp2=Receive_data2(); /* store next eight bit in I_Temp */
D_Temp2=Receive_data2(); /* store next eight bit in D_Temp */
CheckSum2=Receive_data2();/* store next eight bit in CheckSum */
Request3();/* send start pulse */
Response3(); /* receive response */

I_RH3=Receive_data3(); /* store first eight bit in I_RH */


D_RH3=Receive_data3();/* store next eight bit in D_RH */
I_Temp3=Receive_data3(); /* store next eight bit in I_Temp */
D_Temp3=Receive_data3(); /* store next eight bit in D_Temp */
CheckSum3=Receive_data3();/* store next eight bit in CheckSum */
comp12 = abs(I_Temp - I_Temp2);
comp23 = abs(I_Temp2 - I_Temp3);
comp13 = abs(I_Temp - I_Temp3);
if(comp12>7 || comp23>7 || comp13>7){
buzz1=0;
}
if(comp12<=7 && comp23<=7 && comp13<=7){
buzz1=1;
}

if(I_Temp > I_Temp2){


if(I_Temp > I_Temp3){
max = I_Temp;
}
else{
max = I_Temp3;
}
}
else{
//max = I_Temp2;
if(I_Temp2 > I_Temp3){
max = I_Temp2;
}
else{
max = I_Temp3;
}
}
if(max==I_Temp && comp12>7){
led1=1;
led2=0;
led3=0;
}
if(max==I_Temp2 && comp23>7){
led2=1;
led1=0;
led3=0;
}
if(max==I_Temp3 && comp13>7){
led3=1;
led1=0;
led2=0;
}
if((I_Temp==I_Temp2 && I_Temp2==I_Temp3) || (comp12<=7 && comp23<=7 &&
comp13<=7)){
led1=0;
led2=0;
led3=0;
}

}
}

Schematic Capture :

Conclusion:
Here in this project we have successfully implemented the railway safety system,if there is fire in
compartment then the buzzer will start ringing and led of the respective compartment will start
glowing .

References :

http://embedded-lab.com/blog/measurement-of-temperature-and-relative-humidity-using-dht11-
sensor-and-pic-microcontroller/