## **Tutorial on how to build an efficient office setup using temperature and lightning sensors**
The tutorial gives step-by-step guidance on building optimal lightning and heat conditions for working from home.
- Dana Kresova - dk222pe
### **The Project Story**
For this project I choose to build an IOT device that can measure a temperature in my room and maintain healthy lightning conditions when working from home.
:::info
:information_source: **Project estimation**
</> 40h depends on the experience with IOT
:::
#### **Objective**
The Covid-19 restrictions in Austria induced a new reality of working from home. Having a good setup became an important element to me to maintain productivity.
Therefore, the tutorial is about building an IOT device to measure temperature in a room and natural lightning conditions. The purpose is to provide solution to regulate temperature and elevate lightning conditions for homeoffice. Furthermore, being notified about the temperature changes e.g. temperature drops below 20 and monitoring of natural light play an important role for reducing energy consumption. Ultimately, dashboard serves as evidence to monitor a range of room temperature and lightning to foster effective home office setup.
##### Accordingly, the IOT project bases on 2 aspects
- Decreasing the energy consumption by utilising natural light as much as possible and turning on/off lights only when necessary.
- Having evidence about a temperature dynamic in the room for good working conditions.
### **Material**
-Pysense 2.0 board
-Fipy
-Breadboard
-Micro USB Cable
-Temperature sensor MCP9700
-Resistor 10 ohm
-Jumper wires
I ordered all the material from electrokit.com for 1499 SEK. I used Pycom Pysense board and Fipy device. The Fipy device has built-in connections of lora, WiFi, Bluetooth and LTE CAT M1/NB1 Cellular technology programmed by MicroPython.
### **Computer Setup**
1. Selection of Atom as IDE
2. Installation of Node js
3. Installation of Atom and Add pymakr plugin to Atom
In this project I use Atom as IDE and run all the codes there.
To know if your Node.js is installed, open command Prompt and type node -v. If installed correctly, it prints the version e.g. v18.3.0. As a second step, install Atom. When installed, open Atom add pymakr plugin by going to File – Settings – Install. You will see Install Packages type pymakr and click install.
Before moving to connecting the sensors, update of the firmware needs to be done. Firstly, put a Fipy device on the Pysense board so both are connected. After that connect the USB cable to your Pysense board and plug it into your laptop.
Make sure your laptop has a full battery for the firmware update or the battery charger is plugged in. This is important because the process should not be interrupted. Also, USB cable should not be disconnected as this may hamper the successful firmware update. As a next step download the link, install pymakr plugin
### **Connecting sensors**
To connect the sensors you will need a breadboard, pysense V2.0X, 12 jumper wires, Temperature sensor MCP9700, LDR sensor and Resistor 10 kohm.
1. Take a look at your breadboard , you might see numbering 1, 5, 10, 15, 20 and a dividing line in the centre. Put the Fipy device on the breadboard in a way that the led light is towards the edge of the breadboard. As you can see on the pic, the Fipy should be placed on the dividing line equally so that when A: B: and I: J: pins are free.
2. Take the Pysense, place it so the USB serial port is on the top.
#### Connect Fipy and Pysense board

3.a. Following a yellow cable, use P0 (second pin) on the Fipy and G2 (second pin) on the extension board from the left
3b. Following a white cable, use P1 (third pin) on the Fipy and connect it with G1 (third pin) on the extension board from the left
3.c. Now we need to do the other side (see red and green cable), following red cable use 3.5-5.5V (first pin) on the Fipy and connect it with 5V (first pin) on the Pysense board.

3.d Following a green cable use, GND (second pin) on the Fipy device and connect it with GND (second pin) on the Pysense board.
You should arrive at (see above pic)
4.Let´s connect LDR sensor
4a. LDR sensor has 4 pins, place LDR sensor on the breadboard e.g. I start from number 35 and make sure that 2 pins remain between the upper and lower legs of the sensor. We will need resistor and 3 jumper wires.

Place the resistor on the dividing line in the 4th pin from the lower leg of registor (see pic)

Take a wire and pin it in the 3rd pin from the lower leg (see pic. 4) and connect it with Fipy using P16. Take another wire (in my case orange cable) pin it in the 4th pin next to the upper leg of the sensor and connect it with voltage (close to the red line). Now we need to connect ground see white cable use 4 pin from the resistor and connect it to blue line = ground
The outcome should look like in the picture 5.
Pic. 5.

5.Let´s connect the Temperature sensor MCP9700
This sensor has 3 pinout: one side is round while the other flat. Place the sensor so the round side is situated outwards (see pic 6 and visualisation in the right corner). Take a wire (in my case yellow cable) and use 3rd pin from the middle leg of the sensor, then connect it to fipy P13. Use another wire (red) and pin it in the 5th pin from the lower leg of sensor and connect to the voltage close to the red line. Let´s connect the upper leg with ground, take a blue wire use the 5th pin and connect it close to the blue line (see pic 6).

To enable electric circuit we need 2 more wires (blue and red) that we connect to Fipy. As you can see on the pic, use the red wire pin in in 3V3 pin and connect it to the red line on the breadboard. Lastly we need ground connection, take a blue wire and pin it in the second row of pin (GND) next to the green wire and connect it to the blue line.

### **Platform Datacake**
For this project, I used a platform Datacake to upload my data over the MTTQ protcol. One the main reasons of choosing this platform was for its simplicity and powerful visualisations tools. Important decisive factor was also that the platform offers automation features.
### **Code**
In the below code I use while loop and define val as apin which read analogue value of LDR sensor. Then I define bpin and use string method and formula to convert voltage to degree celsius. Within a while loop I used logic condition for the LDR sensor to send data if the value of light is higher or eaqul to 1000 lux.
```
while True:
val = apin()
print("Value", val)
millivolts = bpin.voltage()
celsius = (millivolts - 500.0) / 10.0
print(celsius)
if val >= 1000:
send(celsius, val)
time.sleep(3600)
time.sleep(600)
```
### **Transmitting the data / connectivity**
For this project I tried using Lora but could not reach the coverage in my location. I used Wifi as a network connection because I use the device in my room so I do not need a large distance possibility.
### **Visualisation & Automatic notifications**

:::success
Below is an example of an alert. I receive the email notification when a temperature in my room is a higher or equal to 28°C.
:::

:::info
:information_source: I also set a condition to receive an email alert when natural light in my room is lower than 450 lux so I am aware that I might need to switch on the light to maintain good eyesight
:::
### **Reflections** :bulb:
My final reflections are that I could have worked on the battery consumption and frequency of sending data.