Pages: [1]   Go Down
Author Topic: Computerized cat toilet  (Read 1909 times)
0 Members and 1 Guest are viewing this topic.
Baltic states
Offline Offline
Jr. Member
**
Karma: 0
Posts: 97
new day, new try
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is it... Somebody says it is the 8th wonder of the world, but let's stay realistic.. it is just computerized cat toilet, that`s 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 what`s 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

















Code:
#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);
 }
}
   
   
 
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 142
Posts: 5282
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can we subscribe to this twitter channel?

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 64
Posts: 2100
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can we subscribe to this twitter channel?

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


Baltic states
Offline Offline
Jr. Member
**
Karma: 0
Posts: 97
new day, new try
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can we subscribe to this twitter channel?
You should! smiley

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 smiley-wink
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13471
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what gas sensor do you use ?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Baltic states
Offline Offline
Jr. Member
**
Karma: 0
Posts: 97
new day, new try
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

CO, USA
Offline Offline
God Member
*****
Karma: 5
Posts: 711
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

... it is poor civic hygiene to install technologies that could someday
facilitate a police state. -- Bruce Schneier

Pages: [1]   Go Up
Jump to: