Smart Cat Flap MCT Howest
by thibaut.detandt in Circuits > Raspberry Pi
1632 Views, 8 Favorites, 0 Comments
Smart Cat Flap MCT Howest
In a nutshell
As a student Multimedia & Communication technology in Howest Kortrijk, I had to make my own IoT project. This would combine all of the modules followed in the first year into one big project. I had the issue of always having to open my door when my cats needed to go outside. And sometimes I wasn't around when they wanted to go outside. This is why I decided to make a smart cat flap, so I'd never have to worry about my cats going outside or getting back inside
Smart Cat Flap is a Raspberry Pi powered dashboard designed for cat owners that gives the owner the ability to see the outside conditions right on your screen. You can see how light it is outside, the temperature and the air humidity. There is also the option to check if your cat is outside or inside and to manually change the cat flap positon from for example completely closed to half open or completely open!
I will be referring to this Github quite a bit in this instructable so make sure to check it out!
My Github: Github
Bill of Materials
Main computing units:
- Raspberry Pi 4
This is the main controller of the whole thing:
- Arduino Uno
This a secondary controller connected with serial communication to the Pi Electronics:
- 12V and 5V powersupply
power supply for the motor and other components
- 2 Breadboards with jumper wires
- A set of resistors
- Different colors of 0.2mm wire
Sensors and modules:
- DHT11 temperature and humidity sensor
- Light dependent resistor(LDR)
- RFID rc522 - 16x2 LCD
- MCP3008 - 8-channel 10-Bit ADC with SPI Interface
- Stepper motor with ULN2003 board
- Level shifter
- 2 buttons
- GPIO T-Part
Tools used in the project:
- soldering iron and solder
- glue
- saws
- ...
The Housing
Wooden housing machined and glued together to become this housing
I first started sketching how I wanted the case to look, something important was that it had to be big enough for everything to fit in since we got a big circuit to put in the case but had to stay compact so that it didn't take alot of space
I made the case out of wood, I think it is the easiest to work with when you don't have that much experience with building cases and you also have a lot of things you can do with it.
I started with making the case out of leftover carton I had laying around to avoid redoing the wooden case multiple times. Try doing the same so you still have room for error!
Once I had my basic case, I just had to drill holes in it (a lot on the front of the case, as you can see on the pictures and put some nails in it, it's a really basic case, but it looks pretty cool and fits perfect. I also decided to paint it white to make it look good.
Once the case was done, it was time to put it all together, as you can see on the last picture! It is kinda a mess inside the box, but everything works and I did not have that much more space.
Everything fits nice and tight and that makes the whole project look way better!
Fritzing
Before we can start on anything else, we NEED to get a "prototype plan" ready. In this case, we make a fritzing schema. Just so we know exactly how everything will be connected and we can use this as a guideline later on.
A few tips for fritzing:
- make the breadboard and schematic separate as the fritzing program makes it very hard to switch in between without a mess
- if you don't have a component in your fritzing folder, there are many on the internet!
- makes sure your ground and voltage are always connected correctly, avoid shortages!
Normalised Database
To log and store sensor data I have designed my own database which contains 3 tables.
The EER diagram is shown in the image above.
1.SensorData
This table stores the main sensor data such as temperature, humidity, and light
2.ActuatorData
This table stores the motor status so we can always know in what position the stepper motor is.
3.RfidData
This table stores the main Rfid data which are when the cats used the cat flap and if they went outside or inside.
To get this database on your Raspberry Pi, forward engineer this EERD in MySQLWorkbench.
Writing the Code
Installing Python packages
Before we try to run anything, we need to install some packages for python first. Head into the terminal of your RPi and type the following commands:
- pip3 install mysql-connector-python
- pip3 install flask-socketio
- pip3 install flask-cors
- pip3 install gevent
- pip3 install gevent-websocket
Raspi-config
We will have to enable different interfaces and to do that we first have to typ following code:
sudo raspi-config
The things we need to enable are in the interfacing section. We need to enable following interfaces:
- Serial
- SPI
- i2c
That was everything we needed to do with raspi-config
Writing the backend
I used Visual Studio Code for my whole backend, you just need to make sure your Visual Studio project is connected to your Raspberry Pi, this means your LAN cable has to be connected to your RPi and to make an SSH connection.
(info on how to create a remote connection can be found here: https://code.visualstudio.com/docs/remote/ssh)
I used my own classes and these are also all included in my GitHub. In my backend file, I used different classes, so everything can be used separately and so that my main code isn't a mess with all the different threads. I used threading to run all the different classes at once. And at the bottom, you got all the routes so we can easily get data in our frontend.
check out my github for the full code
Writing the frontend
Now that the backend is done, we can start writing the full front-end.
Do your best to make it mobile first and then add media queries for the desktop version. You can design your dashboard in any way you want to, i'll just leave my code and design here, you can do whatever you like! In javascript be ready to work with a few GET's from your backend routes, tons of event listeners and some socketio structures to get the data from the sensors displayed on the website.
check out my github for the full code