Power outage and temperature tweeter

Thought this might be useful as a starting point some someone. It tweets temperature changes of more than + or - 2 degrees and every 4 hours it tweets current temperature and also if there is a power outage for more than 10 minutes it tweets. It would need power from a UPS, which will also be needed for your Internet connection, and separate power (NON UPS) for the relay driver.

#include <SPI.h>
#include <Ethernet.h>
#include <Twitter.h>
const int sensorPin = A0;
boolean Power = true;
byte mac[] = { your mac address };
byte ip[] = { your IP address};

// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("your tweet code in here");
char Text[80];
int tempup = 22;
int tempdn = 18;
int num;
int minutecount = 0;
int nopwrcount = 0;

void setup()
{ pinMode(7, INPUT);
delay(3000);
Ethernet.begin(mac, ip);
Serial.begin(9600);}

// Tweet subroutine
void tweetsub()
{ Serial.println(Text);
Serial.println("connecting ...");
delay(3000);
if (twitter.post(Text)) {
int status = twitter.wait();
if (status == 200) { Serial.println("OK."); }
else
{ Serial.print("failed : code ");
Serial.println(status); }
} else
{ Serial.println("connection failed."); }
return; }

void loop()
{
if (digitalRead(7) == LOW)
{ Power = false;
Serial.print(minutecount);
Serial.println("no power");
++nopwrcount; }
else
{ Power = true;
Serial.print(minutecount);
Serial.println("Power"); }

// One minute delay and increment minutecount which is used to produce 4 hour delay
delay(60000);
++minutecount;

// Monitors power outage, relay to 5v line usually closed with capacitor and resistor
// debounce network from Pin 7
// nopwrcount counts number of minutes without power
// sprintf function is used to embed a variable(num) into the tweet text, the variable
// is used to ensure that tweets are unique
if (digitalRead(7) == LOW && Power == false && nopwrcount > 9)
{ Serial.println(nopwrcount);
Serial.println("10 mins no power");
++num;
nopwrcount = 0;
Serial.print(nopwrcount);
sprintf(Text, "No Mains Power for 10 minutes Ref %1d", num);
tweetsub(); }

// This section uses simple temperature sensor TMP36 using Pin A0
int sensorval = analogRead(sensorPin);
float voltage = (sensorval/1024.0) * 5.0;
int temp = ((voltage - 0.5) * 100) - 4;
Serial.println(temp);

// Tweets every 4 hours the staus of Power and the temperature
if (minutecount > 239)
{ Serial.println("4 hours"); Serial.println(minutecount);
++num;
minutecount = 0;
sprintf(Text, "Mains Power OK 4Hrs Ref %1d Temperature %2d", num, temp);
tweetsub(); }

// This section tweets changes in temperature of more than 2 degrees up or down unused at present
// if (temp > tempup)
// { tempup = temp + 2;
// tempdn = temp - 2;
// ++num;
// sprintf(Text, "Temperature %1d Centrigrade Ref %2d", temp, num);
// tweetsub(); }
//
//if (temp < tempdn)
// { tempup = temp + 2;
// tempdn = temp - 2;
// ++num;
// sprintf(Text, "Temperature %1d Centrigrade Ref %2d", temp, num);
// tweetsub(); }

}

Andy

Hi Andy,

This looks very interesting to me. I want to do something like this, but I want it to just send an email.

However, what hardware do I run this on at the lowest cost?

I'm trying to monitor a wifi AP and router, so I really can't justify spending $100 just to monitor $75 dollars of gear.