Auto Pet Care Cage
Project By:
Robert Choi, Hokyoung Hwang, Jin Ha Hwang, and Nakyoung Kim
Overview:
As an opportunity in the "Internet of Things," this project features a regular pet cage that has an:
- Automated Door Opener
- Automatic Dog Feeder
- Dog Training Sound system
- Notification System
The dog cage door will open when the dog shakes the cage and a specific threshold is met. The dog will leave the cage and take care of his business. After the dog has left, the dog cage door will close and the owner of the dog will be notified that the dog has left via email. When the dog wants to come back into the cage, the door cage will automatically open back up using an IR sensor. The dog goes back into the cage, and the door will automatically close again. Again, another notification will be sent to the owner of the dog that the dog has come back via email. After the dog has closed, the dog is fed a treat and the dog sound system will first play a sound a simple high pitch note that a treat is coming and finally to tell the dog that the dog did a "good job." This is the training method that is defaulted. The owner has the option to change the sound to train the dog as the owner wishes.
Components Used:
- Speaker: Speaker was used to help train the dog and tell the dog that the dog did a "Good Job." More information on connecting the speaker to the Mbed can be found here: http://developer.mbed.org/users/4180_1/notebook/using-a-speaker-for-audio-output/
- RC Servo: Two RC Servos were used for the project. One RC Servo was used to open and close the dog cage door, and the other servo was used to automate the dog feeder for the treats. More information on servo can be found here: http://developer.mbed.org/users/4180_1/notebook/an-introduction-to-servos/
- SD Card: An SD Card reader is used to read a wav file to play a recording and a sound. More information on the SD Card can be found here: http://developer.mbed.org/cookbook/SD-Card-File-System
- 9 Degrees of Freedom IMU (Gryo Meter): An IMU was used to detect the vibration of the cage when the dog wants to come out of the cage. More information on the IMU can be found here: https://www.sparkfun.com/products/12636
- Ethernet Ports: Two ethernet ports were used to communicate and notify the owner with an email when the dog has left the cage and when the dog comes back to the cage. More information can be found here: http://developer.mbed.org/handbook/Ethernet-Interface
- IR Sensor: An IR Sensor was used to notify the cage that the dog has come back to the cage. The cage will open and close after the dog has gotten back in the cage. More information about the IR Sensor can be found here: https://www.sparkfun.com/products/242
Pin Connections:
Mbed | Speaker |
---|---|
3.3v | Speaker + |
p18 | Speaker - |
GND | GND |
Mbed | RC SERVO |
---|---|
p21 | Signal |
p23 | Signal |
Mbed | SD Card |
---|---|
p5 | DI |
p6 | DO |
p7 | SCK |
p8 | CS |
3.3v | VCC |
GND | GND |
Mbed | Ethernet |
---|---|
P1 | TD+ |
P2 | TD- |
P7 | RD+ |
P8 | RD- |
MBED | 9-Degree IMU |
---|---|
3.3V | VDD |
G1ND | GND |
P9 | SDA |
P10 | SCL |
MBED | IR_SENSOR |
---|---|
5V | VD |
GND | GND |
P19 | DATA |
MBED_A | MBED_B |
---|---|
P19(DogOutEmail) | OWNER |
P20(DogInEmail) | OWNER |
Photos:
Overview Cage:
Overview System:
Gyro Meter:
IR Sensor Placement on the Cage:
Automatic Dog Feeder:
Automated Cage Opener and Closer:
Servo Setup:
Email Notification:
Video Demo:
Main Code:
// Hello World to sweep a servo through its full range #include "mbed.h" #include "Servo.h" #include "Speaker.h" #include "LSM9DS0.h" #include "math.h" #include "stdio.h" #include "SDFileSystem.h" #include "wave_player.h" #define LSM9DS0_XM_ADDR 0x1D // Would be 0x1E if SDO_XM is LOW #define LSM9DS0_G_ADDR 0x6B // Would be 0x6A if SDO_G is LOW LSM9DS0 imu(p9, p10, LSM9DS0_G_ADDR, LSM9DS0_XM_ADDR); //Gyro SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card //Speaker mySpeaker(p26); AnalogOut DACout(p18); //Sound wave_player waver(&DACout); //Sound Servo rollerServo(p21); //Servo Servo feederServo(p23); //Servo Serial pc(USBTX, USBRX); //PC Serial AnalogIn IR_sensor(p19); //IR Timer t; //Time DigitalOut dogOutEmail(p24); //Email(digital) DigitalOut dogInEmail(p25); //Email(digital) // Global Variable int check_movementCounter = 0; int checkMovement_flagCounter = 0; int check_IRsensorCounter = 0; int checkIRsensor_flagCounter = 0; bool isDogInside = true; bool didYouFeed = false; ////////////////////////////////////////////OUT /** * Open Door */ void openDoor(){ rollerServo.write(1); // wait(3); // rollerServo.write(0.46); } /** * Close Door */ void closeDoor(){ wait(3); rollerServo.write(0.4); wait(0.3); rollerServo.write(0.46); } /** * Play Sound */ void makeSound() { // mySpeaker.PlayNote(969.0, 0.5, 1.0); // wait(2); FILE *wave_file; wave_file=fopen("/sd/good_dog.wav","r"); if(wave_file == NULL) { error("Could not open file for write\n"); }else{printf("read wavefile\r\n");} waver.play(wave_file); printf("play wavefile\r\n"); fclose(wave_file); printf("close wavefile"); return; } ////////////////////////////////////////////IN /** * Check the Gyro sensor */ void checkMovement() { imu.begin(); imu.readGyro(); t.start(); int count = 1; float avg = 0; while(t.read() < 1) { float _avg = sqrt((imu.gx)*(imu.gx) + (imu.gy)*(imu.gy) + (imu.gz)*(imu.gz)); avg = ((avg* count) + _avg) / (count+1); count++; } if (avg > 3) { checkMovement_flagCounter++; } check_movementCounter++; t.stop(); t.reset(); if (check_movementCounter == 5) { if (checkMovement_flagCounter >= 3) { printf("Dog is moving\r\n"); dogOutEmail = 1; printf("Email Request Has been Sent\r\n"); printf("dogOutEmail Value is :%d\r\n",dogOutEmail.read()); wait(1); dogOutEmail = 0; openDoor(); isDogInside = false; closeDoor(); } else { printf("Not Moving\r\n"); dogOutEmail = 0; } printf("Movement Average is : %f\r\n",avg); checkMovement_flagCounter = 0; check_movementCounter = 0; } } /** * Feeder Servo */ void feed() { wait(3); feederServo = 0.51; wait(1.74); feederServo = 0.5; makeSound(); wait(2); } /** * IR Sensor */ void seeCage() { int IR_sensorVal = IR_sensor.read() * 100; if (IR_sensorVal > 20) { checkIRsensor_flagCounter++; } check_IRsensorCounter++; if (check_IRsensorCounter == 5) { if (checkIRsensor_flagCounter >=3) { printf("Dog is present in front of the cage : %d\r\n",IR_sensorVal); if(didYouFeed == false) { openDoor(); closeDoor(); dogInEmail = 1; wait(1); dogInEmail = 0; wait(2); feed(); didYouFeed = true; isDogInside = true; } } else { printf("Dog is not present : %d\r\n",IR_sensorVal); } checkIRsensor_flagCounter = 0; check_IRsensorCounter = 0; } } int main() { feederServo = 0.5; rollerServo = 0.46; dogOutEmail = 0; dogInEmail = 0; while(true) { dogOutEmail = 0; if(isDogInside) { checkMovement(); wait(0.5); }else { seeCage(); wait(0.5); } } }
Ethernet Code:
//WORKING SET // -- SimpleSMTPClient_HelloWorld.cpp -- // Used EthernetInterface Library // Don't support TSL/SSL. #include "mbed.h" #include "EthernetInterface.h" #include "NTPClient.h" #include "SimpleSMTPClient.h" #include "TextLCD.h" #define DOMAIN "DOMAIN" #define SERVER "aspmx.l.google.com" #define PORT "25" //25 or 587,465(OutBound Port25 Blocking ) #define USER "ece4180final@gmail.com" #define PWD "ece4180final12" #define FROM_ADDRESS "ece4180final@gmail.com" // TO_ADDRESS (Of some address is possible.) // to-user1@domain, to-user2@domain, to-user3@domain .... // The TO_ADDRESS are less than 128 characters. #define TO_ADDRESS "ece4180final@gmail.com" DigitalIn input(p19); DigitalIn input2(p20); DigitalOut led1(LED1); //TextLCD lcd(p24, p26, p27, p28, p29, p30); //Serial Device(p13, p14); int main() { //int hi = input; //printf("Value is %d\n", hi); printf("running programing\n"); wait(1); //char m; int ret; while (1) { while (input.read() == 0 && input2.read() == 0) { led1 = 1; } led1 = 0; if (input.read() == 1) { EthernetInterface eth; char SUBJECT[22] = "ALERT DOG CAGE OPENED"; char strTimeMsg[16]; printf("\n SimpleMTPClient library demonstration\n"); printf("Setting up ...\n"); eth.init(); wait(1); //eth.init("192.168.137.20", "255.255.255.0", "192.168.137.1"); eth.connect(25000); printf("Connected OK\n"); // IP Address printf("IP Address is %s\n", eth.getIPAddress()); //lcd.locate(0,1); //lcd.printf("%s", eth.getIPAddress()); // NTP Client printf("NTP setTime...\n"); NTPClient ntp; ntp.setTime("pool.ntp.org"); time_t ctTime = time(NULL)- 14400;//32400; // Atltanta time printf("\nTime is now (JST): %d %s\n", ctTime, ctime(&ctTime)); strftime(strTimeMsg,16,"%y/%m/%d %H:%M",localtime(&ctTime)); SimpleSMTPClient smtp; char msg[]="ALERT: "; smtp.setFromAddress(FROM_ADDRESS); smtp.setToAddress(TO_ADDRESS); smtp.setMessage(SUBJECT,msg); smtp.addMessage("Dog Dage Opended\r\n"); smtp.addMessage("Time Send:\r\n"); smtp.addMessage(strTimeMsg); ret = smtp.sendmail(SERVER, USER, PWD, DOMAIN,PORT,SMTP_AUTH_NONE); if (ret) { printf("E-mail Transmission Error\r\n"); } else { printf("E-mail Transmission OK\r\n"); } } else if (input2.read() == 1) { EthernetInterface eth; char SUBJECT[22] = "ALERT DOG CAGE ClOSED"; char strTimeMsg[16]; printf("\n SimpleMTPClient library demonstration\n"); printf("Setting up ...\n"); eth.init(); wait(1); //eth.init("192.168.137.20", "255.255.255.0", "192.168.137.1"); eth.connect(25000); printf("Connected OK\n"); // IP Address printf("IP Address is %s\n", eth.getIPAddress()); //lcd.locate(0,1); //lcd.printf("%s", eth.getIPAddress()); // NTP Client printf("NTP setTime...\n"); NTPClient ntp; ntp.setTime("pool.ntp.org"); time_t ctTime = time(NULL)- 14400;//32400; // Atltanta time printf("\nTime is now (JST): %d %s\n", ctTime, ctime(&ctTime)); strftime(strTimeMsg,16,"%y/%m/%d %H:%M",localtime(&ctTime)); SimpleSMTPClient smtp; char msg[]="ALERT: "; smtp.setFromAddress(FROM_ADDRESS); smtp.setToAddress(TO_ADDRESS); smtp.setMessage(SUBJECT,msg); smtp.addMessage("Dog came inside\r\n"); smtp.addMessage("Dog food has been distributed as an award"); smtp.addMessage("Time Send:\r\n"); smtp.addMessage(strTimeMsg); ret = smtp.sendmail(SERVER, USER, PWD, DOMAIN,PORT,SMTP_AUTH_NONE); if (ret) { printf("E-mail Transmission Error\r\n"); } else { printf("E-mail Transmission OK\r\n"); } } } return 0; }
Please log in to post comments.