fbpx
Magicblocks Lesson 20:  Temperature and Humidity Sensor
Magicblocks Project

Lesson 20: Temperature and Humidity Sensor [Magicblocks]

Use the DHT11 Sensor on the Magicbit using Magicblocks

Components Required

Story

 

Hello and Welcome, This tutorial will teach you to use a DHT11 Sensor with a Magicbit using Magicblocks. We will be measuring temperature and humidity using the Magicbit and displaying the output in the dashboard.

First, log into your Magicblocks account,

Magicblocks is easy visual programming software for the program of your Magicbit. Anyone can program their microcontroller by using magicblocks.io and there is no need for programming knowledge. You can sign up for free.

Start and Open the Playground.

Next, make sure your Magicbit is connected to the internet and plugged in, and also linked to your account through Device Manager.

All Done? Great! Now let’s find out the theory behind the DHT11 sensor.

 

Theory

The DHT11 detects water vapor by measuring the electrical resistance between two electrodes. The humidity-sensing component is a moisture-holding substrate with electrodes applied to the surface. When water vapor is absorbed by the substrate, ions are released by the substrate, which increases the conductivity between the electrodes. The change in resistance between the two electrodes is proportional to the relative humidity. Higher relative humidity decreases the resistance between the electrodes, while lower relative humidity increases the resistance between the electrodes. The DHT11 measures temperature with a surface-mounted NTC temperature sensor (thermistor) built into the unit.

 

Now let’s follow these steps to build the Temperature and Humidity Monitor.

 

Set up the DHT11 Block and inject node

 

1. Drag & Drop the  DHT11 block from the Magicbit nodes section to the flow.

 

 

2. Configure the inject node to inject repeatedly as follows.

3. Drag & Drop the  DHT11 block from the Magicbit nodes section to the flow.

 

4. In this tutorial, we will be plugging the DHT11 sensor to pin 33.

 

 

5. Configure the DHT11 block as follows by selecting the Device ID and Pin.

 

Set up the template blocks

 

6. Drag and drop two template nodes into the flow. We will be using these to format the message coming from the DHT11 block.

 

7. Configure the first template block as follows. Here we extract the temperature reading and add the unit ( °C ).

 

 

8. Configure the second template block as follows. Here we extract the humidity reading and add the unit ( % ).

 

 

Set up the text blocks for the dashboard

 

9. Add two text blocks into the flow and connect them as follows.

 

10. Configure the labels of the text blocks as follows, also create a new group in the dashboard as you have learned in the dashboard lesson to place these text elements.

 

 

Deploying the blocks

 

11. Finally, Deploy the blocks and open the dashboard using the icon shown.

 

 

12. Your dashboard should look like this, now you can measure the temperature and humidity anywhere using Magicbit!

 

 

 

[Optional] Import Already Setup Nodes

If you had trouble setting up nodes, you can use the import feature in Magicblocks to get the nodes that have already been set up.

  • First, copy this code to your clipboard;
[{"id":"8f8afc31.bb46e","type":"ui_text","z":"25961db4.e22d02","group":"a24f1d37.70871","order":0,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":660,"y":140,"wires":[]},{"id":"d00ac608.24d278","type":"DHT","z":"25961db4.e22d02","name":"","epId":"id3359-1673348308190","pin":"33","mode":"TH","x":290,"y":200,"wires":[["809ea92b.fe42d8","fa326ed3.30715"]]},{"id":"9db0ae57.7e114","type":"inject","z":"25961db4.e22d02","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":200,"wires":[["d00ac608.24d278"]]},{"id":"809ea92b.fe42d8","type":"template","z":"25961db4.e22d02","name":"temprature ","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.temprature}} °C","output":"str","x":470,"y":140,"wires":[["8f8afc31.bb46e"]]},{"id":"fa326ed3.30715","type":"template","z":"25961db4.e22d02","name":"humidity ","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.humidity}} °C","output":"str","x":460,"y":260,"wires":[["b1aaab7b.543d18"]]},{"id":"b1aaab7b.543d18","type":"ui_text","z":"25961db4.e22d02","order":0,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":640,"y":260,"wires":[]},{"id":"a24f1d37.70871","type":"ui_group","name":"Group 1","tab":"f1a4f840.46d658","order":1,"disp":true,"width":6},{"id":"f1a4f840.46d658","type":"ui_tab","name":"Tab 1","icon":"dashboard","order":1}]
  • Click on the options menu on the top right-hand corner of the screen.

 

  • Next, hover your cursor over the Import sub-menu.

 

  • Then click on Clipboard and paste the code on your clipboard to the text field.
  • Select current flow or new flow and click on Import.

IMPORTANT

Make sure you type your device ID on the Digital In node properties and choose the PIN to which your Motion Sensor is connected.

 

Troubleshooting

  • Check whether your Magicbit is connected to the internet.
  • Check whether the DHT11 is connected correctly and the correct PIN is used (PIN 33).

If you need help or couldn’t understand a step, be sure to check out our YouTube video by clicking here: Youtube Video

Related Posts
Leave a Reply