Introduction: TerraTech: Smart Terrarium for Reptile Havers

I have developed a sophisticated smart terrarium that employs various sensors to accurately monitor and analyze key environmental factors, including humidity, temperature, and water level. The project incorporates programming languages such as Python and JavaScript to ensure seamless functionality and optimal performance.

Supplies

Electrical Supplies:

  1. 2x DS18B20 OneWire Temperature Sensors
  2. 1x DHT11 Humidity & Temperature Sensor
  3. 1x CQRobot OceanWaterLevel sensor Non-Contact
  4. 1x Airwick Freshmatic
  5. HD44780 16x2 LCD Display
  6. uxcell DC 5V Blue LED Pilot Light SPST Momentary Action Pushbutton Switch
  7. Raspberry Pi Model 4 B
  8. Raspberry Pi PSU 5.1V 2.5A MircroUSB
  9. 1 Basic breadboard & F-F, M-F Jumper cables +- x40
  10. Breadboard PSU & Cable
  11. T-Extentionboard (bcm)
  12. L293D board

Physical Supplies:

  1. Wooden Plank(s) 100x100cm
  2. screws (different sizes)
  3. basic tools(such as screwdriver, saw,..)
  4. (old) rectangular terratrium/aquarium 15x30x17
  5. 2 small hinges
  6. a handle(for the lid)
  7. Silicone (Black)
  8. Instant Glue

(Bill of materials with prices below)

Step 1: Circuit

Make the follow Electrical Scheme:

  • Put the breadboard psu at the end of the breadboard and put each side to 3.3V and 5V respecfully.
  • Connect the GND from both sides to the extentionboard
  • Follow the scheme and don't forget to put the resistors in for the OneWire & On/Off button

Step 2: Initializing the Repository and Work Environment


  • Before cloning the repository, make sure your Pi is connected to Internet
  • Clone my repository:https://github.com/howest-mct/2022-2023-projectone-CardoenOlivier
  • Make sure you cloned it in the root pi folder
git clone <insert_url_here>	

Create a virtual Inverement

python -m venv <venv_name>

Now we need to setup the Database

  • Install the connector with:
sudo apt install mariadb-server mariadb-client -y
  • After this we configure the user student with password W8w00rd on the MariaDB server
  • To access the MariaDB server
mysql -u root -p
  • Creates a new user student with password W8w00rd that gets rights to all databases.
grant all on *.* to 'student'@'localhost' identified by 'W8w00rd'; grant grant option on *.* to 'student'@'localhost'; 
  • Reload privileges
flush privileges
  • Name the Database "terrarium", it will otherwise not work
  • Install the following SQL Dump and put in inside the remote SSH Database
  • Copy the txt file and paste it in your MySQL Workbench and run

Now the Database should be ready

Installing external packages:

  • (make sure you are running this inside the venv)
pip install -r requirements.txt
  • Install the following packages
pip install adafruit-io
apt install apache2

check if everything is installed with the command

pip list

Attachments

Step 3: Hardware Functionality

Now we will check if you can run the sensors apart from the frontend.

  • Enable the onewire Bus:
sudo nano /boot/config.text
  • Add the following line in this file after [all]:
dtoverlay=w1-gpio
  • Now save the file with crtl + X, Y, enter
  • Reboot the pi with the following command:
sudo reboot now

For the OneWire Sensors, there are different physical addresses, you can check these with the following commands:

  • Go to the following directory:
/sys/bus/w1/devices/w1_bus_master1
  • Now you can see if there are OneWire devices connected by looking at the map contents using the command:
ls
  • To be sure if the Sensor is functional or not, we can check the current temperature with the following command:
cat <name-of-the-onewire>/w1_slave

Now all you have to do is change the name of the sensors in the app.py file on line 17.


All the other sensors should work without having to change any of the raspi enternal settings if wired correctly.

Test the sensors with the test.py file in the test folder.

Step 4: Fullstack Functionality

To be able to run the front-end standalone without the VScode liveserver extiontion, these steps must be made.

Step 1: Run the front-end on your default debian webpage

  • On your PC, surf to http://192.168.168.169.
  • You should normally see the Apache2 Debian Default Page, which is the Apache default page currently located in the /var/www/html/ directory on the Pi. We will not use this default directory, but will use the front-end directory from the repo you just cloned.
  • If you are no longer sudo:
sudo -i


nano /etc/apache2/sites-available/000-default.conf
  • Use the down arrow to go to the line that now says DocumentRoot /var/www/html or DocumentRoot /home/pi/<name_of_your_repo>/front and change it to DocumentRoot /home/pi/<name_of_your_repo>/front
  • You save by doing Ctrl + x, followed by Y and Enter

Step 2: Restarting Apache and editing the file

  • Then we restart Apache by doing service apache2 restart
  • Now we have to set the rights on the root folder correctly.
  • open nano /etc/apache2/apache2.conf and use the down arrow to look for the following lines:
<Directory />
  Options FollowSymLinks
  AllowOverride All
  Require all denied
</Directory>
  • and change it to:
<Directory />
  Options Indexes FollowSymLinks Includes ExecCGI
  AllowOverride All
  Require all granted
</Directory>
  • You save by doing Ctrl + x, followed by Y and Enter

Step 3: Restarting the Apache server (again)

  • Then we restart Apache by doing service apache2 restart
  • Check if apache started correctly: service apache2 status
  • You should get something like the following output:
  • Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  • Active: active (running) since ...


Step 4: Making sure the project runs on it's own

  • Create a file called myproject.service
  • Place the following code in the file:
[Unit]
Description=ProjectOne Project
After=network.target
[Service]
ExecStart=/home/pi/<your_repo_name>/<venv>/bin/python -u /home/pi/<your_repo_name>/backend/app.py
WorkingDirectory=/home/pi/<your_repo_name>/backend
StandardOutput=inherit
StandardError=inherit
restart=always
User=pi
[Install]
WantedBy=multi-user.target

Copy this file as root user to /etc/systemd/system with the command

sudo cp myproject.service /etc/systemd/system/myproject.service

Now you can test the file by running it:

sudo systemctl start myproject.service

You can stop the file by entering the command:

sudo systemctl stop myproject.service

If everything works well you can have the script start automatically after booting:

sudo systemctl enable myproject.service

You can view the status of your service via:

sudo service myproject status

You can view the logs via:

sudo journalctl -u myproject


Reboot the Raspberry Pi and you're ready to go!

Now all the software-end services/files should fully operational

Step 5: Housing of the Electronics

For the you will require (some) physical strength


Step 1: Making the new floor

  • Use a hammer to break the upper and side panel(s) of the terrarium
  • Remove the frame of the upper panel and cut the wood to fit the panel (this will be the new floor)
  • Fit the wooden panel inside the frame with some Silicone or glue
  • Let the silicone dry by adding additional weight on top of the terrarium

Step 2: Making the lower-tray compartment:

  • Cut 5 pieces of wood and glue them together
  • Make it the same size to fit the bottom of the terrarium
  • Let it dry for at least 3 hours

Step 3: Making the Electrical compartment

  • For the terrarium to be extra sturdy, we will add additional planks to make it thicker
  • Cut 2 wooden planks and glue them to the sides of the tray
  • Let it dry for at least 2 hours

Step 4: Making holes to fit the components

  • Make 2 holes in each sides of the bottom of the terrarium to fit the OneWire temperature sensors
  • Make another hole in the middle to fit the DHT11 Humidity sensor
  • Make a rectangular hole to fit the LCD display
  • For the DHT11 to be water-proof, we will add an additional wooden block, apply it with instant glue
  • Make another hole for the ON/OFF switch
  • Make another hole to fit the Raspberry PSU and the Breadboard PSU

Step 5: Applying the hinges to the terrarium and the electrical compartment

  • Drill 6 holes in each part respectfully, to fit the hinges
  • Screw the hinges in
  • Now you should have a chest-like terrarium :D

Step 6: "Hacking" the Airwick

  • Open the Airwick, with the model of your choice, and cut the Red and Black wire from the main board
  • Solder it to the 2 wires connected to the L293D board
  • Now we need to install the water-level sensor
  • To be able to fit the sensor, we need to cut a hole in the Airwick, so the sensor can fit the frame
  • Place the Sensor on the water-container

Step 7: Making the spray compartment

  • Cut 5 pieces of wood and glue them together
  • Make it the same size to fit the side of the terrarium
  • Let it dry for at least 3 hours
  • Make a small hole, so the cables from the Airwick can fit inside the terrarium
  • Make another hole so the spray can spray into the terrarium, and not in a wall ;)
  • To make it extra secure, I've used a spare tube that was just laying around (free)

Step 8: Applying the compartment to the mainframe

  • Apply 2 extra wooden planks to make it extra secure
  • Drill 4 holes in each compartment respectfully
  • Drill it in place
  • If not secured, or tight enough, use silicone or glue to have an airtight fit

Step 9: Making the lid

  • Cut a plank to fit the upper part as a whole
  • Now cut another plank so it barely fits inside the glass terrarium itself
  • now screw these 2 in each other so the lid is secured and stays in place
  • Now drill 2 screws on top of the lid to fit the handle
  • Drill the handle in

Step 10: Placing the electronics inside

  • Start by putting the Onewire, DHT11, LCD-Display and the ON/OFF button in their respectful holes
  • Put the breadboard & Raspberry Pi inside and make sure their power cables are fitted trough the hole
  • Wire the ON/OFF, LCD-Display to the breadboard using the electrical scheme
  • Now place the Airwick inside it's compartment and make sure the cables are fitted trough the extra opening we've made earlier


Close it up and power it on!

Enjoy!

~Olivier