Automatic Cat Feeder
Cat Feeder using IoT is one of the new ways of feeding cat technologies.This technologies directly helps the owner to take care of their cat in spite of they are not at home.By this way the owner of the cats can still give their cat food when they got notification from the system.This new way of automatic cat feeder is using Iot application and two types of sensor.The sensor that we are using are ultrasonic sensor and Pir sensor.This application is functionally when the bowl of the cat is empty it will automatically drop down into the bowl.This cat feeder also help the owner to know the amount of the food that has been stored.
Supplies
- Ultrasonic sensor
- Jumper wire
- NodeMcu ESP8266
- PIR sensor
- Servo
- Breadboard
- USB
- A computer (for compiling and uploading Arduino code)
Prepare the Components
For the first part , we prepare all the component that we use in our projects.The component that we use are
- Breadboard
- NodeMcu
- PIR motion sensor
- Ultrasonic Sensor
- Male to female jumper
- Male to male jumper
- USB
Connect All Components
Next is,connect the component to the breadboard.We need to prepare some jumper wires to connect the ESP-8266 module , the servomotors,ultrasonics sensor and PIR motion sensor.
The PIR Sensor has three pins: GND(Ground), OUT(signal) and VCC(Voltage)
■ VCC to the Positive railings of the Bread board.
■ OUT pin to the Digital pin 2 of the Arduino board.
■ GND pin to the Negative railings of the Bread board.
Plug the USB cable to the NodeMCU board and proceed to the next step.
Setup the Telegram-Bot
Install the library of CTBot .In this project CTBot.h library was used for the control of the Telegram.
Firstly,go to the BotFather then choose the newbot for the option for the new user .Then,setup the name for the bot.
Then ,setup the username for the bot,it must end in 'bot'.After the setup it,we will get a token to connect with the devices.
Other than that,we must search for the IDBot to get an id to insert it into the coding.
Install ESP8266 Library
Install the latest Arduino IDE. In this project servo.h library was used for the control of the servos.Then add the compatibility.Next setup the board manager,click at the latest version.Then,proceed by waiting the installation process is complete.Select the board and the port through the device manager.
NodeMCU Code
#include <CTBot.h>
#include <Servo.h>
Servo s2;
#define trigPin 12
#define echoPin 14
int ledPin = D8; // choose the pin for the LED
int inputPin = D2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
int duration, distance;
CTBot myBot;
String ssid = "UniSZA-WiFi";
String pass = "unisza2016";
String token = "5195567336:AAHt3QpviF3Z9V6wiOHSL_N2rhS38AOwZ5U";
const int id = 663658214;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Starting TelegramBot...");
myBot.wifiConnect(ssid,pass);
myBot.setTelegramToken(token);
if (myBot.testConnection()) {
Serial.println("Good Connection");
} else {
Serial.println("Bad Connection");
}
myBot.sendMessage(id, "Hello User NodeMCU, Welcome to Automatic Cat Feeder");
Serial.println("Sent");
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(2, OUTPUT);
Serial.begin(9600);
s2.attach(D4);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;
if (distance >= 15 || distance <= 0) {
Serial.println(distance);
Serial.println("Insufficient Food");
myBot.sendMessage(id, "Insufficient Food");
digitalWrite(2, LOW);
}else{
delay(2000);
Serial.println(distance);
Serial.println("Food is Enough");
digitalWrite(2,HIGH);
}
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
delay(1000);
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
s2.write(0);
delay(1000);
}else{
digitalWrite(ledPin, LOW); // turn LED OFF
delay(1000);
if (pirState == HIGH) {
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
s2.write(90);
delay(5000);
}
delay (2000);
}
}
}
Usage
Firstly in this video the screen will be appear "insufficient food".It was detected by the ultrasonic sensor.If the container is full of food it will remain "food is enough" .If the motion is detected the food will drop down into the food container.