# IoT Scale
**Irma Krantz Golinski, ik222qv**
How to build a scale is the goal of this Internet of Things project. The scale can measure up to 1kg and the hardwear that we are using are Raspberry Pi 3+, weight sensor HX711 and a load cell.
Time esimation is depending on previous experience with IoT, programming and the hardwear but i would say but around 5-10 hours with everything.
### Objective
The project was choosen because I did not have any previous experience of working with Rasperberry Pie and sensors. I choose something I thought would be on a good level for myself. A friend of mine had some of the equipment I needed fot the project so that was also a reson why I chosse this project.
Scale is something we use in all kinds of areas and I thought it be interesting to know how it works, understand one of the most useful tools we have.
It will give me insights how a scale works, how to us a Raspberry Pi and how to work with sensors.
### Material
| Image | Item | From | Price | Description |
| -------- | -------- | -------- | -------- | -------- |
| []()| Raspberry Pi B 3+ | Borrowed| - | Credit-card sized computer that plugs into a computer monitor and uses a standard keyboard and mouse.|
| []() | HX711 | m.nu | 69 kr | Is used to read load cells used in electronic scales connected through a wheatstone bridge. |
| []() | Load Cell | Borrowed | - | The load cell is built up as a wheatstone bridge and can measure the applied pressure. |
| []() | Female/Female Jumper Wires | m.nu | 59 kr | Connect the sensor to the Load cell and Raspberry Pi|
### Computer setup
The Raspberry Pi was borrowed from a friend who had installed the editor Thonny. Since it works perfect with Python I choose to work with Thonny. I installed the IoT platform Blynk so I could display the data.
No computer was needed for this project so I didn't have to install anything there nor upload any code since I wrote the program on the Raspberry Pi.
### Putting everything together

The Raspberry Pi, weight sensor (HX711) and load cell are connected with jumper wires (female-female). Pin 2 (5V) on the Raspberry Pi is connected to VCC on the weight sensor, pin 6 (GND) is connected to GND, pin 29 (GPIO 5) is connected to DT and pin 31 (GPIO 6) is connected to SCK. The four wires on the load cell are connected to the weight sensor. The red wire is connected to E+, black to E-, green to A- and white to A+. Finally the Raspberry Pi is connected to a screen, mouse, a keyboard and a micro-usb that ends with a power socket.
### Platform
The platform I choose to use is Blynk since it work very well with the Raspberry Pi and a good application for the phone. Blynk is easy to connect through WiFi, it works with any hardware, it has drag-n-drop editors for both webb and mobile apps. I didn´t try different platforms so unfoutrunately I don´t have anything to compare with but I´m satisfied with the Watson platform. The platform is cloudbased and I got to try out a free trial for this project.
### The code
The main file can be seen below were some packages are imported to be able to controll the GIPO on the Raspberry Pi. The weight sensor HX711 is set up and the scale is calibrated. I used a known weight to calibrate and the vaule I first got was 28 250 and the obejct on the scale was 250 g. So I calculated 28 250/250 and got the parameter 113.
```
import time
import sys
import RPi.GPIO as GPIO
from hx711 import HX711
hx = HX711(5, 6)
hx.set_reading_format("MSB", "MSB")
hx.set_reference_unit(113)
hx.reset()
hx.tare()
print("Tare done")
val = hx.get_weight(5)
print(val)
hx.power_down()
hx.power_up()
```
Get the weight from the scale is done from the code below where get_value_A(times) returns the median value of the read values.
```
def get_weight(self, times=3):
return self.get_weight_A(times)
def get_weight_A(self, times=3):
value = self.get_value_A(times)
value = value / self.REFERENCE_UNIT
return value
```
### Transmitting the data / connectivity
Everytime there is an impact on the scale, data is sent over WiFi to Blynk but somehow the WiFi has been struggeling a bit since I
ve been trying to share it from my phone. When I´ve used WiFi from a router there hasn´t been any problems. Blynk uses a transport layer security protocol, TSL, that relies on industy standards.
### Presenting the data
Blynk IoT Platform was used to present the data from the scale. Blynk presents the most recent data on the screen and updates everytime there is an impact on the scale.

### Finalizing the design
I think the project went very well since I didn't have any experience of this before I started the course. I feel like I've learned alot but I of course see that there is much to learn and experience. I'm satisfied with the result and look forward to learn more within this area.
