Computerized cat toilet

Here is it... Somebody says it is the 8th wonder of the world, but let's stay realistic.. it is just computerized cat toilet, thats sends messages to twitter when the cat has done his bad job(we call it MEGATRON). So after you got a message rush to the toilet and clean it, no more bad smell in the room! If you are miles away and you get the message, immediately call your parents, friends and tell whats happened, they should clear the problem. I have installed on my pc metro twit software, it makes bing sound when a new tweet is posted.

Hardware:
Arduino UNO
Ethernet shield
MQ-4 Gas Sensor
9DC adapter

#define SENSITIVITY 5 // 1 max, 20 min
#define SENSTIME 5000 // 5sec is a good time
const int SensorPin = A3; //Sensor pin.. with my ethernet shield pins A0-A2 are always HIGH(don`t know why), so I took A3.
char msg1[] = "Cat toilet is online!";  // Message after start
char msg2[] = "WARNING WARNING MEGATRON!"; //Warning message
char*msg;

#include <SPI.h>
#include <Ethernet.h>
#include <Twitter.h>            // http://playground.arduino.cc/Code/TwitterLibrary
#include <SignalFilter.h>       // http://jeroendoggen.github.com/Arduino-signal-filtering-library/
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,192,1,4 };                                            //IP
Twitter twitter("1133881105-X3pMth1pGFFs4m133881105-X3pMth1pGFFs4mj5yt6FIZ");  //get a token at http://arduino-tweet.appspot.com/
SignalFilter Filter;
int sensorValue; 
int value_1;
int value_2;
int value_read = false;
unsigned long read_value_time;
unsigned long lastsend;
unsigned long debugtime;


void setup()
{
Filter.begin();
Filter.setFilter('b');
Filter.setOrder(1);
Serial.begin(57600); 
Serial.println("WARM UP");  
delay(60000);    // warm up time for sensor 
msg = msg1;
sendtotwitter(); // send message to twitter
}

void loop()
{
readValue();
//debug();  //if you want to see sensor value
}


void readValue()
{
sensorValue = Filter.run(analogRead(SensorPin));
if(millis() - read_value_time > SENSTIME)   
{
read_value_time = millis();
if(value_read == false)
{
value_1 = sensorValue;
value_read = true;
}
else
{
value_2 = sensorValue;
value_read = false;
}
}
if(value_1 > value_2)
{
  if(value_1 - value_2 >= SENSITIVITY)
  alarm();
}
else if(value_1 < value_2)
{
  if(value_2 - value_1 >= SENSITIVITY)
  alarm();
}
}


void alarm()  // here you can add alarm activities, in my case it is only sending message to twitter
{
if(millis() > lastsend)  // Please avoid sending more than 1 request per minute not to overload the server! My time is 200sec.
{
msg = msg2; // which one message we will send to twitter
sendtotwitter();   // Send
}
}

void sendtotwitter()
{
  Ethernet.begin(mac, ip);
  Serial.println("connecting ...");
  if (twitter.post(msg)) {
    int status = twitter.wait();
    if (status == 200) {
      Serial.println("OK.");
    } else {
      Serial.print("failed : code ");
      Serial.println(status);
    }
  } else {
    Serial.println("connection failed.");
  }  
  lastsend = millis() + 200000;
}

void debug()
{
 if(millis() - debugtime > 1000)
 {
   debugtime = millis();
   Serial.print("value_1 "); Serial.print(value_1);Serial.print("  value_2 "); Serial.print(value_2);Serial.print("  sensorValue "); Serial.println(sensorValue);
 }
}

Can we subscribe to this twitter channel?

fungus:
Can we subscribe to this twitter channel?

If that twitter key is authentic, then you can probably do whatever you like to the channel.

fungus:
Can we subscribe to this twitter channel?

You should! :slight_smile:

pYro_65:

fungus:
Can we subscribe to this twitter channel?

If that twitter key is authentic, then you can probably do whatever you like to the channel.

No it is not :wink:

what gas sensor do you use ?

robtillaart:
what gas sensor do you use ?

MQ-4 Gas Sensor
http://www.ebay.com/itm/Methane-Gas-Sensor-MQ4-MQ-4-Module-Free-3pin-cables-/190791699716?pt=LH_DefaultDomain_0&hash=item2c6c124d04

fungus:
Can we subscribe to this twitter channel?

Well, using the screen name from the screen shot, the RSS feed for it would be:
http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=romaslina