Name: Hala Zeeb
Credentials: 000518
This project will focus on the process and steps of building a simple cat/pets feeder, through the use of SG90 - Servo with a notification function using LoPy4, Pybets and Discord, which will be connected through WiFi. The time of the project will depend on whether you have previous knowledge of programming, IoT, and sensors functionality. However, being a beginner that never worked before with IoT or programing it took me more time due to the additional research and help which took me about 10 hours.
The reason for this project is that I own a cat. As I am sure many who own pets will also agree with me. For a person who lives alone, going out for long hours sometimes is challenging, since no one can feed my pet. Therefore, the idea of creating an automatic food dispenser came to my interest. With my limited knowledge of IoT that was gained throughout the course, I decided to keep it simple and try to learn more about how the connections between the hardware and software work.
This project will first solve a problem for me since my pet will be fed at a specific time, even if I was not available to do so. Secondly, it will build my knowledge and understanding of the way the data transfers to sensors, as well as, how codes work to make the sensor work.
This project will allow me to gain knowledge about IoT. The connection between hardware and software, as it will build an insight into a whole technological world that I have no previous knowledge about.
I decided to stay on the safe side and follow the lecturers' recommendation to work with LoPy4 and an Expansion board, that will be connected to the SG90 - Servo motor through jump wires. A USB is used to connect to the expansion board (see table below for more information):
Material | Items | Cost € and link | Usage |
---|---|---|---|
1. | LoPy4 | €38.45 Pycom | It is a Microcontroller that is used to run Mircopython |
2. | Expansion board | €17.60 Pycom | Used to add functions to the LoPy4 such as the USB and pins on the board |
3. | SG90 - Servo | €6.54 Amazon | €54.18 Amazon: UNO Kit. I bought the whole Kit to allow me to experiment in the future. The Kit included the Servo, Jumper wires and much more. The servo is a mini motor used to provide the motion of open and close to the feeder |
4. | Jumper wires | €7.47 Amazon | Used to connect the servo with the Expansion board |
5. | Rubber bands | Free | Found it at home, used to fasten the Servo to the empty bottle (see picture below) |
6. | USB cable | Free | Used the phone USB charger to connect the expansion board to the laptop, to power the device. |
7. | Empty bottle | Free | Empty bottle is an optional creation, used to place the cat food in the it. |
8. | Optional: Breadboard | €5.52 electrokit | Found in the UNO kit, can be used to make it easier to connet the device with the sensors. |
Total price | €75.58 + shipment | It consted me about €111 + shipment |
Following the teachers intstruction I choose Atom as an IDE, which uses the Micopython programming language.
Note: the following steps might differ depending on the OS choice, I used Windows in my project.
Step 1: Install an IDE
I choose Atom as IDE for the project. Especially that it is easy to work with for beginners, can be downloaded on all OS and it was recommended by the lecturers. Atom was my choice but you can also use VS Code.
Step 2: Install Node.js
It is important to install Node. js to be able to make the Pycom device work since it will be needed to make Pymakr work, thus connecting the Pycom device to the IDE. Through the following steps: open Atom > File > settings > Install > in search bar type: Pymakr and install it.
Step 3: Update the LoPy4 firmware device
This step took me a while to figure out and work out. In this step, the LoPy4 should be inserted into the expansion board (on top of it). Then connect the USB cable to the expansion board and the computer/laptop. Now it is time to update the Firmware, follow Updating device Firmware I then used simple codes such as flashing with different colours, to make sure that the connection between Atom and Firmware worked (codes provided in the update firmware device link). It is important to install Node. js to be able to make the Pycom device work since it will be needed to make Pymakr work, thus connecting the Pycom device to the IDE. Through the following steps: open Atom > File > settings > Install > in search bar type: "Pymakr" and install it.
This part is really simple if the steps was followed correctly. First thing first, connect the Jump wires to the Servo motor. Please note that some motors do not need the jump, wires but rather the Ribbon cables. The following picture is how I connected the jumper wires to the servo motor:
Then connect the servo with the Pycom firmware as shown in the following picture:
The black wire to GND, red to 3V3 and the green/blue to P8. 3V3 (voltage) is responsible for powering the servo and the GND is the ground. While P8 will single the connection between the servo motor and the expansion board.
Note: You can use the breadboard, however, it was not used in this project, and the wires were directly connected to the expansion board.
The platform chosen for this section is Pybytes and that is to save and visualize the data transmitted by the Pycom firmware to Pybtes. For this project, I tried two platforms Pybytes and Datacake, nonetheless, I decided to stick with Pybyets since it was the first platform I downloaded and learned how to work with and it is free to use. It runs smoothly and there are many tutorials online that can help you learn to work it. All the data will be saved on the Pybyets cloud. However, it is worth mentioning that all data will be stored for only 30 days, which means that Pybyets has a small storage space, so it is good to keep that in mind. Yet, you can buy an expansion usage if you needed it.
With my limited coding knowledge I choose to follow the codes that were provided to us and used the main.py that was provided for the SG90-Servo.
The structure of the project was as follows:
boot.py
is used by the firmware when it first is turned on. This file will include the codes for the Wifi-network connection. How to connect WiFi-network found here.
keys.py
is only used to store the WiFi ssid and password, that will be used in boot.py.
main.py
is includes the main codes, in other words, it gives order to the servor and alert to Pybyets. The main code, as mentioned before, was taken from GitHub
Here are the codes that I have included in the boot.py. They are responsible to scan the WiFi network that will be looking for the SSID and password that was provided to it in the key.py
, when it finds the information it will connect.
Under the keys.py
make sure that you add your network SSID and password, with the correct letters and numbers, since it is easy to sometimes make a mistake filling them in.
As you can see it is simple coding, but the "main" function for the project. It is the on and off measurement, which will open and close to dispense the food. In this case, it is the duty cycle is how long the bottle will take to open and sleep is how long the bottle lid will stay closed. Mine is set at 3600 seconds, which means that food will be dispensed every one hour. As you can see the last part of the code is responsible for how long the bottle lidwill take to close and that is set to one second open and then it closes for 3600 seconds.
After finishing the previous step and making sure that the codes work, it is time to upload the code to LoPy4 by simply clicking the "Upload bottom" as shown below:
For this project, I was highly interested in learning more about how Lora works and use The things internet (TTN). Sadly, that did not go as planned, since I found no gateways in both TTN and Helium in the area where I live which made it impossible to connect to Lora. Thus, my best choice was to use a WiIFi connection. It is good to know that WiFi is a wireless protocol, through the connection of the internet it will be then possible to send data to the Pybytes clouds. For this project the connection to Pybyets was simple since it needed only one line in the main.py
to work:
pybytes.send_signal(1,1)
TThis line will send a signal to Pybytes with two statements. One indicates which signal will be sent to the event (explain). Second, what signal/order will be given to Pybyets. I further went on and used webhooks through Pybytes and connected it to Discord and that is to get notified each time my cat gets fed (setting webhook, will be described in the next section).
Visualization
It's time to setup Pybytes to present and visualize the project data. After setting up Pybytes, you can then customize how you want your data to be presented. I choose to create a bar chart by going to Deceives > Dashboard > create bar graph > edit > save.
Setting up Webook to Discord
The following is what the notification that you will receive on Discord will look like:
Here is the final design, as you can see I used a simple method of creating a pet feeder from an empty plastic bootle, you can use cardboard and many other materials to make it stronger.
For the bottle lid I also cut a part of the plastic bottle and replaced on the servo motor, as the following:
I gained a lot of knowledge from this project, I did try some mini projects before doing this project to get myself used to how the devices and sensors work. The project can be expanded on by adding a motion sensor which can detect the pet's motion and thus dispense food. Or maybe a connection that will allow you to feed the pet from your phone. However, I am satisfied with the result, especially since it is my first one.
Here are some of the results on Pybytes, however, you should note that the time was reduced for the sake of presentation for the project results.
Finally, a photo that will show you how the bottle lid is opened and the food is dispensed: