I made a program that uses the Adafruit pressure sensor, and the DHT22 temperature and humidity sensor to log pressure, temperature and humidity every 30 minutes. I left it outside my house overnight yesterday in the hopes that it would have logged all the data overnight but it had logged only once. I'm guessing it drained the whole 9V battery in 30 minutes due to some inefficiency in my program? The program works when the sampling rate is at 2 seconds or something small like that. Please tell me how to make the program more efficient so it can do the logging every 30 minutes successfully.

    #include "DHT.h"
    #define DHTPIN 3
    #define DHTTYPE 22


#include <SD.h>
#include <SPI.h>

#include "Wire.h"
#include "Adafruit_BMP085.h"

Adafruit_BMP085 mySensor;
File myData;

int cs = 4;//chipSelect for SD reader/Writer
double tempC;//holds temperature reading (Celcius)
double pressure;//holds pressure reading (Pascals)
double humidity;
double DHTtemp;
double finalTemp;

void setup() {
  // put your setup code here, to run once:
  SD.begin(cs); //initialize cardReader/Writer
  mySensor.begin();//initialize pressure sensor
  pinMode(10,OUTPUT);//the SD library requires pin 10 to be reserved as OUTPUT and not to be used.

  myData.println("Logging start at  8:30PM, logging 30-minute intervals");


void loop() {
//   put your main code here, to run repeatedly:

  tempC=mySensor.readTemperature();//read Temperature
  pressure=mySensor.readPressure();//read Pressure
  DHTtemp=dht.readTemperature();//read temp from DHT Sensor

  delay(1800000);//30 min delay;


  • \$\begingroup\$ Maybe it was too cold for the battery to function? \$\endgroup\$ Oct 2, 2016 at 13:56
  • \$\begingroup\$ if read functions are provided by the vendor, then you probably don't have control over performance, or the sensors itself drew too much energy. \$\endgroup\$ Oct 2, 2016 at 14:23
  • 1
    \$\begingroup\$ How exactly do you supply the power? The arduino takes 3.3 or 5V as far as I remember, not 9V. What current is actually drawn from the battery? If this thing eats a battery in an hour, there might be something wrong in the circuit, too. Also, there are other sites on the network that might be more helpful for the overall problem, namely Electrical Engineering and Arduino. \$\endgroup\$ Oct 2, 2016 at 15:39
  • 1
    \$\begingroup\$ See this answer for example \$\endgroup\$ Oct 3, 2016 at 13:01

1 Answer 1


Rather than use the Arduino delay feature, use a watchdog timer to turn the Arduino on/off to take readings. The TI TPL5010 should serve well. http://www.digikey.com/product-detail/en/texas-instruments/TPL5010DDCT/296-38829-2-ND/5130142


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.