Introduction: Natural Vitamins IoT Device

About: Hello! I'm a MCT student at Howest Kortrijk

Hello everyone!

I am a student at Howest Kortrijk and I study MCT. For our final project in our 1st year we had to realize a project. My project is Nature Health. An IoT device that determines how much vitamin D you need to stay healthy (from a natural source: sun).

The reason I chose this project is because I noticed with the corona pandemic that people were sitting inside too much and thought I would find a solution to that, Nature Health!

To accomplish this I used some sensors, an LCD, Raspberry PI, Arduino, ... (this comes in Step 1). Everything runs on the Raspberry Pi (Frontend, Backend, Program itself).

It's also my first instructable I've ever made so if anything is missing or you don't understand something. I will try to answer as soon as possible :) !

View my Github Repository here!

Step 1: Supplies

Main computing units:

  • Raspberry Pi

Everything runs on this controller, only the Air Quality Sensor runs on Arduino.

  • Arduino Uno

As mentioned above, the arduino serves only for reading the Air Quality Sensor.

Electronics:

  • Breadboard with copper wires

To connect the pins (of the sensors, ...) to the GPIO-pins on the Raspberry Pi.

  • Resistorts

3x 220 Ohm & 1x 330 Ohm

  • Breadboard adapter

T-piece that shows the GPIO-connections on your breadboard.

Sensors, modules & actuators:

  • DS18B20 1-Wire temperature sensor

Thermometer that measures temperatures from -55°C to +125°C (-67°F to +257°F).

  • Adafruit CCS811 Air Qualtiy Sensor

Ultra-Low Power Digital Gas Sensor for Monitoring Indoor Air Quality.

  • VMA405 RFID read/write module

Used to scan a pre-programmed badge.

  • Buttons

3 buttons to control the LCD.

  • LCD-display

16x2 LCD-display, which allows you to have 2 rows of 16 characters written.

  • Potentiometer

To adjust the contrast of the LCD.

  • Speaker

Housing:

  • 3MM wood

Tools:

  • Soldering

Used for soldering the pins of the speaker, lcd, sensors.

  • Lasercutter

Cutting out my case.

  • Superglue
  • Screws

Step 2: Circuit

Now that we have all our materials we can start wiring!

For this we will need our:

  • breadboard
  • copper cables
  • breadboard adapter

I have also drawn out an electrical diagram for you & the circuit on the breadboard.

Important here is that you watch carefully that you don't connect anything to 5V instead of 3.3V!

When you boot up your Raspberry Pi, make sure there is no short circuit! Otherwise, your PI, may be RIP. But if you follow everything as indicated on the schematics this should not be a problem at all.

Step 3: Setting Up the RaspberryPi

Now that we've done the basics, it's time to set up the Raspberry Pi! The main computing unit of our project.

1) Software & Files

First of all we download the required software and files

Software:

- Win32 Disk Imager: Download here

- SD Card Formatter: Download here

- PuTTY: Dowload here

Files:

Raspbian OS: Operating system of the Pi: Download here

2) Configuring the SD Card

- Insert the card into the card reader (allready built in or external)

- Open up SD Card Formatter and format your SD card (When it's completed we are going to write the OS to the SD card)

- Open Win32DiskImager

- Select your device

- Click on the folder-icon and search the .img file

- When your OS is loaded you press Write

Info: This process takes a while so be patient!

- Go to your SD card's directory, search for the file named 'cmdline.txt' and open it

- Now add 'ip=169.168.168.168' on the same one line and save the file

- Create a file with the name 'ssh' without extension or content

3) Connecting with the Raspberry Pi

- Open up PuTTY

- Categorie: Session

- Host Name: 192.168.168.168

- Port: 22

- Finally press Open


4) Logging in on the Raspberry Pi

The default user & password are:

  • User: pi
  • Password: Raspberry

Info: For security reasons and good practice change your password immediately with the command passwd

5) Setting up the Raspberry Pi

Become root:

sudo -i

Enable interfaces:

First thing we need to set up is to enable some interfaces:

raspi-config

Enable these interfaces:

  • One-Wire
  • I2C
  • Serial
  • SPI

That was everything we needed to do in the raspi-config menu!

Adding WiFi:

Replace SSID with your network nmae en password with your network password

 wpa_passphrase "ssid" "password" >> /etc/wpa_supplicant/wpa_supplicant.conf

Check if everything is configured the right way

nano /etc/wpa_supplicant/wpa_supplicant.conf

Enter the following code in the WPA menu:

wpa_cli
interface wlan0
reconfigure
list_networks

reboot

Now the Pi is fully set up!

5) Installing software on the Raspberry Pi

Now that we are connected to the internet we can update the software installed on the Pi! We do this by using

sudo apt-get update
sudo apt-get upgrade

After updating we need to install the following software:

  • MariaDB
sudo apt-get install mariadb-server
  • Apache2 Webserver
sudo apt install apache2
  • Python
sudo apt install python3

After this you need to do a sudo reboot 1 more time for everything to work correctly

Step 4: Database

To store the data from the sensors, I designed a database. As you can see in the EER diagram the database contains 3 tables and I will go through them all separately!

1. Component

This table contains every sensor or actuator. It describes the sensor name and measuring unit.

2. Actie

This table stores actions for a different sensor. One action is always linked to a particular sensor.

3. Historiek

This table keeps track of all the values of the sensors read in. Each value has a unique id, component id, actie id, time of measurement & comments.

If you want to get this database on your Rasberry Pi, head over to my GitHub!

Step 5: Backend

If you haven't already, head over to my GitHub and clone/download the repository. Under the folder Backend you will find the full backend for the project.

The folder contains classes that I made for reading the used sensors. Also a folder /repositories that I use to communicate with the database and the main application is in the root map (app.py).

View my Github Repository here!

Installing Python packages:

Our whole backend won't work if we don't install these next packages:

pip3 install flask-socketio
pip3 install flask-cors
pip3 install gevent
pip3 install gevent-websocket

Now you can run app.py without any problems!

Step 6: Frontend

Now that the backend is done, we can start writing the frontend.

The website is mobile first, what that means is that persons using the website on the phone has the same features as a person using the website on the computer.

View my Github Repository here!

Step 7: Housing

Since the name of my project is "Nature Health," I naturally had to make sure my housing had a natural look. Therefore, I worked with wood for my enclosure!

As you can see, everything was sawn to the mm. Only I didn't saw it, I used a lasercutter! I highly recommend this technique. You create your design in Adobe Illustrator (or another program that supports the corresponding laser cutter) and let the laser cutter do its work.