Hello,
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.
Thanks,
Jacob
P.S. If it's useful, my code is below:
/*
* 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 WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
#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
char* auth = "TWITTERUSERNAME:PASSWORD"; // Base64 encoded USERNAME:PASSWORD
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.print("[");
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(temp_f);
WiServer.print("° F and ");
WiServer.print(humidity);
WiServer.print("%");
}
// 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)
WiServer.init(NULL);
// Enable Serial output and ask WiServer to generate log messages (optional)
Serial.begin(9600);
WiServer.enableVerboseMode(true);
}
void loop()
{
if (tweet == 0) // Tweets once at inital startup. Next tweet won't happen for <intervalTweet>
{
++tweet; // Increment initial tweet count
Serial.println("Tweeting...");
sentMyTweet.submit();
}
// 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();
Serial.println("Tweeting");
sentMyTweet.submit();
}
WiServer.server_task();
}