3.8 IoT and Adafruit.io
Learning Objectives:
After this lesson, students can
- understand the basic principles of IoT and MQTT;
- use control Wemos D1 by Adafruit.io.
1. INTRODUCTION OF IoT & MQTT
A. IoT
The Internet of Things is a concept that refers to a digital interconnection of objects everyday with the Internet. It is indefinitely the connection of Internet with more objects than with people.
B. MQTT
MQTT It is a protocol used for communication machine-to-machine (M2M) on the "Internet of Things ".
It is oriented to the communication of sensors, consumes very little bandwidth and can be used in most devices with few resources.
It follows a star topology, with a node central that acts as a server or "broker", in charge of managing the network and transmitting the messages.
Communication is based on "topics", that the client who publishes the message creates and the nodes that want to receive it must subscribe to it.

Some free MQTT brokers
2. ADAFRUIT.IO
https://io.adafruit.com
Adafruit IO claims itself that it is the easiest way to get your projects onto the Internet of Things! Do you agree?
3. CLASSWORK
ArduinoBlocks have tools to communicate with the following MQTT brokers:
- Any MQTT brokers
- Adafruit (broker: io.adafruit.com)
- Thingspeak (broker: mqtt.thingspeak.com)
- Blynk
We are going to learn how to use ArduinoBlocks to connect to Adafruit IO.
1. Sign up an Adafruit IO account
https://accounts.adafruit.com/users/sign_up
You are suggested to use your school email to sign up.
2. Sign in
http://io.adafruit.com/api/v2/sign_in
3. Get your AIO Key
- Click "My Key"
- You can see your Username and Active Key
These two values will be copied into the codes in ArduinoBlocks.
Example

4a. Create New Group
4b. Create New New Feed
https://io.adafruit.com/(username)/feeds
- Click Feeds >"view all"
- Add a new group
- In the new group, add a new feed
- To change the feed name and key, click the feed and go to "Feed Info".
The feed key will be copied into the codes in ArduinoBlocks.
Remark: if your feed is in a group, the feed key should also include the group name. (e.g. groupname.feedname) You can get it in the feeds table.
5. Create New Dashboard
https://io.adafruit.com/(username)/dashboards
- Click Dashboards > "view all"
- Add a new dashboard
- In this new dashboard, click "Create New Blocks" to add appropriate controls, e.g. Toggle, Stream, Slider, ...

ArduinoBlocks Program Example:
AIO Username: ngkinkeung
AIO Key: aio_VYPW95ra7URda9FCtJ2WTraSGLRN
Group Name: ltpss-random
Feed Name: randomnumber
Feed Key: ltpss-random.randomnumber
The above program is to make Wemos D1 board to send a random number ranging from 1 to 10 to Adafruit IO every 3 seconds.
Classwork 3.8.1 (10 marks):
Write the above program to send data to your Adafruit IO dashboard.
PROJECT CODE For Group 2:
gAqPKW66
Challenge: Flash the on-board LED to indicate the data has been published.