Aqua Alert Howest MCT

by taliaXvdb in Circuits > Raspberry Pi

159 Views, 1 Favorites, 0 Comments

Aqua Alert Howest MCT

Screenshot 2023-06-03 094233.png

As a student Multimedia & Creative technology in Howest Kortrijk, I had to make my own IoT project. This would combine all the modules followed in the first year into one big project. I care about my health and like to have a healthy lifestyle. I know from myself that I don't drink enough water each day, so I made a device that gives you reminders to drink water. You can choose which reminder you want (light, sounds or vibration) and how often you want them. You can set a personal goal you want to achieve, and the device looks if you achieved this at the end of the day, by weighing your bottle. It also keeps a streak for how many consecutive days you have achieved the goal.

Supplies

sen-10-012-1.jpg
download.jpg
HX711 Scale 1-1500x1500w.jpg
download.jpg
download.jpg
open-smart-vibration-dc-motor-module-3.7-5.3v-1500x1500.jpg
download.jpg
ST1167_01.jpg
download.jpg
download.jpg
download.jpg
PCF8574-DIP.png
download.jpg

Hardware

  • DS18B20: temperature sensor
  • RC522: RFidreader with tag
  • HX711: weight module
  • loadcell (5kg)
  • ledring (24leds)
  • passive buzzer
  • vibrationmotor
  • LCD1602
  • levelshifter
  • raspberry pi 4 + power supply
  • SD-card 16GB minimum
  • button
  • 5V power supply + cable
  • PCF8574
  • potentiometer
  • resistors : 1 x 470ohm, 1 x 4.7k ohm, 1 x 110 ohm
  • wires
  • breadboard
  • wood

In the following file, you can find a bill of materials of a few components, with the price and where to buy


Software

Fritzing Scheme

Screenshot 2023-06-03 103138.png
Screenshot 2023-06-03 103204.png

Before we can start on anything else, we NEED to get an idea of what we will make. In this case, we make a fritzing scheme because they are easy to use, and they give you a good overview of your project. It's good to have these, because if you change your wires, it can happen some things don't work anymore, and then you can look back to this to see if you wired something wrong. In my breadboard scheme, you see 2 batteries, but I actually used a power supply as in the pictures above, but they didn't have it in fritzing scheme.

Assemble the Circuit

349706079_609070894532975_5193095092772777274_n.jpg
349158857_282682364202640_5350629642479966319_n.jpg

Now it's time to assemble the circuit. Use the fritzing scheme to do this!

At first, I used the typical jump wires, but later on I used other wires, that are occupying less space.

Write Image to Raspberry Pi

Screenshot 2023-06-03 112310.png
Screenshot 2023-06-03 112449.png
Screenshot 2023-06-03 112913.png
Screenshot 2023-06-03 113252.png

Keep your Raspberry Pi unplugged during this whole step, until noted otherwise.

  1. Download the image from this link (it's a big file)
  2. Unpack the zip-file (prepare enough space, the image is around 8 GB)
  3. Open win32diskimager
  4. Plug in your SD-card
  5. Click the file icon en select the image file you just unzipped.
  6. Choose the device, the name should look like D:, this can be another letter, but it mostly looks like this
  7. When you have selected the right things, you can push the write button. Writing the image can take a few minutes, keep your computer on during the whole process.
  8. When the writing is done, you click the USB icon on your taskbar, and click on eject (name of SD-card). Then you get a notification, and after that notification you can safely unplug your SD-card.
  9. When all of this is done, you can plug it in your Raspberry Pi. After that, you can connect your Raspberry Pi to your computer with an Ethernet cable, and you can also plug in the Raspberry Pi power supply.

Connect Pi to Wifi

Screenshot 2023-06-03 121308.png

Make sure your Raspberry Pi is properly plugged in and connected to your computer before you start this step

  1. Open VNC viewer
  2. Enter the address of your Pi (192.168.168.169)
  3. The username and password are already made in the image, the username is student, and the password is W8w00rd. You can change this later on.
  4. When you're logged in, in the top right corner, you can see 2 arrows facing different directions. In the picture you can already see a Wi-Fi logo, that's where the arrows should be. Now click on the 2 arrows, and select your network to log in to your Wi-Fi. After that, your Pi is connected to your Wi-Fi.
  5. Now you can simply close the VNC viewer tab.

Set Up Remote Connection in Mysql

Screenshot 2023-06-03 113921.png
Screenshot 2023-06-03 114204.png

After you've done step 4, you can start with this.

Make sure your Raspberry Pi is properly plugged in and connected to your computer before you start this step

  1. Open MySQL Workbench
  2. Click on the plus icon to add a new connection
  3. Give your connection a useful name
  4. Select the method: Standard TCP/IP over SSH
  5. Type in the right hostname, with this image it's the same one as in the picture
  6. Give your SSH username a name like raspberryPi
  7. The next thing you need to do is add a username and password.
  8. After that, you can click ok, and then your new connection is made.
  9. Now you can open this connection, but keep in mind, this connection only works when your Raspberry Pi is plugged in and connected to your computer

Normalized Database

EER-diagram.png

After Step 5, you can start doing this step.

Make sure your Raspberry Pi is properly plugged in and connected to your computer before you start this step

To log and store the data, I have made my own database, which contains 6 tables.

In the image above, you can see the EER-diagram.


Table Devices:

This table stores the different sensors and actuators I used. The devices each get a unique ID (handy for foreign keys), they also have a type to know if it's a sensor or an actuator. The other tables are less important, but are handy for when you need to look up a device.

Table History:

In this table, the records are kept of the sensors and actuators, such as the temperature, the weight, the state of an actuator, ... The table also keeps when a certain thing happened, and you can give it an additional comment. This table has 3 foreign keys:

  1. deviceID from the table Device
  2. actionID from the table Action
  3. userID from the table User

Table Action:

In this table, you can find the actions all the components can do, such as:

  • measure
  • light up
  • make sound
  • vibrate
  • show ip-adress

Table User:

This table contains the information of a user, such as a unique ID, a name, their goal, and their streak.

Table Reminder:

In this table, you can find which user has which reminder. You can choose the type, the time between reminders, the amount you want to drink, and if you want your reminders faster when it's hot outside.

Table Logging:

This table contains the logging of a user, when they drink, it's counted as a logging. It also keeps a true or false value if you have reached your goal or not.


When you make a database, keep in mind that it's better to have consistence names for your tables. Always look if you don't have duplicate names, because this can cause a lot of problems.

To get this database on your Raspberry Pi, make this EER-diagram and do a forward engineer in MySQL Workbench.

In my github, you can find a dump excel file.

Setup a Remote Connection in Visual Studio Code

Screenshot 2023-06-03 121853.png
Screenshot 2023-06-03 121927.png
Screenshot 2023-06-03 122040.png
Screenshot 2023-06-03 122158.png
Screenshot 2023-06-03 122218.png
Screenshot 2023-06-03 122900.png
Screenshot 2023-06-03 123037.png

Make sure your Raspberry Pi is properly plugged in and connected to your computer before you start this step

  1. Open Visual Studio Code
  2. Click in the bottom left corner on the 2 arrows facing different directions.
  3. Select connect to host
  4. Select Add new host
  5. Give in pi@192.168.168.169, and press enter
  6. Select the top option, after that the connection is being created
  7. Then click again on those arrows, and select the right address
  8. Then it'll open, and you have to give up the password
  9. When it's done, instead of the arrows you see SSH:192.168.168.169

Clone the Github Repository

Screenshot 2023-06-03 123501.png
Screenshot 2023-06-03 123554.png
Screenshot 2023-06-03 123716.png
Screenshot 2023-06-03 123830.png

After Step 7, you can start doing this step.

Make sure your Raspberry Pi is properly plugged in and connected to your computer before you start this step

  1. Open this GitHub link
  2. Go to Visual Studio Code and click on the branch icon, this will open the source control panel
  3. Now click on Clone repository, and give in the GitHub link, and press enter
  4. After that, you can click the file icon to open the explorer tab
  5. Click on Open folder and find the folder for GitHub. The name should look like in the photo
  6. Select the right folder, and click on ok. After that, you have to give in the password again
  7. Congratulations, you now have all the files and codes you need for this project.

Install the Packages & Virtual Environenment

Screenshot 2023-06-18 182700.png

After Step 8, you can start doing this step.

Make sure your Raspberry Pi is properly plugged in and connected to your computer before you start this step, and that you are in the correct folder

  1. Open a new terminal
  2. The first command you enter in the terminal is: python3 -m venv .venv
  3. The second command you enter is:  pip install -r requirements.txt
  4. Now you have all the packages you need

Editing the Raspi-config

Screenshot 2023-06-18 183532.png
Screenshot 2023-06-18 183640.png
Screenshot 2023-06-18 183801.png
Screenshot 2023-06-18 183848.png

Make sure your Raspberry Pi is properly plugged in and connected to your computer before you start this step, and that you are in the correct folder

  1. Open a new terminal
  2. Command: sudo raspi-config (a blue screen will open in your terminal)
  3. Go to Interface Options and press enter
  4. Go to SPI, press enter, choose yes when asked if you want to enable it
  5. Again go to Interface Options and press enter
  6. Now choose I2C, and do the same as with the SPI
  7. And the last one is One-Wire, do the same as with the other one
  8. Now select finish and press enter
  9. Now again in your terminal do this command: sudo reboot now (this restarts the pi)

The Code

Backend

In the backend, you can find the classes for the different components I used, and a small test code for the components, so it's easier to see if you connected them correctly. This is in the helpers folder. There's also the app.py file, this contains all the code for the backend for the real code. First, there are all the imports for the raspi things and other. Then you can see the pin defining, and the global variables. After that there's the instance for socketio, then you can see how to make variables of the class components with the right pin defining. Then there's the setup, this makes the components ready to use for the rest of the code and the IP address is displayed there on the LCD, because this only needs to happen once. Then there's the loop, this code keeps repeating over, and over again. There you can find all the code that makes the components do what they need to do, and also counts the progress, and gets the data for the graphs. The timer is also made here, I used the time library, and makes the reminder go on the right moment. After that there are some functions, to create measurements for the database, to shut down your pi with a button, to get the interval out of the database, and the code for the reminders. Then you can see all the app routes, these are used to handle data in the fronted. Then there are the socketios to communicate between backend and frontend: socketio.on listens to a message, socketio.emit sends a message. Under all that code, there is the code to start threadings and sockets. Always keep in mind that you call the socket after the threading if you use 1. At last, there is the code to shut off the code with ctrl + c, and teh clear up of all the components and pins. In the backend, there is also a folder called repositories, in that folder you can find all the SQL scripts you need.

Frontend

In the frontend, you can see all the html-pages: login-page, index-page(home-page), overview-page, history-page, and settings-page. In the head of the HTML files, I imported all the stylesheets, fonts, and scripts. In the body is all the HTML that is going to be displayed on the page. Then there is the script folder, in there is our frontend code(app.js), this contains all the code for what is displayed where and when. For charts, I used apexcharts. All the get__ functions, are used to get data using the datahandler script, in those functions you call show or callback functions, above the gets are the shows, and under the gets are the callbacks. I also made for each page a different init. The last thing is the style folder, this contains the SCSS and CSS files to make the website look pretty, and make it mobile responsive. Make sure you push "watch sass", otherwise you won't see the layout.

Making the Casing

Screenshot 2023-06-18 184538.png

For the casing I used a lasercutter with MDF wood (40cm x 60cm x 3mm)

  1. Download and open the illustrator file in Adobe Illustrator
  2. Go to a place with a lasercutter
  3. Open the file on the computer and click file>print>done
  4. Now follow the instructions that are on the lasercutter

Downloads

Assembling the Casing

352865433_943251423621257_1553422742746677851_n.jpg
349706079_609070894532975_5193095092772777274_n.jpg
349158857_282682364202640_5350629642479966319_n.jpg

After the lasercutting, you can start assembling the case.

First of all I made a few small holes for the jumpwires. After that I glued 3 of the 4 sides to the underground, then I made (out of some leftover wood) a small platform for the raspberry pi. After that, I did the same for the rfid. Then I put the breadboard in the casing, and glued the last side. When that was done i glued the ledring on to the weightsensor, and taped the vibration motor inside the weightsensor. When those things were dry, I glued the weightsensor on the top of the casing. At first there was a small square, but I made it a bigger cirkel for the passive buzzer. In the other hole I put the button. For some extra, I glued the logo on the top of the casing. I didn't glue the top to the rest of the case so the electronics can always be accessible.

Run the Code

If you want to run the code automaticly and over wifi, you can follow this directions

Otherwise, you can just run the code in the terminal, but make sure you put sudo before it.

Good Luck

I hope my explanations are understandable, if something doesn't work let me know!

Enjoy this device :)