---
# System prepended metadata

title: Tutorial on how to connect a temperature and humidity sensor

---

# Tutorial on how to connect a temperature and humidity sensor
Created by: Stefan Gustavsson, Userid: sg223bx
Email: stefan.vk.gustavsson@gmail.com
Course: 1dt305-tillämpad-iot

## Project Overview
Since I am a beginner in this field I just wanted to create an easy project to get me started. I chose to connect a temperature and humidity sensor to Pybytes and to present the result in a dashboard.
As a beginner it took me a lot of time to get this simple task up and running, but if you are more experienced I think it will take about 2 hours.

## Objectives
I am a beginner and I chose this project with the main goal to learn more about the basics in IoT. I wanted to create a project that was rather easy to get me started.
I am also a beginner in most of the programs/systems we use in the course (Atom, HackMD, Python, Pybytes) so it was a lot of stuff to get in order just to create this simple task.
But now I know a lot more than in the beginning so my next project will be quicker to set up.
I want to get the signal from my temp/HR sensor (DHT11) every five seconds into the Pybytes dashboard and present it in a chart. I also want to show the location of the device.
This project will help me understand the basic technics about IoT, both hardware and software. I have learned a lot about software I have not used before.

## Material
I bought a starter kit from Electrokit for 995 SEK and one temperature and Humidity sensor DHT11 from Kjell & Company for 50 SEK.
I did not use all the stuff in the starter kit so below I will try to estimate the cost for the material I needed.
I used the LoPy built-in WiFi-antenna. I did not use any batterypack.



| Device               | Purpose                          | Cost  |
| -------------------- | -------------------------------- | ----- |
| Pycom LoPy4          | Processor and WiFi antenna                        | 400SEK  |
| Temp/HR sensor DHT11 | Measure temperaure and humidity  | 50SEK |
| USB-cable            | Connect the computer to LoPy4    | 39SEK |
| Cables               | Connect between bread board and LoPy4  | 1SEK  |
| Bread board          |  Makes the connection easier       |   59SEK    |
| Expansion board      | Makes it easier to connect LoPy4 | 50SEK  |
  
I have chosen to work with the Pycom LoPy4 device as seen below, it’s cheap and can be programmed by MicroPython and has a build in WiFi-antenna. Lopy4 has many digital and analog input and outputs and is well supported and there are many online examples how to use it.

![](https://i.imgur.com/wr6O1Qv.jpg)

The Temperatur and Humaidity sensor I chose is cheap and also have many online examples and it is easy to find support if I have any questions (since I am a beginner).
The DHT11 has a range between 0-60 degrees C and 20-90% RH and this is perfect for my purpose.
DHT11’s power supply is 3-5.5V DC.

![](https://i.imgur.com/anZk1GX.jpg)

The Bread board is not necessary but makes it easier to connect the cables an I yhink it is easier to get an overview of what I am doing.

![](https://i.imgur.com/vZORDO6.jpg)


## Computer setup
I chose to install Atom since this is a common tool for IoT and fairly easy.
Imported the DHT11-22 project to Atom.
Installed Node.js
Connection to the LoPy4 via USB connection cable.
LoPy4 sends data to pybytes cloud platform via WiFi. I used the LoPy built-in WiFi antenna and the WiFi network at my home.
I created an account in pybytes in order to use pybytes cloud platform to collect the data.



## Putting everything together
This setup is only for development and education and should not be used in production.
I connected the LoPy4 to an expansionboard to make it easier to connect to the sensor.
Connection between computer and LoPy4 expansionboard via USB-cable.
I connected the DHT11 temp/RH-sensor to a breadboard because it makes it easier to connect the wires. 
DHT11 GND to GND on LoPy4 expansionboard (white wire IRL, black wire in picture below).
DHT11 Power to 3,3V on LoPy4 expansionboard (orange wire)
DHT11 Data to Pin23 on Lopy4 expansionboard (blue wire)
![](https://i.imgur.com/zznVXi5.jpg)
![](https://i.imgur.com/7qQe0NF.jpg)


## Platform
I chose the pybytes cloud platform for this project. It is easy to use and it is free of charge. The platform has the basic functionality I need, for example dashboard, charts and device location via Google maps.
It is possible to connect to more advanced cloud platforms (eg Google, AWS or Azure) if this should be necessary in the future.

## The code
I have been using the example code for most of the connection. During the project I have tried to make some changes to see what happens.
![](https://i.imgur.com/LTYz15w.png)




## Transmitting the data / connectivity
The data is sent every five seconds. 
LoPy4 sends data to pybytes cloud platform via WiFi. I used the LoPy built-in WiFi antenna and the WiFi network at my home.
I created an account in pybytes in order to use pybytes cloud platform to collect the data.
I am using MQTT as the transport protocol.


## Presenting the data

![](https://i.imgur.com/4rDQ8yn.jpg)
![](https://i.imgur.com/Do8HyvH.jpg)
![](https://i.imgur.com/ATlN6Ob.jpg)
![](https://i.imgur.com/K4xGd0j.jpg)





## Finalizing the design

I have learned a lot about IoT, Python, Atom and the technics behind it. I think this is a good start and introduction, but I realize there are A LOT more to learn in this topic.
I had some more complex project in mind at the beginning but realized that I had to keep it simple. I will be much faster up and running with my next project now when I have knowledge about the basic stuff.
I have a better understanding of the topic now and it will be easier to discuss and have an opinion about IoT after this course.
The introduction to 3D printing was very interesting and has increased my interest in this topic too.
Good that the lessons were recorded because I sometimes had to watch more than once :-)
![](https://i.imgur.com/JLdNtt9.jpg)





