Using DHT11 with MegaPI


#1

I have a MegaPi and also wish to interface to a DHT11 sensor to get both temperature and humidity. For hardware I have the 3-pin sensor mounted on a board with a pullup resistor (http://www.uugear.com/portfolio/dht11-humidity-temperature-sensor-module/).

I started by using the MeHumitureSensorTest1.ino example in the Arduino IDE, which refers to “MeHumiture humiture(PORT_6);”. This code seems to

I’ve connected the GND, VCC and DAT from the DHT11 to the 3 pins on A6 (GND, VCC and SIG when I read them top to bottom). My code for MeHumitureSensorTest1 Sketch was modified to include megapi, temp and humidity header files:

include MeMegaPi.h
include MeHumitureSensor.h
MeHumiture humiture(PORT_6);

void setup()
{
Serial.begin(9600);
}

void loop()
{
humiture.update();
Serial.print(“Humidity (%) =”);
Serial.print( humiture.getHumidity() );
Serial.print(", Temperature (oC) =");
Serial.println( humiture.getTemperature() );
Serial.println("###########################");
delay(1000);
}

The code successfully compiles and I can see the following sent repeatedly over the Serial Monitor screen but the values are all zero:

Humidity (%) =0, Temperature (oC) =0

I suspect either I’ve:

  • got DHT11 wired improperly into A6
  • used incorrect syntax for addressing A6 port
  • using incorrect function call syntax for the MegaPi hardware

Any suggestions would be greatly appreciated - thanks!

P.S. Note I added this same topic as a reply to another DHT11 question. Don’t mean to clutter up the forum but thought it should get it’s own topic. Please let me know if I should remove this new topic.


#2

Try this code, just need to change the “MeOrion.h” to "MeMegaPi.h"
http://learn.makeblock.com/cn/Makeblock-library-for-Arduino/_me_humiture_sensor_test2_8ino-example.html


#3

Thanks for the code you sent Michael. I compiled and downloaded it but I seem to be getting the same response:

///////////////////////////////////////
Humidity (%) =0
Temperature (oC) =0
Fahrenheit (oF) =32.00
Kelvin (K) =273.15
dewPoint (oC) =nan
///////////////////////////////////////

I even left the circuit wired to A6 but changed the code to read from A7 and the results don’t change, so now I suspect that I have maybe a wiring issue. Any idea if wiring GND, VCC and DATA from DHT11 to GND, 5V and SIG on MegaPi port A6 is the proper way to wire this? Any registers that I have to configure to make it read serial data from A6 perhaps?

So I tried wiring an analog sensor (LM35) into that same A6 port, using the following code and it worked correctly:
///////////////////////////////////////////////////////////////////////
#include “MeMegaPi.h”
#include “MeOnBoardTemp.h”

int val;
int tempPin = 6;

void setup()
{
Serial.begin(9600);
}
void loop()
{
val = analogRead(tempPin);
float mv = (val/1024.0)5000;
float cel = mv/10;
float farh = (cel
9)/5 + 32;

// Temperature in F
Serial.print(“TEMPRATURE = “);
Serial.print(farh);
Serial.print(”*F”);
Serial.println();
}
///////////////////////////////////////////////////////////////////////

Seems like there’s something about trying to read this serial DHT11 that is problematic.


#4

Seems to me that you have a defective DHT11 sensor. request for replacement i think.


#5

Good point… I think we’ve tried everything and the sensor is the only suspect left. Thanks for all your help.


#6