DHT11 is not responding to PIC microcontroller

Status
Not open for further replies.

thunderboympm

Full Member level 5
Joined
Sep 17, 2007
Messages
243
Helped
32
Reputation
64
Reaction score
29
Trophy points
1,308
Location
Malappuram, India
Activity points
2,469
hi,
i am doing a project in PIC18f452, it needs a DHT11 temperature and humidity sensor. my problem is DHT11 is not responding to my detection code
this is my start sequence
Code:
void dht11_start(void)
{
	onewire_cntrl = 0;
	onewire = 0;
	__delay_ms(20);
	onewire = 1;
    __delay_us(30);
	onewire_cntrl = 1;
	return;
}
this is my detection subroutine
Code:
void dht11_responce()
{
    while(onewire & 1);  /* wait till bus is High */     
    while(!(onewire & 1));  /* wait till bus is Low */
    while(onewire & 1);  /* wait till bus is High */
}
onewire_cntrl is TRISAbits.TRISA0
onewire is PORTAbits.RA0
i already given ADCON1bits.PCFG = 7

i am using XC8 as compiler and PICKit3 as debugger.
please help
 
Last edited:

I think we need to see more code. 'dht11_responce' doesn't return any value, it just waits until 'onewire' goes low and high again so you can't use it to check anything.

Are you changing TRISAbits.TRISA0 from an output to an input at the right time and if this is a real circuit, do you have a pull-up resistor on the one-wire data line?

Brian.
 

Please share more code. In void dht11_start(void) it seems you are only changing variables/port levels, I can not see how they should influnce your communication.

Further, I assume you have not forgotten the pull up resistor :wink:.
 
Last edited:


But sir, when I am debugging using pickit3 the code is stucked in
Code:
while(onewire & 1);
this line.

- - - Updated - - -

Please share more code. In void dht11_start(void) it seems you are only changing variables/port levels, I can not see how they should influnce your communication.

Further, I assume you have not forgotten the pull up resistor :wink:.

I am using a dht11 module, in that module already 5.1k is present. I think it is enough, right?
 

That (incredibly old) MCU has LAT registers so you should obey the golden rule "read from the PORT, write to the LAT" to avoid RMW issues.
Is the line you say it is getting stuck on the 1st or the 2nd 'while(onewire & 1)' statement in the 'dht11_responce'[sic] function?
The data sheet I've seen for the DHT11 says that an external 5K pull-up is recommended - do you have an external pull-up or not?
How are you debugging the code - I hope that you are not single-stepping through the code as that will completely destroy any timing the DHT11 is using to send its response. So how are you determining that it is getting 'stuck' on the line of code?
Susan
 


i stucked in the first "while" statement. that means, according to datasheet, presence signal is not getting.
i didn't put any pullup, because the module itself have a 5K pullup, i thought that it is sufficient.
 

(Note - this is also being discussed at https://www.microchip.com/forums/m1136547.aspx#1136547).
Can you please post a link to the data sheet that says it has an internal 5K pull-up built within the DHT11 and therefore no external pull-up is required? All of the data sheets I've looked at just now show an external pull-up - if you don't have that in there then the line will float and there is no guarantee that it will ever get high enough to trigger the pin. Remember that both ends of the line use open-collector (or equivalent) devices so there is nothing to pull the line high.
Susan
 


Checked the LATX also, no change. Is ther any problem with my DHT11_start subroutine
 

The code is OK in principle but one-wire interfaces have very specific timing requirements and you would always have to use your "dht11_responce()" immediately after the "dht11_start()" routine with no delays between them. It would make far more sense to combine the two sections of code together:
Code:
char dht11_detect(void)
{
	onewire_cntrl = 0;
	onewire = 0;
	__delay_ms(20);
	onewire = 1;
	onewire_cntrl = 1;
  __delay_us(40);
	
  return(onewire);
}
Even safer is to use LAT for the 'onewire' and return the PORT value. Note that the code above returns a value to indicate whether the presence pulse was there or not. I have not tried the code myself but hopefully it gives you some ideas.

Brian.
 

hello,


i had also some problems on a similar device DHT22
program stuck when reading value

i added a timetout into the reading loop measure to avoid infinite loop
and also this device must have a big delay (1,7sec) between each measurement ..
Datashett tells about 2000mS delay !!!
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…