Using DHT11 - RPi (Part 1)

16 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€67.10
List Price:  €95.86
You save:  €28.76
£55.67
List Price:  £79.54
You save:  £23.86
CA$100.49
List Price:  CA$143.56
You save:  CA$43.07
A$111.96
List Price:  A$159.95
You save:  A$47.99
S$94.87
List Price:  S$135.54
You save:  S$40.66
HK$544.16
List Price:  HK$777.41
You save:  HK$233.24
CHF 62.56
List Price:  CHF 89.37
You save:  CHF 26.81
NOK kr792.29
List Price:  NOK kr1,131.89
You save:  NOK kr339.60
DKK kr500.54
List Price:  DKK kr715.08
You save:  DKK kr214.54
NZ$123.74
List Price:  NZ$176.78
You save:  NZ$53.04
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,330.24
List Price:  ৳11,900.85
You save:  ৳3,570.61
₹5,945.56
List Price:  ₹8,494.03
You save:  ₹2,548.46
RM315.51
List Price:  RM450.75
You save:  RM135.24
₦108,149.19
List Price:  ₦154,505.46
You save:  ₦46,356.27
₨19,403.53
List Price:  ₨27,720.51
You save:  ₨8,316.98
฿2,393.75
List Price:  ฿3,419.79
You save:  ฿1,026.04
₺2,454.67
List Price:  ₺3,506.82
You save:  ₺1,052.15
B$425.95
List Price:  B$608.53
You save:  B$182.58
R1,282.09
List Price:  R1,831.63
You save:  R549.54
Лв131.15
List Price:  Лв187.37
You save:  Лв56.21
₩101,234.93
List Price:  ₩144,627.53
You save:  ₩43,392.60
₪254.67
List Price:  ₪363.83
You save:  ₪109.16
₱4,117.86
List Price:  ₱5,882.91
You save:  ₱1,765.05
¥10,949.58
List Price:  ¥15,642.93
You save:  ¥4,693.35
MX$1,405.49
List Price:  MX$2,007.92
You save:  MX$602.43
QR254.12
List Price:  QR363.05
You save:  QR108.92
P963.49
List Price:  P1,376.48
You save:  P412.98
KSh8,999.72
List Price:  KSh12,857.29
You save:  KSh3,857.57
E£3,561.31
List Price:  E£5,087.81
You save:  E£1,526.49
ብር8,689.79
List Price:  ብር12,414.52
You save:  ብር3,724.72
Kz64,250.82
List Price:  Kz91,790.82
You save:  Kz27,540
CLP$69,143.42
List Price:  CLP$98,780.55
You save:  CLP$29,637.13
CN¥510.67
List Price:  CN¥729.56
You save:  CN¥218.89
RD$4,244.94
List Price:  RD$6,064.47
You save:  RD$1,819.52
DA9,440.04
List Price:  DA13,486.35
You save:  DA4,046.31
FJ$162.13
List Price:  FJ$231.62
You save:  FJ$69.49
Q537.12
List Price:  Q767.35
You save:  Q230.22
GY$14,584.29
List Price:  GY$20,835.60
You save:  GY$6,251.30
ISK kr9,693.35
List Price:  ISK kr13,848.23
You save:  ISK kr4,154.88
DH701.59
List Price:  DH1,002.31
You save:  DH300.72
L1,285.64
List Price:  L1,836.70
You save:  L551.06
ден4,127.89
List Price:  ден5,897.23
You save:  ден1,769.34
MOP$558.06
List Price:  MOP$797.27
You save:  MOP$239.20
N$1,283.39
List Price:  N$1,833.49
You save:  N$550.10
C$2,565.21
List Price:  C$3,664.75
You save:  C$1,099.53
रु9,482.30
List Price:  रु13,546.73
You save:  रु4,064.42
S/259.58
List Price:  S/370.84
You save:  S/111.26
K282.68
List Price:  K403.85
You save:  K121.16
SAR262.90
List Price:  SAR375.59
You save:  SAR112.68
ZK1,929.21
List Price:  ZK2,756.13
You save:  ZK826.92
L333.95
List Price:  L477.10
You save:  L143.14
Kč1,686.22
List Price:  Kč2,408.98
You save:  Kč722.76
Ft27,781.83
List Price:  Ft39,690.03
You save:  Ft11,908.20
SEK kr772.17
List Price:  SEK kr1,103.14
You save:  SEK kr330.97
ARS$71,242.69
List Price:  ARS$101,779.64
You save:  ARS$30,536.94
Bs481.71
List Price:  Bs688.19
You save:  Bs206.47
COP$305,135.87
List Price:  COP$435,927.07
You save:  COP$130,791.20
₡35,171.10
List Price:  ₡50,246.58
You save:  ₡15,075.48
L1,769.55
List Price:  L2,528.04
You save:  L758.48
₲543,563.42
List Price:  ₲776,552.46
You save:  ₲232,989.03
$U3,109.25
List Price:  $U4,441.97
You save:  $U1,332.72
zł286.15
List Price:  zł408.81
You save:  zł122.65
Already have an account? Log In

Transcript

Video 4.3 using DHT 11 Raspberry Pi, part one. In this video, we will learn how to connect the HD 11 and use its data in Node red. I will take it that you know basic electronics, so I won't be explaining much. If you're not familiar with basic electronics, I have given a link in the resources for you to get up and going with electronic projects. I also have given the circuit diagram for this video in the resources. First what is DHT 11 DHT 11 is a basic ultra low cost temperature and humidity sensor.

It has a capacitive humidity sensor and a thermistor to measure humidity and temperature values from the surrounding air. It has a very basic chip that does some analog to digital version two output digital data on the data pin. Good for us, we can connect it directly to our PI. It has two other pins Vcc and ground. You can provide supply voltage from three volts to five volts. To know more about the HD 11 check the resources.

Another question of all the sensors out there by the HD 11 It is a very basic and easy to use sensor and therefore we will start our project using the HD 11. The DHT 11 will be interfaced with raspberry pi and the data from the HD 11 will be accessed by the node red running on Raspberry Pi. I'm using a Raspberry Pi three running on Raspbian stretch. You can use Jesse or stretch let's see how it goes. have been ordered to run on both in my raspberry pi. So I just use the URL to access the note rate editor.

Now we can get values from this sensor using the RPI GPIO nodes from the palette. RPI GPIO Yes, we saw them while scrolling the palette in video 2.4. There are two nodes input and output. These nodes are installed by default when we updated node j, s and Audrey using the bash command. These notes are used to interact with the GPIO pins of the Raspberry Pi using the PI GPIO daemon. Nice right.

There are even nodes to get inputs from peripherals like keyboard and mouse connected to your Raspberry Pi. Now let's test these nodes with an LED and a button. This is the 40 pin GPIO pin diagram. First, let's connect the common ground. Connect your led to GPIO four, that is the seventh pin and your button to GPIO 17 which is the 11th pin like shown in the diagram. Note that I'm using a pulldown circuit.

So whenever I press the button I'll send a value one to the 11th pin. Now let's configure these nodes so that whenever I press the button, the LED should blow. The input node should be configured with the pin the button is connected to that is GPIO 17. You can also set an internal pull up or pulldown resistor to set initial values. You can also let note rate treat the initial state during deployment. This node outputs a message dot payload And the output node should be configured to GPIO for the pin where the LED is connected to.

Here, you can select the mode of output digital, or pw M and also initialize the state of the pin. This node accepts message dot payload. Now join these both and deploy. Now, play time. Okay, let's stop here. Now that we've seen how these work, let's connect DHT 11 and use a debug node to see what its outputs.

Let's connect this we're going to connect the data pane here on GPIO four, or the seventh pin Vcc is five volts and ground to ground. Now let's modify the input node. Delete the output node and add a debug node, deploy and check. Are you getting what I'm getting? Why does it show just one because the DHT 11 output serial data, the output given out by the data pin will be in the order of eight bit of humidity integer data, plus eight bit of humidity decimal data, plus eight bit of temperature integer data, plus eight bit of fractional temperature data plus eight bit parity. To request the DHD 11 module to send these data, the input output pin has to be momentarily made low.

And then Hello, hi. Oh, so how are we going to get the sensor data We'll find a way. First, let's print the sensor data on the terminal by running a Python program. If you're thinking, but I don't know how to write a Python code, forgetting the hedge t 11 sensor data. For that, I have to go through the data sheets and spend a lot of time, then don't worry, we have libraries for the HDx 11. We will first install the add a fruit library for the HD 11 which will take care of all those complexities and display its data.

I have given the list of commands to download the library in the resources. First, let's do an update and install a Python library which acts as a dependency for the one we're going to install to install it if you've not already installed it before. Python dash dev is the package that contains the header files for the Python c API. Then we need to clone the Adafruit library from the GitHub repo using this command, after which you need to install the library for Python two and Python three. That's it. Now let's check out the example program present in the examples folder.

Let's select simple test.py Wait, let me clear the screen. Let us see what's inside simple test.py. We are importing the module here. Then we are setting up the sensor type which is the HD 11 and GPIO pin number. We have to comment the first one because they have given that for BeagleBone boards. This is for Raspberry Pi boards.

Now we've connected our DHD 11 at seventh pin GPIO four, so change 23 to four. Then we're getting the humidity and temperature values from this default function after which we are formatting it in a nice way to present. Now let's save and run this. There you go. Temperature and Humidity data. Good.

But how are we supposed to make this data available in Node read? Well, there is a way it is by using the exec node. It can be found under Advanced category in the palette. The exec node is used to run a system command and output its STD out STD error and return code. By default, the node uses exec which calls the command blocks while waiting for completion and then returns the complete result in one go along with any errors. That is, it replaces the current running process with the new process and returns its output.

To know more about exact function, check out the resources. Remember the command which we use to run the DHD 11 program, we are going to use the same command here you can append the payload to the executed command. You can also add extra input parameters, the output can be got in two modes. One is the exec mode, where the output is shown only after the whole program finishes execution and the other one is spawn mode, where the output is shown during the execution of the program. Check out the flow and the Python program in the resources which shows the difference between these two modes. You can also add a timeout To kill the program automatically after the specified number of seconds.

To know more about the exact node, please see the node help on the sidebar. Now I have one more thing to do. I want to modify the output format a little bit. You'll understand why soon done. Now let's add an inject node with interval of five seconds and a debug node to the STD output of the exec node, because we only need the output data. Now deploy.

Yeah, it's working. I wanted it this way, because now we can take the number alone and use it for further processing. Now I want you to send a tweet if the value of temperature goes above 25 degrees centigrade if the value of humidity goes below 10% you will send a mail. If both happen at the same time, then you will send data to your Android using mq TT node. I know first try out the first two tasks, and then we will come to mq TT. So how did it go?

Did it work? Good if it worked, rewatch the videos from section three. If it doesn't work, you all should look like mine. Note that I have removed the units from the print statement in the Python program to get the numbers separately and use it for processing easily. You can find this flow in the resources. Now let's come to the third task.

Mq TT ring any bells? Maybe not. I'll explain. mq TT stands for message queuing telemetry transport. It is a protocol from this we can understand that it is a kind of messaging protocol like the one that Facebook uses. Facebook uses mq TT.

Yes it does. The publish subscribe form of trend came from that. Actually, mq TT uses publish subscribe message types to communicate. In mq TT. There'll be a broker and lots of clients all in the same network. Any client can publish a message under topic, the Publish message reaches the broker.

The other clients who have subscribed to this particular topic will get the message from the broker. All right, look out for the link in the resources to learn some concepts like retain QoS and different types of messages. So why am I telling you to use mq TT can use HTTP itself right? Check out the resources section to know why. So mq TT is what we're going to use now. There are two mq TT nodes input to subscribe and output to publish.

Now let's try an example. First, we can try sending a message from one workspace to another using mq TT nodes. I'm using an inject node to define the data to which we will attach the Publish node. So let's configure this a new broker configuration. Add a broker name. Enter the server address as your Raspberry Pi address.

If you have an mq TT broker running on your Raspberry Pi, or you can use the public mq TT broker provided by hive mq using the broker address broker dot hive mq dot com. If you want to know how to set up an mq TT broker in your PI, then look for a link in the resources. If you want, you can give some client ID check out for a link in the resources to know why we use client ID. You can add your credentials for extra layer of security. These fields are optional. If you have gone through the resource, then you will know what these are.

You can make this true if you want to retain your message and choose the Q or s appropriately for your application. I'm going to set my topic in inject node to let have it as time and pass the timestamp as message. Now add a subscribe mq TT node. Here. The configured option will be automatically available. Set the topic field and QoS you can choose the The type of output you want, then connect a debug node and deploy.

Let's try super. Now let's step up a notch. Let's try controlling an LED with a button using mq TT. For that, we need to connect the GPIO in node to mq TT out node and mq TT in node to GPIO output node. Pause the video and configure accordingly. Something like this.

Good. Now let's deploy and test it out. Give me a five. Awesome. Now we have to complete that last task. We'll do that along with some other cool stuff in the next lecture.

In this video, we learned about how to connect the HD 11 to node grid, and how we can get its data into node red. In the next video, we'll finish this pending task and see how does dashboard work on your Android

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.