Battery Powered ESP8266 Temperature/Humidity Monitor with DHT11


#42

@pearl3 here are some projects that were made with NodeMCU, feel free to peruse and ask them questions


#43

I’m already in contact with Rich (Garage Door Opener) on Facebook. He told me about cayenne.

But we two also had no luck to get HTU21d running.


#44

I don’t have a nodeMCU to test with but one thing I can see is that you have the temp function commented out but still waiting for it to run in your if statements. Also, make sure you have a widget on your dashboard for V0 and V1 otherwise it will never execute those functions. Try the code below:

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
// #define DHTTYPE DHT11
// #define DHTPIN  14

#include "CayenneDefines.h"
#include "BlynkSimpleEsp8266.h"
#include "CayenneWiFiClient.h"
// #include <DHT.h>
#include <SparkFunHTU21D.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "";
// Your network name and password.
char ssid[] = "";
char password[] = "";
//Variables for DHT11 values
//float h, t, hif;
float h, t;
bool Humidity = false;
bool Temperature = false;
//bool HeatIndex = false;

//DHT dht(DHTPIN, DHTTYPE);
HTU21D myHumidity;

void setup()
{
  Serial.begin(9600);
  Serial.print("Setup");
  Cayenne.begin(token, ssid, password);

  Humidity = false;
  Temperature = false;
  //HeatIndex = false;
}

void loop()
{
  //Run Cayenne Functions
  Cayenne.run();
  //Check if we got all values we wanted and sleep for 10 minutes if we did
  // if (Humidity && Temperature && HeatIndex){
    if (Humidity && Temperature){
    Serial.println("Got all values - sleeping");
    delay(100);
    ESP.deepSleep(60000000, WAKE_RF_DEFAULT);
    delay(100);
  }
}

CAYENNE_OUT(V0){
  Serial.println("Entered Humidity");

  //Check if read failed and try until success
  do {
    //Read humidity (percent)
    // h = dht.readHumidity();
    h = myHumidity.readHumidity();

    delay(1000);
  } while  (isnan(h));

  Serial.print("Humidity: ");
  Serial.println(h);

  //Set Humidity to true so we know when to sleep
  Humidity = true;

  //Write to Cayenne Dashboard
  Cayenne.virtualWrite(V0, h);
}

CAYENNE_OUT(V1){
  Serial.println("Entered Temperature");
  
  //Check if read failed and try until success
  do {
    //Read temperature as Fahrenheit
    // t = dht.readTemperature(true);
    t = myHumidity.readTemperature();

    delay(1000);
  } while  (isnan(t));

  Serial.print("Temperature: ");
  Serial.println(t);

  //Set Temperature to true so we know when to sleep
  Temperature = true;

  //Write to Cayenne Dashboard
  Cayenne.virtualWrite(V1, t);
}

/*CAYENNE_OUT(V2){
  Serial.println("Entered Heat Index");

  //Check if read failed and try until success
  do {
    //Read humidity (percent)
    h = dht.readHumidity();
    //Read temperature as Fahrenheit
    t = dht.readTemperature(true);
    //Calculate Heat Index as Fahrenheit
    hif = dht.computeHeatIndex(t, h);
  } while  (isnan(t) || isnan(h));

  Serial.print("Heat Index: ");
  Serial.println(hif);

  //Set HeatIndex to true so we know when to sleep
  HeatIndex = true;

  //Write to Cayenne Dashboard
  Cayenne.virtualWrite(V2, hif);
} */

#45

Another question for you, were you able to read the HTU21d and print to serial with a very basic sketch without Cayenne?


#46

Indeed i made the /* at the wrong line. But unfortunately this was not the solution :frowning:


#47

Yes, i used his sensor before for an standalone temp/hum projet with lcd display.


#48

Try this for your loop:

void loop()
{
  //Run Cayenne Functions
  Cayenne.run();
  delay(100);
  //Check if we got all values we wanted and sleep for 10 minutes if we did
  // if (Humidity && Temperature && HeatIndex){
    if (Humidity && Temperature){
    Serial.println("Got all values - sleeping");
    delay(100);
    ESP.deepSleep(60000000, WAKE_RF_DEFAULT);
    delay(100);
  }
}

#49

Also, monitor your voltage. This can easily happen with the ESPs if you are running on a battery that can’t provide the transmit current of 80+ mA.

Craig


#50

Thanks but no better results:

bBʦ5bäöÎʦýÿSetup[261] Connecting to networxSAVE2
[2264] Connected to WiFi
[2264] My IP: 192.168.200.37
[5065] Connecting to arduino.mydevices.com:8442
[5438] Ready (ping: 100ms).
Entered Temperature

Exception (28):
epc1=0x40203f45 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: cont 
sp: 3ffef7f0 end: 3ffefb00 offset: 01a0

>>>stack>>>
3ffef990:  3ffe8504 3ffefa44 3ffeea10 40203f41  
3ffef9a0:  00007276 3ffeea10 3ffee7cc 4020404b  
3ffef9b0:  3fff0bb4 3ffeea10 00000001 40202a16  
3ffef9c0:  3ffefa30 3ffefa44 00000001 40202cf0  
3ffef9d0:  3ffefa40 3fff0bb4 3fff0a84 40203d52  
3ffef9e0:  3ffefa01 3ffee808 00000031 40203d8e  
3ffef9f0:  3ffee700 3ffee808 3ffeeae0 3ffefa43  
3ffefa00:  3ffee7d4 00000004 40204bc8 3ffeeae0  
3ffefa10:  00000005 3ffefa40 3ffee7d4 3ffefa40  
3ffefa20:  00000004 00000001 3ffee7d4 40202f66  
3ffefa30:  00000000 3ffee7f4 3ffee7d4 40202dc8  
3ffefa40:  31007276 3f003000 3ffeeacc 00000030  
3ffefa50:  04000314 00002000 3ffeeae0 3ffee7f4  
3ffefa60:  00000004 3ffefa40 40204bc8 3ffeeae0  
3ffefa70:  3ffe84a0 000020fa 3ffee7d4 00000001  
3ffefa80:  00000000 3ffee7f4 3ffee7d4 40203155  
3ffefa90:  4010599c 0032add5 3ffee8b4 00000000  
3ffefaa0:  3ffee1f0 3ffee8b4 3ffeeae0 3ffee8b4  
3ffefab0:  3ffee7f4 3ffeeacc 40204bc8 3ffeeae0  
3ffefac0:  4020151e 00000064 00000064 3ffeeacc  
3ffefad0:  3fffdad0 00000000 3ffeeac4 40203193  
3ffefae0:  3fffdad0 00000000 3ffeeac4 40204c14  
3ffefaf0:  feefeffe feefeffe 3ffeeae0 40100718  
<<<stack<<<

#51

As you can see, sensor is working with SparkFun HTU21s sample sketch in the same setup:

0‚~?–4“Ò¶£ÿOCAEüûHTU21D Example!
Time:326 Temperature:22.5C Humidity:44.3%
Time:1398 Temperature:22.5C Humidity:44.3%
Time:2471 Temperature:22.5C Humidity:44.3%
Time:3543 Temperature:22.5C Humidity:44.3%
Time:4616 Temperature:22.5C Humidity:44.3%
Time:5688 Temperature:22.5C Humidity:44.3%

#52

I’d like to know how much current the ESP devices draw, too.
My Fluke ammeter only has 3.5 digit resolution,
and only down to 1/100th an amp, so it only shows 00.01 A.
Not accurate enough.
I need a milliammeter.
I don’t have one.

I’d surely like to know.
I’m imagining the ESP12-e draws
something like 35 mA (milliamps),
-just a WAG.


#53

Do you Google Bro? :slight_smile:

Spec sheet says 80 mA, I’ve measured 86 or so for my modules.

On the raw modules, you need to put at least a 220uF capacitor across the 3V3 to keep it from resetting when connecting to the cloud server. Perhaps if I use multi-core wire for connection, this wouldn’t be as necessary… but a capacitor works.

Craig


#54

I’ve been becoming fond of using the 78SR3.3 voltage regulators.
It works well for me,
while using a 47 muff cap on either side of the regulator.

That 220 muff cap takes up a lot of real estate,
but changing the 47 muff cap
to a 1 muff cap wouldn’t gain me much space,
and 47 muffs is (much) more than adequate.

The 78SR3.3 is a VERY efficient switcher,
and also allows for a VCC of up to +36,
and eliminating the need of a large +V filter capacitor-
it’s a switching regulator, as such (by definition) filters out AC line ripple
and other spurious electrical noise.

It would be interesting to see
how long 2 standard 9V batteries (in series) would last
in this configuration.
The minimum V(in) voltage on the 78SR3.3 is 7.5V.

@kreggly - I’ve vaguely heard of Google.
I can’t quite pin where I’ve heard that term before…
:stuck_out_tongue_winking_eye:
http://www.kloppenborg.net/images/blog/esp8266/esp8266-esp12e-specs.pdf


#55

I like this project I am going to implement similar project for green house control system :slight_smile:


#56

Any other hints for my problem? I’m pretty sure this is not a voltage problem as i had othr projects with blynk i.e. before…


#57

Install this, https://github.com/me-no-dev/EspExceptionDecoder, and see what it says.

Also, post your whole sketch and one of us can try it and see if we can repeat your error.

Craig


#58

Or is there anybody with nodeMCU an HTU who can copy my setup?


#59

Maybe, if you post your full sketch :wink:

Craig


#60

You will find it up there 38/58 :wink:

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
// #define DHTTYPE DHT11
// #define DHTPIN  14

#include "CayenneDefines.h"
#include "BlynkSimpleEsp8266.h"
#include "CayenneWiFiClient.h"
// #include <DHT.h>
#include <SparkFunHTU21D.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "";
// Your network name and password.
char ssid[] = "";
char password[] = "";
//Variables for DHT11 values
//float h, t, hif;
float h, t;
bool Humidity = false;
bool Temperature = false;
//bool HeatIndex = false;

//DHT dht(DHTPIN, DHTTYPE);
HTU21D myHumidity;

void setup()
{
  Serial.begin(9600);
  Serial.print("Setup");
  Cayenne.begin(token, ssid, password);

  Humidity = false;
  Temperature = false;
  //HeatIndex = false;
}

void loop()
{
  //Run Cayenne Functions
  Cayenne.run();
  delay(100);
  //Check if we got all values we wanted and sleep for 10 minutes if we did
  // if (Humidity && Temperature && HeatIndex){
    if (Humidity && Temperature){
    Serial.println("Got all values - sleeping");
    delay(100);
    ESP.deepSleep(60000000, WAKE_RF_DEFAULT);
    delay(100);
  }
}

CAYENNE_OUT(V0){
  Serial.println("Entered Humidity");

  //Check if read failed and try until success
  do {
    //Read humidity (percent)
    // h = dht.readHumidity();
    h = myHumidity.readHumidity();

    delay(1000);
  } while  (isnan(h));

  Serial.print("Humidity: ");
  Serial.println(h);

  //Set Humidity to true so we know when to sleep
  Humidity = true;

  //Write to Cayenne Dashboard
  Cayenne.virtualWrite(V0, h);
}

CAYENNE_OUT(V1){
  Serial.println("Entered Temperature");
  
  //Check if read failed and try until success
  do {
    //Read temperature as Fahrenheit
    // t = dht.readTemperature(true);
    t = myHumidity.readTemperature();

    delay(1000);
  } while  (isnan(t));

  Serial.print("Temperature: ");
  Serial.println(t);

  //Set Temperature to true so we know when to sleep
  Temperature = true;

  //Write to Cayenne Dashboard
  Cayenne.virtualWrite(V1, t);
}

/*CAYENNE_OUT(V2){
  Serial.println("Entered Heat Index");

  //Check if read failed and try until success
  do {
    //Read humidity (percent)
    h = dht.readHumidity();
    //Read temperature as Fahrenheit
    t = dht.readTemperature(true);
    //Calculate Heat Index as Fahrenheit
    hif = dht.computeHeatIndex(t, h);
  } while  (isnan(t) || isnan(h));

  Serial.print("Heat Index: ");
  Serial.println(hif);

  //Set HeatIndex to true so we know when to sleep
  HeatIndex = true;

  //Write to Cayenne Dashboard
  Cayenne.virtualWrite(V2, hif);
} */

#61

Take a seat @kreggly!

Anyway…let’s try doing some serial prints to see where you’re getting caught up. Try this and post the output.

void setup()
{
  Serial.begin(9600);
  Serial.print("Setup");
  Cayenne.begin(token, ssid, password);
  Serial.print("Cayenne setup");

  Humidity = false;
  Temperature = false;
  //HeatIndex = false;
}

void loop()
{
  //Run Cayenne Functions
  Serial.print("Begin loop");
  Cayenne.run();
  Serial.print("End Cayenne.run");
  delay(100);
  //Check if we got all values we wanted and sleep for 10 minutes if we did
  // if (Humidity && Temperature && HeatIndex){
    if (Humidity && Temperature){
    Serial.println("Got all values - sleeping");
    delay(100);
    ESP.deepSleep(60000000, WAKE_RF_DEFAULT);
    delay(100);
  }
  Serial.print("End loop");
}