Can't get DHT-11 sensor to work with ATMega16. Kindly help.

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm trying to get humidity and temperature with a DHT-11 sensor interfaced with an ATMega16 at PIN no. 39 (Port A1).

 

Now, there aren't much (if any) libraries available in the internet, which I can use for ATMega and DHT-11. All the available ones seem to be only for Arduinos. I'm totally stuck here.

 

I got one set of dht11 c and h files for some Arduino and edited it. I wrote a program, and I've spent hours trying to get it work. But it does not. Could you please help me?

 

This is my C program:

 

#include <avr/io.h>
                             // special function registers
#include <stdio.h>              // sprintf()
#define F_CPU 4000000           // 4MHz Internal Clock
#include <util/delay.h>

#include "dht.h"
#include "lcd.h"                 //Fleury

#define DHTTYPE DHT11   // DHT 11


int main(void)

{
	{

	lcd_init(LCD_DISP_ON);
	lcd_puts("DHT11 initializing!");
	
	_delay_ms(2000);

}



while (1) {
	
	lcd_clrscr();
	
	float h = dht_gethumidity;
	float t = dht_gettemperature;

lcd_gotoxy(0,0);

lcd_puts("Humidity: ", h);
lcd_gotoxy(0,1);

lcd_puts("Temp.: ", t);

_delay_ms(1500);

}
}

 

 

This is my DHT.h file:

 


#ifndef DHT_H_
#define DHT_H_

#include <stdio.h>
#include <avr/io.h>

//setup port
#define DHT_DDR DDRA
#define DHT_PORT PORTA
#define DHT_PIN PINA
#define DHT_INPUTPIN PA1

//sensor type
#define DHT_DHT11 1
#define DHT_DHT22 2
#define DHT_TYPE DHT_DHT22

//enable decimal precision (float)
#if DHT_TYPE == DHT_DHT11
#define DHT_FLOAT 0
#elif DHT_TYPE == DHT_DHT22
#define DHT_FLOAT 1
#endif

//timeout retries
#define DHT_TIMEOUT 200

//functions
#if DHT_FLOAT == 1
extern int8_t dht_gettemperature(float *temperature);
extern int8_t dht_gethumidity(float *humidity);
extern int8_t dht_gettemperaturehumidity(float *temperature, float *humidity);
#elif DHT_FLOAT == 0
extern int8_t dht_gettemperature(int8_t *temperature);
extern int8_t dht_gethumidity(int8_t *humidity);
extern int8_t dht_gettemperaturehumidity(int8_t *temperature, int8_t *humidity);
#endif

#endif

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So, the first hit on a Google search for "dht11 atmel avr" http://davidegironi.blogspot.it/... is no use to you?

 

What about http://tinusaur.org/tag/dht11/

Ever wanted to do a project with that cheap DHT11 temperature/humidity sensor and did not want to go the Arduino way but with a simple ATtiny85? You probably know already about  the issues with the existing Arduino based libraries running on the ATtiny microcontrollers, but can’t deal with them. TinuDHT is our answer to this.

TinuDHT is a C library for working with the DHT11 temperature/humidity sensor intended to be used with the Tinusaur but should also work with any other board based on ATtiny85 or similar microcontroller. ...

 

 

And none of the several dozen searches of these forums for "dht11" or "dht22" lead to useful code?

https://www.avrfreaks.net/comment...

 

And

https://github.com/goldsborough/...

http://www.pocketmagic.net/atmeg...

http://www.electronics-lab.com/b...

...

 

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
	float h = dht_gethumidity;
	float t = dht_gettemperature;

Didn't you get warnings on those lines?  You are putting the address of the function into a float variable.

And those functions take a parameter, and have a return value that is not a float.

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I got errors. Thank you so much for pointing me the links. I searched for "DHT-11 ATMega." I'm going through the info you sent me.

Last Edited: Thu. Jun 18, 2015 - 09:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello bagho

 

I am trying to write a program like yours! and I use this library

http://tinusaur.org/tag/dht11/

 

but I have always error as return.

first error that mean sensor didn't respond! have you the same problem?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can you post the error message?

 

I wrote the Tinusaur DHT11 library and haven't used it for a long time. Maybe it needs a fix.