I am trying to interface NodeMCu with DHT11 . Intially i tested the dth sensor working with arduino uno code and its working well.
Arduino uno code
#include <dht.h>
dht DHT;
#define DHT11_PIN 7
void setup(){
Serial.begin(115200);
}
void loop()
{
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
delay(1000);
}
Now i wanted to test same code using NodeMcu 12E version v1.0. Here I downloaded SimpleDHT11 library and I wont get response.
I have tested with changing the output pin from 2 to 0 didint worked
given separate 3.3v power supply with common ground it didn't worked.let me know suitable library and how can i use with esp node mcu model
#include <SimpleDHT.h>
// for DHT11,
// VCC: 5V or 3V
// GND: GND
// DATA: 2
int pinDHT11 = 0;
SimpleDHT11 dht11;
void setup() {
Serial.begin(115200);
}
void loop() {
// start working...
Serial.println("=================================");
Serial.println("Sample DHT11...");
// read with raw sample data.
byte temperature = 0;
byte humidity = 0;
byte data[40] = {0};
if (dht11.read(pinDHT11, &temperature, &humidity, data))
{
Serial.print("Read DHT11 failed");
delay(1000);
return;
}
Serial.print("Sample RAW Bits: ");
for (int i = 0; i < 40; i++) {
Serial.print((int)data[i]);
if (i > 0 && ((i + 1) % 4) == 0) {
Serial.print(' ');
}
}
Serial.println("");
Serial.print("Sample OK: ");
Serial.print((int)temperature); Serial.print(" *C, ");
Serial.print((int)humidity); Serial.println(" %");
// DHT11 sampling rate is 1HZ.
delay(1000);
}