Introduction
When we talk about top trending keywords in technology nowadays, we can't forget the "Internet of Things". With the development of the internet, IoT has to play an important role. That's why I'm going to write a small article about IoT. The simplest things we can start with is controlling lights via the Internet. In this article, I'll control LEDs on/off. From this start, you can control lights, fans, air-condition, etc, in your house. But with these AC appliances, you'll need relays to turn them on/off.
What is IoT?
The Internet of Things (IoT) is the network of physical devices, vehicles, home appliances, and other items embedded with electronics, software, sensors, actuators, and connectivity which enables these things to connect and exchange data, creating opportunities for more direct integration of the physical world into computer-based systems, resulting in efficiency improvements, economic benefits, and reduced human exertions. (Wikipedia)
As you know, we can't decline the important role of the IoT in our lives. It helps us in different industries. I believe that it'll have a great development in the future by your distribution.
How Does IoT Work?
An IoT system includes four components: sensors, connectivity, data processing and a user interface.
- Sensors: Sensors or devices will collect data from the environment. This could be humidity, temperature, gas sensors, GPS, etc.
- Connectivity: The data, after receiving from sensors, is sent to the cloud. To do that, we have a variety of methods, such as cellular, satellite, Wifi, Bluetooth, low-power wide-area networks (LPWAN) and so on.
- Data processing: Once the data gets to the cloud, software performs some kind of processing on it. It can check if the gas amount exceeds the limit.
- User interface: Finally, we'll control fans, know the value of gas in the house by using buttons, texts on the screen. It can be smart phone screen or websites or a notification via SMS. All of them are user interface. We interact with appliance by this interface.
Let's Make a Simple Project
Now, let's start our project. The first thing we should do is to prepare some components.
Wemos D1 Board
Firstly, we need something to connect devices (lights, fans, etc.) to the Internet and then we can control them from any place via the Internet. Obviously, a board that can connect the Wifi is required. One of them is Wemos D1. This board includes ESP8266 module and it's around $12. Let's see it on Amazon here.
On the left of this board is ESP 8266 Wifi chip. It's used to connect, receive and send data through Wifi. We use this chip to get access to Wifi in the house. Then, we'll send the controlling statement via Wifi to have control of all the devices. See the following datasheet:
* GND pin, also called LOW leg, we need to connect the cathode of devices to this pin.
* The pins D0 - D15 are the positive pins used to plug into the anode of the device. For example, to control LEDs, we need to plug the long leg of the LED into one of the positive poles. There are also other legs that you can find out more about, but in the basic device controlling, we just use these pins.
Wires
Obviously, we need wires to connect all devices together. There are 3 types of wires: male - male, female - female and male - female. You'll choose suitable wires for your project.
Breadboard
Breadboard is a component that can be used to check principle diagram and the connection of our devices to Wemos D1 easily. We'll put the leds, Wemos board and some wires on it. I'm going to explain how to use breadboard for someone who hasn't heard about it.
It's a hard thing that has a lot of holes on the surface. On two sides, it has red and blue lines to show where you should connect anode or cathode. But they're just the symbol, in fact, you don't need to follow them at all. There are also some numbers on it, 5 10 15 20, etc. It helps us easily see the order of each line of holes.
Let's see the following illustration.
The holes in the breadboard are connected with other ones in the same line. In the illustration, all holes in the same yellow, red or blue line are connected. It's likely a wire. You can put wires, LEDs' legs, sensors' pins into those holes.
Arduino IDE
'IDE' abbreviation stands for Integrated Development Environment. That is a software suite that consolidates the basic tools developers need to write and test software. Typically, it contains a code editor, a compiler and a debugger that the developer aaccesses through a single graphical user interface.
We use Arduino IDE to write and upload code to the Wemos D1 board. We can download it here.
App Blynk
It's an application used to control smart home via MQTT protocol without extra server installation. Blynk provides SDK for ESP 8266 module which we are using. What we need to do is add buttons to control appliances. Click here to install it on Android, or this on iOS. Assuming we are connecting a device at D0 port for which we want to have a control, we'll do a few easy steps on Blynk interface.
If we have four lights, we'll have a screen like this:
Make a Circuit
After having some basic knowledge of the diagram and components, let's start gathering them to complete our first simple IoT system. I'm using 4 leds to simulate for 4 appliances in the house. But in fact, in order to control AC appliances, we need relays as well.
Connect leds' anode to line 10, 15, 20 and 25. Anode of leds are the longer legs. And then connect them into D1 to D4 ports, respectively. For cathodes, we connect all of them to GND on Wemos D1. We use male-male wires for these connections.
Upload Code to Wemos D1
After making a circuit, the final thing we need to do is write some codes and upload them to Wemos D1. As I've said above, the community between hardware and the Internet can be performed via MQTT protocol. This protocol might be a little complicated for beginners, so we will use another solution for this problem, a third party that provides platform for hardware and the Internet, it's Blynk. Blynk supplies SDK directly for Arduino so that you just run it only and do nothing else. You can download Blynk library here. To add the library, go to Sketch -> Include library -> Add .ZIP library and choose the zip file you've just download above.
After installing SDK Blynk for Arduino, we go to the example section like this:
We have a small code below:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "YourAuthToken";
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}
What we'll do next is change some parameters:
YourAuthToken
: is the token that you registered Blynk. It will email you after successful register. YourNetworkName
: is your house's wifi address. It can be the address of your Wifi hotspot. YourPassword
: is the password of your Wifi.
Now, let's power the Wemos D1 by plugging it to the computer using USB port and enjoy our project.
Conclusion
This article aims to make an introduction about IoT for beginners. It's really basic and cheap.
Thank you dandy72, he reminded me one thing that I should tell you about IoT system. This is only an introduction about IoT, so if you find it interesting, you should learn more about the IoT features, especially the IoT's security. It's really dangerous for a system that cannot limit people to access. You can find more about it on the Internet. How about some keywords like "Security of IoT".
I hope that you can make more interesting things with this start. Thank you for reading!!!