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
€65.14
List Price:  €93.07
You save:  €27.92
£55.73
List Price:  £79.62
You save:  £23.88
CA$95.61
List Price:  CA$136.60
You save:  CA$40.98
A$106.30
List Price:  A$151.87
You save:  A$45.56
S$94.64
List Price:  S$135.20
You save:  S$40.56
HK$546.91
List Price:  HK$781.33
You save:  HK$234.42
CHF 63.50
List Price:  CHF 90.72
You save:  CHF 27.21
NOK kr764.69
List Price:  NOK kr1,092.46
You save:  NOK kr327.77
DKK kr485.92
List Price:  DKK kr694.20
You save:  DKK kr208.28
NZ$117
List Price:  NZ$167.15
You save:  NZ$50.15
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,661.98
List Price:  ৳10,946.16
You save:  ৳3,284.17
₹5,839.65
List Price:  ₹8,342.71
You save:  ₹2,503.06
RM331.75
List Price:  RM473.95
You save:  RM142.20
₦86,437.65
List Price:  ₦123,487.65
You save:  ₦37,050
₨19,492.21
List Price:  ₨27,847.21
You save:  ₨8,355
฿2,575.56
List Price:  ฿3,679.53
You save:  ฿1,103.97
₺2,262.43
List Price:  ₺3,232.18
You save:  ₺969.75
B$357.76
List Price:  B$511.10
You save:  B$153.34
R1,296.01
List Price:  R1,851.52
You save:  R555.51
Лв127.38
List Price:  Лв181.98
You save:  Лв54.60
₩95,113.23
List Price:  ₩135,881.87
You save:  ₩40,768.63
₪260.11
List Price:  ₪371.60
You save:  ₪111.49
₱3,999.61
List Price:  ₱5,713.97
You save:  ₱1,714.36
¥10,715.43
List Price:  ¥15,308.41
You save:  ¥4,592.98
MX$1,185.45
List Price:  MX$1,693.57
You save:  MX$508.12
QR254.79
List Price:  QR364.01
You save:  QR109.21
P955.69
List Price:  P1,365.33
You save:  P409.64
KSh9,427.65
List Price:  KSh13,468.65
You save:  KSh4,041
E£3,355.67
List Price:  E£4,794.02
You save:  E£1,438.35
ብር3,989.43
List Price:  ብር5,699.43
You save:  ብር1,710
Kz58,616.62
List Price:  Kz83,741.62
You save:  Kz25,125
CLP$66,326.02
List Price:  CLP$94,755.52
You save:  CLP$28,429.50
CN¥506.51
List Price:  CN¥723.62
You save:  CN¥217.11
RD$4,049.59
List Price:  RD$5,785.38
You save:  RD$1,735.78
DA9,420.19
List Price:  DA13,457.99
You save:  DA4,037.80
FJ$157.70
List Price:  FJ$225.30
You save:  FJ$67.59
Q542.62
List Price:  Q775.21
You save:  Q232.58
GY$14,613.08
List Price:  GY$20,876.73
You save:  GY$6,263.64
ISK kr9,792.30
List Price:  ISK kr13,989.60
You save:  ISK kr4,197.30
DH706.05
List Price:  DH1,008.69
You save:  DH302.63
L1,239.86
List Price:  L1,771.31
You save:  L531.44
ден4,010.92
List Price:  ден5,730.13
You save:  ден1,719.21
MOP$562.15
List Price:  MOP$803.11
You save:  MOP$240.95
N$1,302.54
List Price:  N$1,860.85
You save:  N$558.31
C$2,571.43
List Price:  C$3,673.63
You save:  C$1,102.20
रु9,317.58
List Price:  रु13,311.40
You save:  रु3,993.82
S/262.81
List Price:  S/375.46
You save:  S/112.65
K268.53
List Price:  K383.63
You save:  K115.10
SAR262.51
List Price:  SAR375.03
You save:  SAR112.52
ZK1,879.71
List Price:  ZK2,685.42
You save:  ZK805.70
L324.19
List Price:  L463.14
You save:  L138.95
Kč1,629.65
List Price:  Kč2,328.17
You save:  Kč698.52
Ft25,373.17
List Price:  Ft36,248.95
You save:  Ft10,875.77
SEK kr758.75
List Price:  SEK kr1,083.98
You save:  SEK kr325.22
ARS$61,468.94
List Price:  ARS$87,816.53
You save:  ARS$26,347.59
Bs482.36
List Price:  Bs689.12
You save:  Bs206.75
COP$272,946.91
List Price:  COP$389,940.87
You save:  COP$116,993.96
₡35,623.88
List Price:  ₡50,893.45
You save:  ₡15,269.56
L1,732.95
List Price:  L2,475.75
You save:  L742.80
₲523,151.84
List Price:  ₲747,391.81
You save:  ₲224,239.96
$U2,683.09
List Price:  $U3,833.15
You save:  $U1,150.06
zł281.85
List Price:  zł402.67
You save:  zł120.81
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.