I am trying to run a DHT11 sensor from my Wemos D1 R1. I have the ground connected to ground and the sensor connected to D2 pin with a resister between sensor and power line. I have tried to connect the power to the D3 pin and setting the pinMode(D3,OUTPUT);and digitalWrite(D3,HIGH);, but the sensor isn't recognized. If I connect the power to the 3.3v output pin on the Wemos it works fine. I am plugging the Wemos into my computer's USB. Can someone tell my why the Wemos isn't being powered up by the D3 pin. Do I need to connect 9v to the Wemos instead of the computer power? Not a big deal but would be nice to understand why and to hook it up to another power pin. This is my code that activates the pins and turns on the power to the D3 pin.
#include <DHTesp.h>
DHTesp dht;
pinMode(D3,OUTPUT);//make pin D3 a power outlet for 3.3v
void setup() {
Serial.begin(115200);
dht.setup(D2, DHTesp::DHT11);
digitalWrite(D3,HIGH);//make pin D3 hot
}
void loop() {
delay(8000);
float t = dht.getTemperature();
float f = (t*1.8) + 32;
if (isnan(t))
{
Serial.println("Failed to read from DHT2 sensor!"); **//when the sensor is powered by pin D3 this shows up but when powered by 3.3v it does get the sensor amount**
return;
}
Serial.print(", \"maintemp\": ");
Serial.print(f);
Serial.print("}\n");
delay(2000);
}