Project1


Hi
I'm an NMCT student and this year i got the assignment to create a project. I chose to create some sort of fitness device where you can see your BPM (beats per minute) and the temperature.
The project that I created has 2 sensors, a pulse sensor and a temperature sensor. I use a raspberry pi to get data from the surroudings and to display this data on a self made website in flask, html and css. In this instructable I will explain how I completed this project.
Circuit


To begin, we need a working circuit that can collect data from the environment, for this I used a T-piece Cobbler to easily connect my sensors to the correct GPIO pins. In the fritzing diagram you can see how I have connected them. For the resistance between the data pin and power supply pin of the temperature sensor you can use 5.1 k ohm as i did or 4.7 k ohm.
The temperature sensor is One-wire. The data pin from this sensor needs to be conected to GPIO pin 4!
The pulse sensor is an analog sensor! For this sensor we need the mcp3008 to convert the analog data to digital data! Connect the datapin from the pulse sensor to channel 0 of the converter.
Database

To store the data from the sensors i build a MySql database with 2 tables. The first table stores each user with his/her password and email to indentify each persons account when you log in on the website. The second table stores all data from the sensors and also date and time each value is added.
The first table is necessary for the log in system of the site, the second is necessary to fill the graphs and lists on the site.
Website


Next up is the website, to create this I used flask and let flask use templates to display all my pages. Those templates are html pages which are styled with css. Through SQL inserts the data from the sensors in the database will be read on the website. The graphs are created with javascript.
Command Line Interface

To make a project with a raspberry pi you obviously need to use the command line interface a lot! To run all scripts by startup you need services. Services have to be enabled to be usable.
To enable each service, use these commands:
sudo cp conf/project1-*.service /etc/systemd/system/
sudo systemctl daemon-reload
web interface: sudo systemctl start project1-flask.service
sensor.py: sudo systemctl start project1-sensor.service
web server: sudo systemctl start nginx.service
Also make sure your raspberry pi uses wifi, so you can forget about the Ethernet cable!
To make this happen, use this command:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Scroll to the end of the file and add the following to the file to configure your network:
network={
ssid="Test Wifi Network"
psk="SecretPassWord"
}
After this, reboot your raspberry pi!
Final Product
When all of the previous steps are completed, you can run all services on your raspberry pi and start everything by just plugging in the power supply.
To check if each service is running, use these commands:
web interface: sudo systemctl status project1-flask.service
sensor.py: sudo systemctl status project1-sensor.service
web server: sudo systemctl status nginx.service
At last, to use the project, follow these simple steps:
1) Plug in the power supply
2) Plug in the Ethernet cable and wait for the lights to turn on
3) Surf to: 127.0.0.1
4) Register on the site or log in with your account
5) Hold your finger on the green LED of the pulse sensor
6) Refresh the page to get the updated values
7) To log out, click on the user icon on the top right and click log out