Click here to Skip to main content
15,609,332 members
Articles / Internet of Things / Arduino
Posted 29 Jul 2018


1 download
11 bookmarked

Internet of Things - Controlling Smart Home within $15, Why Not?

Rate me:
Please Sign up or sign in to vote.
3.30/5 (11 votes)
5 Aug 2018CPOL6 min read
In this article, I'll make an overview of IoT and introduce a way to approach IoT using Wemos D1.


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.

  1. Sensors: Sensors or devices will collect data from the environment. This could be humidity, temperature, gas sensors, GPS, etc.
  2. 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.
  3. 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.
  4. 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

Image 1

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:

Image 2

* 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.


Image 3

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.


Image 4

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.

Image 5

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

Image 6

'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

Image 7

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.

Image 8

If we have four lights, we'll have a screen like this:

Image 9

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.

Image 10Image 11

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:

Image 12

We have a small code below:

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

void setup()
  // Debug console

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

void loop()

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.


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!!!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer
Vietnam Vietnam
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

QuestionSecurity Pin
dandy7230-Jul-18 5:44
dandy7230-Jul-18 5:44 
AnswerRe: Security Pin
ron8526231-Jul-18 16:51
professionalron8526231-Jul-18 16:51 
GeneralRe: Security Pin
dandy721-Aug-18 7:20
dandy721-Aug-18 7:20 
GeneralRe: Security Pin
ron852622-Aug-18 5:04
professionalron852622-Aug-18 5:04 
GeneralRe: Security Pin
dandy722-Aug-18 7:31
dandy722-Aug-18 7:31 
QuestionHow Does IoT work.... Pin
Member 1393099130-Jul-18 3:06
Member 1393099130-Jul-18 3:06 
AnswerRe: How Does IoT work.... Pin
ron8526231-Jul-18 16:54
professionalron8526231-Jul-18 16:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.