2
\$\begingroup\$

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

    DHT dht (DHTPIN,DHTTYPE);

#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:
  dht.begin();
  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=SD.open("PTDATA.txt",FILE_WRITE);
  myData.println("Logging start at  8:30PM, logging 30-minute intervals");
  myData.println("Time,Temperature,Pressure,Humidity");
  myData.close();


}

void loop() {
//   put your main code here, to run repeatedly:
  myData=SD.open("RLDATA.txt",FILE_WRITE);

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

  myData.print(tempC);
  myData.print(",");
  myData.print(pressure);
  myData.print(",");
  myData.println(humidity);
  myData.close();
  delay(1800000);//30 min delay;


  }

 }
\$\endgroup\$
  • \$\begingroup\$ Maybe it was too cold for the battery to function? \$\endgroup\$ – 200_success Oct 2 '16 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\$ – Incomputable Oct 2 '16 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\$ – I'll add comments tomorrow Oct 2 '16 at 15:39
  • 1
    \$\begingroup\$ See this answer for example \$\endgroup\$ – I'll add comments tomorrow Oct 3 '16 at 13:01
1
\$\begingroup\$

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

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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