# Light and temperature sensoring ## Oskar de la Vaux, od222bk ### Project description This tutorial will guide you through the process of setting up a light and temperature sensor using the pycom lopy_4 device. It also shows you how to send the data to the pybytes platform. #### Estimated time: Beginner: 5 hours Pro: less than 1 hour ### Objective Recently I moved apartments and I wanted to figure out how the environment is in every room, if there is any possibility to grow plants on the window sill in the kitchen etc. ### List of materials | Device | Usecase | link | Price (sek) | | -------------------- | ----------------------------- | --- | ----- | | Lopy_4 | programable microcontroller |https://pycom.io/product/lopy4/?gclid=CjwKCAjwi_b3BRAGEiwAemPNU2rrgg141KDJKFRQPXQISV_2U-QIoD8othOi_HMU-pRcFVFlt02rFhoCUBMQAvD_BwE | 350 | | shield | what you connect your lopy to |https://pycom.io/product/expansion-board-3-0/ | 160 | | photo sensor | measures the light | https://www.electrokit.com/produkt/fotomotstand-cds-2-5-kohm/ | 8 | | temperature sensor | measures the temperature | https://www.electrokit.com/produkt/mcp9700-e-to-to-92-temperaturgivare/ | 8 | | resistors | used for voltage dividing | https://www.electrokit.com/produkt/motstand-metallfilm-0-6w-1-100ohm-100r/ | 1 | | charger (power cable) | powering the device | https://www.teknikdelar.se/mobiltillbehor/htc/one-m8/kablar-laddare/deltaco-micro-usb-kabel-1-m-svart/?dfw_tracker=35448-USB-301S&shopping_id_click=USB-301S&gclid=CjwKCAjwi_b3BRAGEiwAemPNU1GpYEsfZTEIlkIXKVdwuaH55zz1GOeWXHv07Joq1doXC5ko1ZeDnhoCmoEQAvD_BwE | 29 | Total price: 556 kr ### Computer setup When setting up your computer and pycom device there are a few steps you should follow. 1. The first step is to register a pybytes account. Follow this link https://docs.pycom.io/pybytes/getstarted/ 2. The second step is to add a new project and device to your pybytes account. (In this step you have to add your preferred way of sending data to the platform) 3. After creating a new device it is time to flash your lora device with the correct firmware. Follow this guide (https://docs.pycom.io/pybytes/connect/quick/) and install the latest pybytes firmware. 4. Now that you have set up your hardware it is time for you to download an ide. In this guide atom is used, To download atom follow this link (https://atom.io/). 5. When atom is installed it is time to add the pymakr plugin. To do that follow these steps (https://atom.io/packages/pymakr). Now you are ready to start programming your device and send data to the platform. ### Putting everything together #### Circut diagram ![](https://i.imgur.com/o7662NY.jpg) #### Calculations These are the calculations for the different sensors used in this project. ##### Temperature sensor In the datasheet we find the temperature calculations for our sensor MCP-9700, this is the formula Temperature=(Readvoltage-Voc)/Tc In the datasheet we the values for our specific sensor. Voc = 500 mV (voltage read at 0 degrees celcius) Tc = 10 mV/C (temperature coefficient) datasheet found at: https://www.microchip.com/wwwproducts/en/en022289 ##### Light sensor When measuring the light at complete darkness the photoresistor has a resistance of over 1 million ohms, this means that when we voltage divide we will get a value of aproximatly 0. At 10 Lux our photoresistor has a resistance of 2-5 kohms, this means that the output is somewhere between 65mV to 157 mV. If we approximate the resistance to 5000 ohms at 10 Lux the output voltage is 157mV. From that we can approximate that the output increases witch 15.7mV per Lux increased. We can use that information to approximate how bright it is. Lux = measuerd voltage/light coefficent The light coefficient is 15.7mV in this case. (the other resistor used is 100 ohms) datasheet found at: https://www.electrokit.com/produkt/fotomotstand-cds-2-5-kohm/ ### Platform The platform used in this project is the pybytes platform. This platform is used because coding your lopy_4 device with the pybytes library is easy and beginner-friendly. It is also easy to add more devices to this platform and send the data to other places with integrations. Other platforms that may be worth looking in to. It may be worth looking in to sending your data to the ttn platform, though lora is not available in a lot of places and is therefore not used in this project. ### Code Code is found at: https://github.com/delavaux/Light-and-temperature-sensing-with-micropython ### Transmitting data I have chosen to send data every 60 seconds. This is because it takes time for the temperature and light to changes making it unnecessary to collect data more often. In this project data is sent via wifi and MQTT to the pybytes platform. If you decide on not using wifi to send your data you have to be more careful on how much data you send and how often because som protocols have longer range but slower transfer rate i.e LoRa. ### Presenting data The data is presented on the pybytes platform in the form of diagrams. The data is sent to the platform every 60 seconds, and the diagrams show the data from the latest 12 hours. ![](https://i.imgur.com/qzz37Y9.png) ### Finalizing the design I decided to put my design in a small compact package that I can put anywhere in my apartment. ![](https://i.imgur.com/2jQh6ax.jpg) This is the data collected from the window sill on the kitchen. ![](https://i.imgur.com/Z9q2W3a.png) The temperature data mostly gives temperatures between 22-29 degrees celsius, but as we can see some time between 7 and 8 am the temperature rose a lot. That may be because the sun shined directly on it. ![](https://i.imgur.com/WKCdWtm.png) The light data follows the sunrise and sunset, it also has the same anomaly as the temperature data between 7 and 8 am. And the reason may be the same in that case. #### improvments to be made In my case i did not have the possibility to use LoRa because it is not available in my area. If LoRa is available for you it may be preferable to use LoRa, but if you use LoRa you have to be careful and manage the data you send so that you don“t send to big packages.