eSleeper
Follow eSleeper on twitter?
eSleeper is a 21st century cat basket, an ideal resting location for any cat.
When the feline decides its nap-time, eSleeper’s automated lighting control turns on a relaxing wave of color inside an eMac, while greeting the cat with the iconic Macintosh start-up chime (keeping the legacy of the eMac). When the cat walks out, eSleeper turns off the lights and tweets to @eSleeper1, displaying various phrases along with how long the cat has occupied eSleeper.
How did eSleeper start life?
My cat loves sleeping, preferably in one location. His old basket suffered from overuse and had to be discarded. Instead of buying him a replacement, I decided to bring cat baskets into the digital age and build eSleeper. He now loves eSleeper (and is sleeping even better).
How does it work?
An Ethernet Arduino is used to control eSleeper. Data is sent to the Arduino from an infra-red beam attached to the inside of the eMac. When the beam breaks, the Arduino turns on the RGB LED, talks a sound shield to play the Macintosh startup chime and records how the cats been inside. When the beam is broken again, the Arduino turns off the LED and tweets a random phrase with the time spent inside.
eSleeper, because cats like automation too.
Arduino Code for eSleeper
// Add the Twitter library (http://www.arduino.cc/playground/Code/TwitterLibrary)
#if defined(ARDUINO) && ARDUINO > 18 // Arduino 0019 or later
#include <SPI.h>
#endif
#include <Ethernet.h>
#include <Twitter.h>
#include <MP3Trigger.h> //for the MP3 trigger (http://www.sparkfun.com/products/9715)
// Ethernet Shield Settings
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later).
byte ip[] = { };
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("INSERT TOKEN HERE");
MP3Trigger trigger; //again, for the MP3 trigger
int catInRoom = 0;
int lastCount = 0;
unsigned long currTime;
unsigned long prevTime;
int ledPin = 6; // Pin 6 on Arduino for LED
int sensorValue = 0; //Analog pin 0
const int threshold = 350; //threshold for the IR beam
void setup()
{
delay(1000);
Ethernet.begin(mac);
trigger.setup(); //begin MP3 Trigger communication
pinMode(sensorValue, INPUT);
pinMode(ledPin, OUTPUT);
}
//twitter section
void twitterPost(char *textToPost)
{
if (twitter.post(textToPost))
{
int status = twitter.wait();
}
}
void inside()
{
trigger.trigger(1); //Trigger the Mac SFX
digitalWrite(ledPin, HIGH); //turn on the RGB LED
delay(10000); //10 second delay so that the cat has enough time to enter
}
void outside()
{
digitalWrite(ledPin, LOW); //Turn off the RGB LED
unsigned long usedFor = currTime - prevTime;
long hours=0;
long mins=0;
long secs=0;
secs = usedFor/1000;
mins=secs/60;
secs=secs-(mins*60);
mins=mins-(hours*60);
if(mins >= 10) //It only posts Tweets if the cat sleeps for over 10 minutes
{
int randNumber = random(12); //Arduino has very little RAM. I found that you can only store around
//12 tweets before it fails. The work-around would be to change the sketch after all tweets have been tweeted.
switch(randNumber)
{
char buffer[150];
case 0:
sprintf(buffer, "Slept for %d minutes", mins);
twitterPost(buffer);
break;
case 1:
sprintf(buffer, "Another status", mins);
twitterPost(buffer);
break;
case 2:
sprintf(buffer, "Another status", mins);
twitterPost(buffer);
break;
case 3:
sprintf(buffer, "Another status", mins);
twitterPost(buffer);
break;
case 4:
sprintf(buffer, "Another status", mins);
twitterPost(buffer);
break;
case 5:
sprintf(buffer, "Another status", mins);
twitterPost(buffer);
break;
case 6:
sprintf(buffer, "Another status", mins);
twitterPost(buffer);
break;
case 7:
sprintf(buffer, "Another status", mins);
twitterPost(buffer);
break;
case 8:
sprintf(buffer, "Another status", mins);
twitterPost(buffer);
break;
case 9:
sprintf(buffer, "Another status", mins);
twitterPost(buffer);
break;
case 10:
sprintf(buffer, "Another status", mins);
twitterPost(buffer);
break;
case 11:
sprintf(buffer, "Another status", mins);
twitterPost(buffer);
break;
}
}
delay(10000); //wait another 10 seconds for the cat to exit
}
void loop()
{
int sensorValue = analogRead(A0); //read the IR
if(sensorValue > threshold) //If the IR beam is greater than the threshold, do the following
{
prevTime = currTime;
currTime = millis();
catInRoom++;
}
if(catInRoom > 1)
catInRoom = 0;
if (catInRoom > lastCount)
{
inside();
}
else if (catInRoom < lastCount)
{
outside();
}
lastCount = catInRoom;
}



