Introduction: Project ElectroTerra

I made a "smart" terrarium/vivarium as a school project.

ElectroTerra is run by a Raspberry Pi which hosts a website and stores data gathered from the sensors in a MariaDB database.

The website shows temperature and relative humidity from the sensors and allows control of the fan and LED strip. That strip can also work automatically bij a LDR sensor.

I assume some practical knowledge of using Raspberry Pi, Arduino, MariaDB (Mysql) and on wiring breadboards.

Supplies

I made a list of materials so that you can find everything needed for this project.

Step 1: Raspberry Pi Setup

First you need to set up the basics for the Raspberry Pi: https://www.raspberrypi.org/downloads/

I used a ssh connection to control the Pi with a laptop: https://www.raspberrypi.org/documentation/remote-access/ssh/

For coding I used Visual Studio Code with a ssh extension: https://code.visualstudio.com/docs/remote/ssh

To make the website available within your private network you can check this instructable from step 1 - 3: https://www.instructables.com/id/Host-your-website-on-Raspberry-pi/ There is no extra security build in this project so beware of exposing it on the internet.

Step 2: Creating the Electronic Circuit

In the fritzing scheme you can see every needed component in this project. The 1-wire temperature sensor can be replaced by the build in temperature sensor of the DHT22.

The Arduino is powered by the Pi via the USB cable.

Step 3: Arduino + Programming

Since the functions in the Arduino libraries for the DHT22 and the LED strip driver are very elaborated, I decided to add an Arduino for these parts.

Therefore you need the Arduino IDE.

Make sure to import these libraries:

Step 4: Testing the Sensors and Actuators on the Pi

In the Github repository are some test files for the individual components.

These are the classes: mcp.py (coverting the analog data from the LDR) pcf.py (communicating I2C data) and pcf_lcd.py (interfacing with the LCD).

Step 5: Database

Create the electroterra database on the Mysql worckbench via the dump file (final_dump_electroterra.sql in the Github repository) with some test data.

There is a compatibility issue by using the "Forward Engineer to Database" wizzard in Mysql Workbench. Make sure to remove the VISIBLE parameter in the sql statements since this is not working in MariaDB.

Step 6: Frontend

The HTML, CSS and Javascript code can be found in the Github repository. They should be put in the directory where the website will be hosted. The design is optimised for mobile use and was tested on the latest stable Chrome, Firefox and Edge versions.

Step 7: Backend

The app.py, datarepository.py and Database.py code must be in the home directory of the Pi user. To make the Pi run the file automatically at reboot use these instructions: https://www.raspberrypi.org/documentation/linux/usage/systemd.md

You can find the code in the github repository: https://github.com/DeblaereHannes/ElectroTerra

Step 8: Putting Things Together

This setup is a proof of concept.

The fan is fixed in place with hot glue. Some extra holes were drilled in the ventilation strip for wiring.

Next up was a box to keep the electronic parts. A simple plastic box was used. Consider adding a ventilation strip in case of overheating.

Step 9: Testing

Power up the Raspberry Pi and the power supplies.

Browse to the IP address shown on the LCD display.

By this, you can monitor the data and control the actuators.