Esp8266 with dht22 running on 2 AA batteries

Tags: #<Tag:0x00007fa4997ed8b8>

Its not something i can capture easily.
As Im not monitoring it live on the device.
But i checked later and it was about 5v.
I need to see if I can capture both device and battery pack voltages.
But im pretty sure theres only one ADC i can use for this on these.
I might have to just monitor the battery pack instead.

Im setting one up now to sleep and report then sleep again.
Brains a bit frazzled at the moment so I may have to finish it another time.

Running on 4AA, Sleeping for 10 minutes, read sensors, upload and sleep again.
https://thingspeak.com/channels/51381

Ive added an extra capacitpr on the 3.3v side and the resistor to pull reset high for better stability.
I need to remove the wasteful led from the switching regulator at some point as well.

Excuse the symbols in eagle. Bit out of practice and some arnt available.

And I blame the hacked together code on my tired old frazzled brain.
Will be cleaned up, sanitised and hardened sometime later.

#include <DHT.h>
#include <ESP8266WiFi.h>
extern "C" {
  #include "user_interface.h"
  uint16 readvdd33(void);
}
 
// replace with your channel's thingspeak API key, 
String apiKey = "xxxxxxxxxxxxxxxx";
const char* ssid = "xxxxxxxxxxxx";
const char* password = "xxxxxxxxxxxxxxxxx";
 
const char* server = "api.thingspeak.com";
#define DHTPIN 2 // what pin we're connected to

const unsigned long SLEEP_INFTERVAL = 10 * 60 * 1000 * 1000; // 10 minutes
//const unsigned long SLEEP_INFTERVAL = 30 * 1000 * 1000; // 30 seconds
 
DHT dht(DHTPIN, DHT22,15);
WiFiClient client;
   
 
void setup() {                
  Serial.begin(57600);
  delay(10);
  dht.begin();
  
  WiFi.begin(ssid, password);
 
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
   
  WiFi.begin(ssid, password);
   
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  // ################################ get and send reading

   
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float vdd = readvdd33() / 1000.0;
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

   Serial.println(); 
   Serial.print("Temperature: ");
   Serial.print(t);
   Serial.print("c  - Humidity: "); 
   Serial.print(h);
   Serial.print("%  - Voltage: "); 
   Serial.print(vdd);
   Serial.println("v "); 

   Serial.println(); 
   Serial.println("Send to Thingspeak");    
   Serial.println();

  while (!client.connect(server, 80)) {
    Serial.println("connection failed, retrying...");
  }

  String postStr = apiKey;
         postStr +="&field1=";
         postStr += String(t);
         postStr +="&field2=";
         postStr += String(h);
         postStr +="&field3=";
         postStr += String(vdd);
         
         postStr += "\r\n\r\n";

   client.print("POST /update HTTP/1.1\n"); 
   client.print("Host: api.thingspeak.com\n"); 
   client.print("Connection: close\n"); 
   client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n"); 
   client.print("Content-Type: application/x-www-form-urlencoded\n"); 
   client.print("Content-Length: "); 
   client.print(postStr.length()); 
   client.print("\n\n"); 
   client.print(postStr);
         
 

   // wait for response
    while(!!!client.available()) {
      delay(10);
    }
  
    // Read all the lines of the reply from server and print them to Serial
    Serial.println("Response: "); 
    while(client.available()){
      String line = client.readStringUntil('\r');
      Serial.print(line);
    }

    Serial.println();
    Serial.println("closing connection");
  
  client.stop();

  Serial.print("up time: ");
  Serial.print(millis());

  Serial.print(", deep sleep for ");
  Serial.print(SLEEP_INFTERVAL / 1000000);
  Serial.println(" secs...");
  system_deep_sleep_set_option(1);
  system_deep_sleep(SLEEP_INFTERVAL - micros()); // deep sleep for 15 minutes minus how long this reading was up for
  
}
 
 
void loop() {


}

Another thing to consider is powering off the DHT22 if you aren’t already doing so.

Well spotted, hadnt considered that.
Ill need to check the data sheet as it may allready have some power saving stuff built in or available that im not aware off.
If not I wonder if i can power it by connecting it to a gpio and setting it high?
Maybe not enough power and ill need to add some extra circuitry.
simple enough to use a gpio as an enable pin.

Found this nice snippet last night for a low power ADC battery monitor.
While i was trying to research smt components.
Would work well for monitoring the battery pack. Just adjust the voltage devider for the 1v range ADC on the ESP8266.
It uses a gpio to enable the voltage devider so it doesnt drain power all the time.
http://www.microbuilder.eu/Tutorials/Fundamentals/MeasuringBatteryVoltage.aspx
Similar to what would be needed to cut power to the dht22.

This could turn into quite a useful little board.
With a little tweaking it could be a general use small IOT.

The dht22 datasheet says it stays in low power mode till it gets something on the data line.

40-50 uA on standby.
1-1.5 mA when in use.

So probably dont need to do any more to save power on that front.
What would the over head be for the extra circuitry to cut it further.

The deep sleeping version running at the moment seems more reliable so far.

Found some 3.3v boost converters or step up regulators.
It seems you can get 5v boosters easily but 3.3v arnt very popular.
By pololu which seem to be a good brand. There stepper sticks are highly regarded in 3d printing.

http://www.hobbytronics.co.uk/u1v10f3-3v3-regulator
Ive ordered a couple to try.

Nice.

The step down converter is no use.
It drains the battery too much 4.8mA in sleep mode.
The ESP is supposed to use only about 80uA in sleep mode.

Waiting for the boost regulator to come in the post to check that out.

I got my boards from Oshpark on Saturday.
Ordered on the 19th arrived on 29th 10 days with the free upgrade i got.
Not bad for $13 dollars. Not great packaging though. Just a jiffy bag.
Got round to checking them and soldering components today.

And of course there are 2 mistakes.
One missing trace and one set of crossed traces. Had to correct them.
2 jumper wires and 2 cuts to traces.

Im sure i checked it several times before uploading to Oshpark but must have not saved something before uploading the design. Obviously Oshpark dont do any checking themselves to catch mistakes.

Soldered on the ESP8266-12 to the pads and the rest of the components.

And heres the 3d printed case im working on.
Just a rough print while i work out whats needed to house it nicely.

This one is for use with a 5v supply plugged in.
The orange isnt the final colour just what was on the printer ready to use.
It will be modular in several pieces so i can swap fronts, backs and bodies for different uses.
This one hss a mounting for a dht22 sensor on the font and holes for the power plug and a reset switch. I intend to have others for oled displays, batteries or other sensors.

Next version is going to be designed for surface mount components and incorporate the 5v to 3.3v switching regulator onboard.

If you run ERC and DRC before sending a job it is impossible to make those two mistakes as it will give an error for N/C pins and crossed traces.

Good one Gordon. This is looking like a great little system

I know, thats why i think i made a few last amendments, did the checks, but didnt hit the save button before uploading the .brd file up to oshpark
Need to alter my work flow a little.

Another thing is to check the Gerbers before you upload.

There’s various applications to do this, but I found this website did a really nice job of it http://gerblook.org

@tobyspark OSHPark take the Eagle file so you don’t have to do the Gerbers, although I did…

Oh. I’d still make the Gerbers – I’ve had things hiding in the Eagle files that become all-too-obvious in the Gerbers.

Ill have a look at the gerbers next time.
I just thought it would be easier to upload the .brd file.