UnLight up Life With Easy IoT titled | IoT Cloud Kit for microbit-MakeCode-Tutorial

0 1900 Medium

Lesson 4: Light up Life With Easy IoT

Objectives

1. Introduce Easy IoT

2. Learn MQTT communication protocol.

3. How is remote control realized?

4. How to use Easy IoT platform to control IoT cloud kit?

Learning Process

Preparation

Teachers: computer/smartphone, good network, IoT cloud kit.

Students: computer/smartphone, good network, IoT cloud kit.

Learning Content

Lead-in: Why smart home gets popular in recent years? In the past, mechanical switches were used, but later they were replaced by touch panel switches. These switches don’t feel good to use, because, for instance, before going to bed at night, you have to check whether the lights are off in each room. But now when smart home devices are used, you only need to lie in bed at night and use the terminal to control the switches, sockets, electrical appliances and other equipment in every room. So next, we are going to learn how to remotely control devices through the IoT platform.

Introduction of Easy IoT

In the previous lesson, we talked about using ThingSpeak to collect data. In this lesson, we mainly talk about using the IoT platform to remotely control devices.

Question: How are smart home devices remotely controlled?

What is ThingSpeak

Easy IoT is an IoT platform independently built by DFRobot. After successful sign-up, it takes 10 minutes to get started, connect and play. It can monitor data online in real time, and then analyze data changes through graphs; the advantage of Easy IoT is that in addition to online data collection and analysis, it can also send commands to control device. It also provides solutions to projects that require remote control.

Communication protocol used in Easy IoT

In the previous lesson, we said that in order to receive messages from the server of the IoT, a communication protocol must be prepared in advance. The communication protocol used in Easy IoT is MQTT protocol.

MQTT Protocol

MQTT (MQ Telemetry Transport, message queue telemetry transmission) is a new type of protocol that has emerged in recent years, it is used as a standard protocol in IoT.

MQTT is a protocol that enables single-multiple communication (people call it to publish or subscribe). It consists of three functions, namely broker, publisher and subscriber. As shown below.

As can be seen from the above figure, the publisher is the client terminal responsible for sending messages, and the subscriber is the client terminal responsible for receiving messages.

Publish and subscribe

First, the broker is waiting for the publisher and subscriber to connect to it. Subscribers connect to the broker and tell the broker the name of the topic they want to subscribe to. This is a subscription. Then the publishers connect to the broker and send a message with the subject as the recipient address. This is publishing.

After the publishers publish the topic, the broker will deliver the message to the subscribers who subscribed to the topic. If the subscriber subscribes to topic A, then only if the publisher publishes topic A, the broker will deliver the message to the subscriber. The subscriber and the broker are always connected, and the publisher only needs to establish a connection when publishing, but it needs to remain connected when publishing several times in a short period of time.

Note: The messages exchanged by MQTT are accompanied by a "topic" address, and each client regards this "topic" as the receiving address.

How to use Easy IoT

Sign up

1. Windows system browser access URL:https://iot.dfrobot.com/. Enter the homepage of Easy IoT. Click sign up to enter the page of sign up.

2. Fill in the information (email address, and name), then click Next.

3. After the sign-up is successful, sign in the account and enter the workplace, which is the interface for collecting device data. You need to add the topic of the new device to be able to pair it with your own device.

Easy IoT operations

After entering the workplace, we need to understand what are in the workplace

1. Introduction to IoT user accounts and passwords.

2. Learn Topic

3. Click “send msg”, then you can see the page of sending and receiving messages. The data received in the terminal can be used to draw a chart.

(Click “Check” , you can view the generated chart)

Working principle of remote control

Remote control is based on wireless communication technologies such as WIFI technology and Bluetooth technology. It connects smart homes and control systems, and realizes remote data transmission and wireless control of devices. Even in remote locations, you can easily manage devices, realize full automation, and make your life more intelligent.

Smart homes-Remote control

From the definition of remote control, it can be seen that remote control is actually based on the network and data. The user reads the status data of the device wirelessly through the mobile phone, and combines their actual needs with the help of wireless network to send commands to the wireless module (WiFi module/Bluetooth module) built into the home appliance to complete actions, such as turning on and off the smart air conditioner, adjusting the wind direction, temperature, and lock/unlock door.

Project Practice—Use Easy IoT to remotely control the device and collect data

Earlier we learned how to use ThingSpeak to collect data collected by sensors. In this lesson, we are going to learn how to use the IoT platform to realize the function of remotely control the fan. The tutorial mainly talks about sending "ON" and "OFF" commands through the Easy IoT platform to control the fan module, and then combined with wireless communication technology to realize the control of multiple fan modules.

Task1: Control single device by Easy IoT

Many smart home devices now are controlled by remote network. The control of home appliances is mainly operated through smart phones and external networks. So, in this section, we will learn how to use Easy IoT to control a fan.

Create workplace

First, we create a "Remote control" workplace in Easy IoT.

Confirm Topic

Because Easy IoT transmits data through the MQTT protocol, we must first confirm the Topic number you need to subscribe to.

Hardware Preparation

Because this project requires the IoT cloud kit, we need to prepare the hardware devices as shown in the figure below.

Hardware Connection

Insert the SD-WiFi card into the micro:IoT Board for Cloud, connect the DC fan to the P1 pin.

Program Design

Function analysis

This program is to send commands to control the on and off of the DC fan through Easy IoT. The steps are as follows:

Program flow chart
Sample Program

*Program link address: https://makecode.microbit.org/_MrUi1Vix48Vs

Note: Select server "Easy IOT_EN".

Operating Effect

When WiFi connection succeeded, the micro:bit LED matrix screen displays “√” and the message “Hi, DFRobot” will be sent to Topic_0. At the same time, the OLED screen shows “Hi, DFRobot”.

Send the command "ON" in the subscription account Topic_0. When the device receives the command, the fan rotates and the "Fan on" is displayed on the OLED; when the command "OFF" is sent, the fan turns off and the "Fan off" is displayed on the OLED.

Summary

In this sample, we learn to send commands to the device through Easy IoT, so as to realize the function of remote controlling of the device. And we also get known that the Easy IoT platform uses MQTT protocol. We only need to subscribe to Topic, and then we can send commands to control the device in the subscription account. So, we must remember what function each topic corresponds to. In this way, each device can be accurately controlled.

Question: Try to control different devices in the same topic. For example: Fan controls the fan, RGB controls the light.

Task2: Control multiple devices by Easy IoT

In the previous part, we learned how to send commands to control the fan through Easy IoT. At the same time, it also raised the question of controlling different devices in the same topic. Then, let's try how to use Easy IoT to control fans and RGB lights. First, we learn to use different commands to control two devices in one topic. Then, learn to control the fan and RGB lights separately in two topics.

1. Control two different devices in one topic

To control two different devices in the same topic, the most important thing is to confirm the commands. For example, the command "Fan_on" is used to turn on the fan, and the command "Fan_off" is used to turn off the fan. The commands for turning on and off the RGB lights need to be changed. For example, the function of "RGB_on" is to turn on the RGB lights, and the function of the command "RGB_off" is to turn off the RGB lights.

Hardware preparation and hardware connection

The hardware list and hardware connection steps are the same as controlling single device.

Program design

Function analysis

This project mainly uses Easy IoT to send different commands to control the DC motor fan and RGB lights to turn on and off. The program flow chart is as follows.

Program Flow Chart

Sample Program

Not finished, continue on the next page.

Program link:https://makecode.microbit.org/_Apw7xUCL7fub

Operating Effect

After successful networking, “√” will be displayed on the LED matrix screen. Then the message "Hi, DFRobot" will be sent to Topic_0. At the same time, "Hi, DFRobot" will be displayed on the OLED screen.

Send the command "Fan_on" in the subscription account Topic_0, the fan rotates, and "Fan on" is displayed on the OLED screen; send the command "Fan_off" to turn off the fan, and "Fan off" will be displayed on the screen.

If send the command "RGB_on" in the subscription account Topic_0, the RGB light will light up in orange, and the OLED screen will display "RGB on"; if send the command "RGB_off", the OLED screen will display "RGB off" and the RGB light will go out.

Question: Try subscribing to two different topics, and using the two topics to control the fan and RGB lights respectively.

2. Control two different devices in two Topic

To meet the requirements of controlling two different devices in two topics, the most important thing is to confirm the topic number and control command. For example, Topic_0 controls the fan; Topic_1 controls RGB lights. When sending the command "ON" into Topic_0, turn on the fan, and sending the command "OFF", turn off the fan. The controlling for the RGB lights is the same, except that the command is sent into Topic_1.

Create workplace

First, we create two workplaces in Easy IoT. As shown below:

Hardware Preparation and Connection

The hardware list and hardware connection steps are the same as controlling single device.

Program Design

Function analysis

The project is mainly to control the DC motor fan, and the turning on and off of the RGB lights through two Topic commands. The program flow chart is as follows.

Program Flow Chart

Sample Program

Program link: https://makecode.microbit.org/_adK0wa2ecgzL

Operating Effect

After successful networking, “√” will be displayed on the LED matrix screen. "Hi, DFRobot" will also be displayed on the OLED screen.

Send the command "ON" in the subscription account Topic_0, the fan will rotate, and "Fan on" will be displayed on the OLED; send the command "OFF" and the fan will turn off, and "Fan off" will be displayed on the OLED.

Send the command "ON" in the subscription account Topic_1 to turn on the RGB light, and "RGB on" will be displayed on the OLED; send the command "OFF" to turn off the RGB light, and "Fan off" will be displayed on the OLED.

Summary

In this sample, we used two methods to control multiple devices. First, we learned how to control different devices in the same topic. When using this method, we need to pay attention: different devices need to use different commands. Then we learned to subscribe to two different topics to control different devices. When using this method, we need to remember which device each topic represents.

Task3: Use Easy IoT to collect the temperature data in classroom

In the last lesson, we used ThingSpeak to collect the real-time temperature in the classroom. At the same time, we also learned the "visual analysis method" and the traditional "statistical analysis method". In fact, Easy IoT can also collect data. It displays data intuitively through a data list or through a chart.

Through the data list, we can clearly observe the temperature in each time period. The trend of the temperature during this period can be observed through the line chart. Next, we are going to use Easy IoT platform and DHT11 temperature and humidity sensor to collect temperature data in the classroom.

Create workplace

First, we create a "temperature" workplace in Easy IoT.

Hardware Preparation

Because this project requires the IoT cloud kit, we need to prepare the hardware devices as shown in the figure below.

Hardware Connection

Insert the SD-WiFi card into the micro:IoT Board for Cloud, connect the DHT11 temperature and humidity sensor to the P1 pin.

Program Design

Function analysis

This project is mainly to upload the temperature collected by the temperature and humidity sensor to the Topic in Easy IoT every 5 minutes. The specific program flow chart is as follows.

Program Flow Chart
Sample Program

Program link: https://makecode.microbit.org/_ahgKeR2pqCoc

Operating Effect

After successful networking, “√” will be displayed on the LED matrix screen. Then send a "Classroom temperature" message to Topic_0 (temperature). At the same time, the characters "temperature" and the currently detected temperature will also be displayed on the OLED.

Open Topic_0 (temperature) and click "view details" to view the temperature data collected every 5 minutes.

Note: Each topic in Easy IoT can only store up to 1000 pieces of data.

Summary

The Easy IoT platform can not only realize the function of remote control, but also collect data. In this way, we can make some projects about triggering feedback. For example, send a command to check soil humidity data through Easy IoT, and when the device receives the command, it returns the current soil moisture. We can also determine whether to turn on watering equipment based on the returned data.

Question: Can you combine the soil humidity sensor and the micro water pump in the kit to complete the idea above?

Discussion

Summary

In this class, we learned how to use Easy IoT to remotely control devices, which helped us solve the problem of people leaving but devices still running. After learning this lesson, we have already understood the use of three IoT platforms. The next project is to use these three IoT platforms to realize smart city-related projects.

License
All Rights
Reserved
licensBg
0