Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interfacing DHT11 Humidity and Temperature Sensor woth PIC16F84A MikroC

Status
Not open for further replies.

Okba_

Junior Member level 2
Junior Member level 2
Joined
Apr 13, 2015
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
183
This is an interfacing of the Microchip PIC16F84A 8-bit microcontroller with digital humidity and temperature sensor DHT11.
This sensor uses One-Wire protocol to contact with the master device. The results will be displayed on 1602 LCD display as shown by the circuit schematic diagram below.
The following video shows the working of the circuit using hardware.
The code is written using MikroC PRO for PIC compiler.

https://www.youtube.com/watch?v=TbyTPmGFCEM



- - - Updated - - -

MikroC Code:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//Interface of DHT11 with PIC16F84A MikroC code
//Please read the datasheet of DHT11 sensor to understand the code
//Written by: BENCHEROUDA Okba
//electronnote@gmail.com
//Use at your own risk
 
// LCD module connections
 sbit LCD_RS at RB5_bit;
 sbit LCD_EN at RB4_bit;
 sbit LCD_D4 at RB3_bit;
 sbit LCD_D5 at RB2_bit;
 sbit LCD_D6 at RB1_bit;
 sbit LCD_D7 at RB0_bit;
 sbit LCD_RS_Direction at TRISB5_bit;
 sbit LCD_EN_Direction at TRISB4_bit;
 sbit LCD_D4_Direction at TRISB3_bit;
 sbit LCD_D5_Direction at TRISB2_bit;
 sbit LCD_D6_Direction at TRISB1_bit;
 sbit LCD_D7_Direction at TRISB0_bit;
 // End LCD module connections
 unsigned char *text,mytext[4];
 unsigned short  a, b, i, t, rh;
 
 void StartSignal(){
 TRISB.F6 = 0;    //Configure RB6 as output
 PORTB.F6 = 0;    //RB6 sends 0 to the sensor
 delay_ms(18);
 PORTB.F6 = 1;    //RB6 sends 1 to the sensor
 delay_us(30);
 TRISB.F6 = 1;    //Configure RB6 as input
  }
 void CheckResponse(){
 a = 0;
 delay_us(40);
 if (PORTB.F6 == 0){
 delay_us(80);
 if (PORTB.F6 == 1)   a = 1;   delay_us(40);}
 }
 void ReadData(){
 for(b=0; b<8; b++){
 while(!PORTB.F6);                   //Wait until PORTB.F6 goes HIGH
 delay_us(30);
 if(PORTB.F6 == 0)  i&=~(1<<(7-b));   //Clear bit (7-b)
 else{i|= (1 <<( 7 - b));             //Set bit (7-b)
 while(PORTB.F6);}                    //Wait until PORTB.F6 goes LOW
 }
 }
 void error(){
 text="ERROR";
  Lcd_Out(1,6,text);
  }
 void main() {
 TRISB = 0;        //Configure PORTB as output
 PORTB = 0;        //Initial value of PORTB
 Lcd_Init();
 while(1){
 Lcd_Cmd(_LCD_CURSOR_OFF);        // cursor off
 Lcd_Cmd(_LCD_CLEAR);             // clear LCD
  StartSignal();
  CheckResponse();
  if(a == 1){
  ReadData();
  rh = i;
  ReadData();
  ReadData();
  t = i;
  ReadData();
  ReadData();
  if(i = rh + t){
  text = "Temp:  .0C";
  Lcd_Out(1, 4, text);
  text = "Humi:  .0%";
  Lcd_Out(2, 4, text);
  ByteToStr(t,mytext);
  Lcd_Out(1, 9, Ltrim(mytext));
  ByteToStr(rh,mytext);
  Lcd_Out(2, 9, Ltrim(mytext));}
  else error();
  }
  else error(); 
  delay_ms(2000);
  }
  }

 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top