# Temperature alarm for a freezer #### Dennis Sundin - ds222xx The project uses a temperature sensor that gathers data and uploads it to the cloud, it also uses a piezo buzzer which is used as an alarm if the temperature reaches a set threshold. I would approximate it to take about 45-60 minutes to recreate this project. ## Objective I got the inspiration to do this project after I realized that my freezer did not have an alarm that warns me if the door is left open. The purpose of the device is to measure the temperature outside of the freezer. The project could also give insight about the temperature in the apartment for other uses such as a fire detector ## Material The material for this project was bought through the website electrokit.com, the sensors used was a part of the arduino starter pack found [here](https://www.electrokit.com/produkt/arduino-starter-kit/?gclid=Cj0KCQjw3ZX4BRDmARIsAFYh7ZLAjVtklyqWfgPr7om-hjJ-F7a5maSOcxhK1bLxLCZAjwC7FGnecEYaAgUrEALw_wcB). The LoPy4, USB-cable and Expansion board was a part of the course package found [here](https://www.electrokit.com/produkt/lnu-1dt305-tillampad-iot-lopy4-and-sensors-bundle/) | Name | Quantity | For? | |:--------------- |:-------- | ------------------------------------- | | DHT22 | 1 | Measuring temperature | | Piezzo buzzer | 1 | Produces sound | | Jumper wires | 7 | Connecting the parts | | Micro USB Cable | 1 | Connecting to the PC and uploads code | | Expansion board | 1 | Expansion board for the LoPy4 | | LoPy4 | 1 | Process the code | | Breadboard | 1 | Neat way of connecting the sensors | | 10kΩ resistor | 1 | Limit the current | The price of the material would be around 100€ but if they were bought indivually it would reduce the price. ## Computer setup The IDE used in this project was Atom and the code is uploaded through a USB connection using the IDE. Before using the IDE an installation of [Node.js](https://nodejs.org/en/) was done. In the IDE the pymaker plugin was installed through the package installer. ## Hardware The electronics are connected as shown in the figure below. To make sure that nothing fries up a 10kohm resistor was used with the DHT22 sensor. It is also connected to ground, power and the pin on the expansion board. The piezo buzzer was just connected to ground and to the a pin on the expansion board. The Micro USB cable is then connected to the expansion board to give it power. ![](https://i.imgur.com/lDdZ7q7.png) ## Platform choice I chose to work with [pybytes](https://pybytes.pycom.io/) as my platform for displaying the data which is a free cloud based platform. I found it easy to vizualize data and use togheter with the device. The functionalites of the platform makes it easy to look at signals sent from the device and present them in a simple way. It does lack complexity when it comes to processing the data. ## Code The code works in a infinite loop with a 1 second delay. It reads data from the temperature sensor every second and checks towards the threshold that is 18C. If the temperature is below the threshold for 5 continuous seconds the alarm is used and cycles between being quiet using a frequency of 300Hz every second. The data is being send every 5 seconds to the pybytes database. The external library used is a DHT sensor library and was downloaded [here](https://github.com/iot-lnu/applied-iot-20/tree/master/sensor-examples/DHT11-22/lib) ``` #Import libraries import pycom import time from dht import DHT from machine import Pin,PWM #Define pins th = DHT(Pin('P8',mode=Pin.OPEN_DRAIN),1) red_led = Pin('P9'); green_led = Pin('P10') time.sleep(2) buzzer = Pin('P11', mode = Pin.OUT) tim = PWM(0,frequency=0) ch = tim.channel(2,duty_cycle=0.5,pin=buzzer) pycom.heartbeat(False) #Variable declaration timer_over = 1; timer_sec_running = 1; send_counter = 1; warningSound = False; while True: time.sleep(1) th_result = th.read() if(th_result.temperature != 0): #Removes faulty measurements th_result.temperature = round(th_result.temperature,1) #Round to 1 decimal if(th_result.temperature < 18): if(timer_over > 5): pycom.rgbled(0x7f0000) #RED, Under threshold for 5 continuous seconds warningSound = True else: pycom.rgbled(0x7f7f00) #YELLOW, Under threshold for a bit #print(th_result.humidity) timer_over=timer_over+1 else: pycom.rgbled(0x007f00) #GREEN, Over threshold timer_over = 0; warningSound = False if(warningSound): if(timer_sec_running%2==0): tim = PWM(0, frequency=300)#changes frequency ch.duty_cycle(0.5) else: ch.duty_cycle(0) else: ch.duty_cycle(0) if(timer_sec_running == send_counter*5): #Send every 5 sec to pybyte send_counter=send_counter+1 pybytes.send_signal(2,th_result.temperature) print(th_result.temperature) if(warningSound): pybytes.send_signal(1,1) else: pybytes.send_signal(1,0) timer_sec_running = timer_sec_running+1 ``` ## Transmitting the data to pybytes The data is transmitted to the pybytes database using the line pybytes.send_signal(signal,value). The signal is defined on the platform and the value is either the temperature or the buzzer value. The package size for the messages is 8 bytes and the it sends data every 5 seconds. The data is transmitted using WiFi and the device has been setup to work with my home WiFi. ## Result The dashboard can be seen in the figure below. It shows the temperature of the room along with the buzzer signal which serves the purpose of showing when the "alarm" went off. The data presented in the figure is from when I opened the freezer door and as seen in SIG1-Buzzer the alarm was used for approximately one minute. It is saved in the database every 5 seconds. ![](https://i.imgur.com/D4xVtSq.png) ## Conclusion Improvements could be made to both the code and the hardware to work more efficiently (and probably look nicer). More testing of the enviroment around my freezer could have been done to make it more accurate. A button to turn the alarm off could have been implemented to the breadboard. My thought was to mount this on the side of the freezer but I did not have the resources to do so. However, I am pleased with the way that the project works. The final result of the project is shown below. ![](https://i.imgur.com/DmB46Vg.png)