Go Down

Topic: Sketch runs fine with USB comp power, crash w/ 9v (Read 988 times) previous topic - next topic


Apr 21, 2010, 03:38 am Last Edit: Apr 21, 2010, 03:44 am by .jacob Reason: 1

I'm using the wishield and SHT15 temp/humidity sensor to tweet the temp and humidity conditions every 90 minutes.  I've been able to successfully run this sketch via USB power from my computer for days at a time but when I use a 9v battery it crashes after approx. 25 minutes and the L LED (pin 13) pulsates, almost like a beating heart.  The 9v battery is new.

I'll be using the arduino in a sealed environment so it must be totally wireless, hence the use of a battery.  If a 9v is not the proper battery to use, what is recommended?  Ideally I'd get 30 days of run-time without having to change batteries.


P.S.  If it's useful, my code is below:

Code: [Select]

* A simple sketch that uses WiServer to send a tweet with the current system time every 90 minutes

#include <WiServer.h>
#include <SHT1x.h>


#define dataPin  7
#define clockPin 6
SHT1x sht1x(dataPin,clockPin); //data and clock pins for SHT1x

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,2};   // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1};   // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};   // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"XXXXXXXX"};      // max 32 bytes

unsigned char security_type = 2;   // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"XXXXXXX"};   // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,   // Key 0
             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // Key 1
             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // Key 2
             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00   // Key 3

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------

// Auth string for the Twitter account
long intervalHum = 30000; //set the interval for temp and humidity to be checked
long intervalTweet = 5400000; // Set the interval for tweets - 1.5 Hrs
float humidity; // Init humidty variable
float temp_f; // Init temp variable
int tweet = 0; /*Used to tweet once on initial startup. Otherwise
                would have to wait until <intervalTweet> expires */
long previousMillis = 0;
long previousMillisTweet = 0;
long tweetTime = 0; // Time (in millis) when the next tweet should be sent

// This function generates a message with the current system time
void currentTemp() {
  WiServer.printTime(millis()); // Append time Arduino has been running - gets around duplicate tweet filtering
  WiServer.print("] ");
  WiServer.print("Humidor temp and humidity is: ");
  WiServer.print("° F and ");

// A request that sends a Tweet using the currentTime function
TWEETrequest sentMyTweet(auth, currentTemp);

void setup()
   // Initialize WiServer (we'll pass NULL for the page serving function since we don't need to serve web pages)
 // Enable Serial output and ask WiServer to generate log messages (optional)

void loop()
 if (tweet == 0) // Tweets once at inital startup.  Next tweet won't happen for <intervalTweet>
   ++tweet; // Increment initial tweet count
// Set the temp and humidity to be checked every 30 seconds (defined by <intervalHum> global variable
// If you don't set this to a reasonable number the arduino seems to get so busy running the
// temp check functions it doesn't have time to run the WiShield TCP/IP stack - ergo all IP comms break
 if (millis() - previousMillis > intervalHum)
   previousMillis = millis();                        
   temp_f = sht1x.readTemperatureF();
   humidity = sht1x.readHumidity();
// Set a tweet to occur every two hours (defined by <intervalTweet> global variable)
 if (millis() - previousMillisTweet > intervalTweet)
    previousMillisTweet = millis();




First of all, where are you connecting the 9V to?

I doubt that the standard 9V battery has enough juice to power the Arduino for a day.

If you could try using a 9V battery pack (i.e. 6 AA's) to test and see if the system crashes.


Sounds like your battery is getting weak and then the arduino begins having problems.  I concur with the 9V battery pack idea.  Need more power storage than a single 9V will provide.

Also, make sure you are connecting the positive battery terminal to the pin marked VIN or through the power jack.


I believe a fresh 9v Alkaline battery will run just the arduino without external connections for around 13 - 15 hours.  The wishield uses 10 times as much as an arduino on transmit and 3 times on recieve.  Realistically for 30 days, I'd be looking at a small motor cycle battery.  


Since you are checking the conditions every 90 minutes, another option would be to put Arduino in sleep mode most of the time to preserve battery time. But again, depending on how much power the peripherals draw, you might still have to resort to either a larger battery pack or some sort of external power.

Go Up