---
# System prepended metadata

title: Straightener extension

---

# Straightener extension

Julia Näsström, jn223ze 

**Table of contents**

## Introduction

Connecting a Fipy and Pysense to WiFi a simple extension for your typical straightener can be created. By measuring the external temperature close to the hot tool the data, which is published to Datacake, can be used to notify the user via email when it is hot enough to be used on the hair as well as how long one approximately should let the straightener cool down after usage. These two different stages are signaled to the user directly, utilizing the LED on the Fipy, as well. During the heating phase it will glow red and during the cooling phase blue. 
  
   This is a fairly simple project, depending on how exact you want the different thresholds for what is considered hot enough to be, which will have to be calculated empirically if one were not using my thresholds, it can take up to approx. 4 hours. 


## Objective
The main objective of this project is to be able to better tell when a hot tool, such as a straightener, is ready to be used as well as how long it should cool down after usage (approximately). This eliminates the need to constantly check if the straightener is hot enough by touching it, which can cause burns. Getting an approximate cooldown period can be helpful as well since one should not put away a hot tool which still is hot. This could cause fires for instance. These are the main issues I tried to solve and why I ended up building this project. Whilst this project might not generate life changing data one could utilize it in order to look if there are any changes in the performance of the straightener over time.



## List of Materials

| Components        | Price                   |
| ----------------- |:----------------------- |
| Pycom FiPy        |   Approx. 760 sek       |
| Pycom Pysense 2.0 X |   Approx. 320 sek  |
| Micro USB charger (detachable cord)         |   30 sek and up  |
| Computer running Atom (IDE)        |    | 
| Datacake   | Free|
| Total  | Approx. 1110 sek|
 
These components were bought from [Electrokit in a FiPy and sensors bundle](https://www.electrokit.com/produkt/lnu-1dt305-tillampad-iot-fipy-and-sensors-bundle/) for 1499 sek. In this bundle there are a few more things included than what is needed for the project. However, if one only wanted the components needed they can be found on [Pycoms](https://pycom.io) own website. The micro USB charger can be found in various stores at various prices. 

The only sensor used in the project is the Temperature and humidity one included on the Pysense called SI7006A20 (Datasheet can be found [here]( https://www.silabs.com/documents/public/data-sheets/Si7006-A20.pdf)) . The Pysense does contain three more sensors, an accelerometer (LIS2HH12), a light sensor(LTR329ALS01) and an altitude and pressure sensor (MPL3115A2). All of the sensors included are from a third party and use the serial communication protocol I2C. For each of the sensors there is a library written by Pycom which can be found [here]( https://github.com/pycom/pycom-libraries/releases/). Therefore the library written for the temperature and humidity sensor is utilized in the project in order to get data on the external temperature near the straightener.
![image alt](https://i.imgur.com/cGsVV6H.jpg)Pycom Pysense 2.0 X


## Computer Setup
Before Coding and connecting all the devices together the correct computer setup is needed. There are two main things to set up. Firstly the latest firmware is needed for the FiPy and Pysense and secondly an IDE is needed. I choose to work with Atom. My computer is running the macOS Mojave 10.14.6, therefore I downloaded the appropriate version of each program to best work with this operating system. Different operative systems will require different versions of the programs which is important to keep in mind. 


In order to update the firmware on the Pysense we need to connect it to the computer using the USB cable. Once this is done the DFU-until terminal tool is utilized, how this is done is described [here](https://docs.pycom.io/updatefirmware/expansionboard/). After the latest firmware is installed on the Pysense the Fipy should be updated as well. This can be done by connecting the FiPy to the Pysense, which in turn is connected to the computer's USB port. In order to update the FiPy an update tool is utilized, how this is done is described [here](https://docs.pycom.io/updatefirmware/device/). 

![](https://i.imgur.com/CfWSW4A.jpg) Pycom FiPy


Once all the devices are running the latest versions an IDE should be downloaded. One option is to use Atom together with the pymakr plugin. Atom is an open source text-editor developed by GitHub and can be downloaded [here](https://atom.io). After installing the IDE you can install pymakr by locating the ‘install package’ -> ‘open installer’  and search for pymakr. By doing this an interface is added to Atom, communication between device and IDE is now made easier and code can be uploaded to the device as well through the interface (press upload project to device). 

## Putting Everything together
This project does not use any loose sensors or actuators, everything needed is included in the Fipy and Pysense. These are connected like the picture below suggests with the LED on the FiPy situated above the USB Serial port. The FiPy should be placed with its leads right through the Paysense, *it will naturally snap in place*. The entire circuit is powered by the micro USB charger (5 Volt), but can be powered through the battery connector by a LiPo battery if needed ([More info](https://docs.pycom.io/datasheets/expansionboards/pysense2/)). 

![](https://i.imgur.com/pJsrAi8.jpg, =400x400)
![](https://i.imgur.com/84zSfrY.jpg, =400x400)


By using the FiPy and Pysense there are no notable connections one has to keep track of, as well as no need for any resistors, electrical calculations, circuit diagrams etc. This makes working with the components easy. However, by removing these loose sensors and only using these larger ones the look of the project gets affected. You can’t really design any shell to put the sensors in since it can affect the values measured (external temperature). Therefore I would personally not use this project in production but rather as a prototype of something which could be made in the future. 

## Platform
When choosing the platform I had some conditions. Firstly it should have simple widgets which clearly can display the temperature and cooldown time. Secondly I wanted to be able to send out notifications. When waiting for the straightener to heat up one usually does not interact with it, but rather let it sit to the side. Therefore you could do something else whilst waiting and pick it up once the notification is sent. Then once the cooldown time has been calculated another notification is sent out as well, signaling to the user that it exists if they wish to utilize it. Since the project is meant to be used individually, others having access to the data is not necessary. However, I did want the platform to be free. 

There are some platforms of this type such as pybytes, adafruit.io etc. I ended up choosing Datacakes since it ticked all of my boxes. This platform has a free plan where 500 data points per day can be sent with a 7 day retention. If one wanted to expand this there are other options available, for instance if the performance of the hot tool is something you want to study a longer retention might be of interest. However, this cloud platform offers some free options such as sending out notifications via email which makes it preferable to use. There are options to send out them via SMS as well, but this costs money. The platform offers a simple dashboard which is clearly visible for the user and looking at the history (previous data) is easy as well. If the project were to be scaled up I would probably look into having the notifications sent to somewhere else. Whilst the email works, the notification pops up as intended, there probably is a more effective way to notify the user. Information on how to set up a Datacackes account and display data can be found [here](https://hackmd.io/@lnu-iot/r1aui0B59#Datacake-part). 

## The code

All code for this project can be found [here](https://github.com/jnassjnass/Temp_and_humidity-2)

> Snippet of the two main loops
```python=52
pycom.heartbeat(False)

# Phase 1 is heating
Heating = True
while Heating: # Whilst we heat up the hot tool, get temprature and publish it
    pycom.rgbled(0xFF0000)  # Blink red during this phase
    temp = get_data()
    client.publish(my_topic_temp, msg=str(int(temp)))

    print("Send data to MQTT broker, sleeping for 10 sec...") # Confirmation that we are resing
    time.sleep(10)

    # Note: This threshold might be different for different people, play around with it!
    # Check if our temp is above 70 celisus, if yes then our hot tool is hot enough and we exit loop
    # Else we get new temprature (While loop continues)
    if temp > 70: # Change if needed
        print('I am hot enough now!')
        Heating = False
        Cooldown = True # Triggers next phase

# Phase 2 is cooling down
i = 0 # Our cooldown time will be calculated using a simple counter
while Cooldown:
    pycom.rgbled(0x0000FF) # Blink Blue during this phase
    temp = get_data()
    client.publish(my_topic_temp, msg=str(int(temp)))
    print("Send data to MQTT broker, sleeping for 10 sec...")
    time.sleep(10)
    i += 10 # Add 10 sec to counter (Since we waited 10 since last time)

    # Note: This threshold might be different for different people, play around with it!
    if temp < 36: # Change if needed
        print('cooldown time done: ', i, 'Secs')
        client.publish(my_topic_cooldown, msg=str(int(i))) # Publish this!
        Cooldown = False
```

The code consists of two main phases, the heating phase and the cooling phase. The heating phase is signaled by the LED glowing red on the FiPy. Every ten seconds a new measurement of the external temperature close to the straightener is taken. The value is then sent to Datacackes. When the temperature measured is over 70 celsius I have decided that the straightener is hot enough to be used. Note that the actual temperature of the hot tool is not 70 celsius but rather the environment in which the sensor is placed. This threshold was calculated empirically by trial and error. I would recommend that you fine tune these thresholds yourself to fit your situation. 

![](https://i.imgur.com/DKIWUK1.jpg, =400x400) During Heating process


When tuning the thresholds I had to turn the straightener on and off multiple times in order to find a suitable value. When doing this I noticed that both the sensor and hot tool cooled down similarly. I decided to explore and utilize this property a bit, whilst it is not a fully scientific result it might still prove useful. So once we have reached 70 celsius the heating phase is over and we start the cooling down phase. Since the straightener now is good to use we would remove it from the sensor and use it on our hair. This means that the sensor will be left alone to cool down, signaled to the user by the LED glowing blue. Once again it sends out the current external temperature to Database every 10 seconds. However, it now also times how long it takes to reach the new threshold of 36 celsius, which I consider a cold enough temperature for the straightener to be when putting it away. Again, find your own threshold here. Once the second threshold is reached the time it has taken for the sensor to cool down, which loosely corresponds to the time it will take for the straightener to cool down will be sent to Datackes as well. Ever since the beginning phase we have sent temperature values to Datacackes every 10 seconds. Once the cool down value has been sent the code stops running, we are done!

![](https://i.imgur.com/AVycofg.jpg, =400x400) During cooldown process


**Note:** The parts where one should change for instance the different thresholds, Wifi passwords and SSIDs as well as Datacake information is clearly mentioned in the code.

## Transmitting the data
As mentioned above the temperature data is sent every 10 seconds and the cooldown time is sent once. Both values are sent using WiFi as the wireless protocol and MQTT as the transportation protocol. These protocols work for my intended purposes since I only really use the straightener inside, where WiFi almost always is available. I can move around with the sensor and straightener without any issues which is useful. One could play around a bit with how often values should be sent, I noticed that sending them every 10 seconds worked well. Since one only would use the project for a relatively short amount of time, I for instance only use it for about 15 minutes, sending these many values works without exceeding the 500 data points per day. 

## Presenting the data
The current temperature is always displayed as soon as it is received on the Datacakes dashboard using a value-widget and then stored under the history tab with a 7 day retention in a graph.  As soon as the temperature exceeds 70 celsius an email is sent to notify the user. The same goes for the cooldown data, it is presented using a value-widget on the dashboard as well as saved under the history tab with a 7 day retention. 
![](https://i.imgur.com/XGtCFHZ.png) *The Last value sent before cooling process beginns to the right. To the left the previous cooldown time is presented.*

![](https://i.imgur.com/oXujcR2.png) *Previous data saved in this graph*



## Finalizing the design
When starting this project I went in with an open mind and a vague idea of what I wanted to do, which was to measure the temperature. I began testing out different ways of doing this. Should I leave it out in the sun during the day and have it work as a thermometer? What is the lowest possible temperature I can measure and what is the highest? How does humidity play a part in it all? 

After playing around with it I naturally ended up using my straightner to get a high temperature and decided I could explore this idea a bit more. Then I just ended up adding features as I went along, such as utilizing the LED on the FiPy to make it more user friendly or finding the best way to position the sensor when the straightener is heating up (which ended up being in between the plates of the straightener). I ended up building a little holder for the hot tool and sensor so that it could be left hands-free. 

![](https://i.imgur.com/wk5pPBz.jpg, =400x400) Final prototype during heating process. Everything is placed on a *heatprotected mat* close to an power outlet.


Since I did not have a clear idea of what to make when starting this project, but rather wanting to explore the different ways of measuring temperature, I would say that the project went relatively well. As a product itself I do not know if I will use it in everyday life. Perhaps if the sensor was integrated inside the straightener instead of being a larger external extension of it I would feel more inclined to use it which could be a future development. However, as an idea, having something tell you when it’s hot enough and then how long it should cool down/ when it’s cold might have potential. One could for instance use it on their computer, so that it tells you when the computer is too hot and needs to cool down or something similar. In order to do this you really just need to tune the thresholds to fit your purpose. There are many possibilities for development of the project but overall I am happy with the final product.
