IoT device in action

This second article in our series focusing on the Internet of Things covers on an IoT device and how it works in practice.

29th July 2016Blog

Are you ready to get in touch?

Request a Call back

Amit Kumar



Date: Friday 29th July

Author: Amit Kumar, Technology consultant


This is the second article of our three part series on the Internet-of-Things (IoT). In the first article we have talked about what IoT is, and what the future possibilities are for this technology. In this article we are going to get hands-on and make a connected IoT device.

What do we need?

Before we start making the device , we need a couple of things to make it work:

Azure subscription

This IoT device will be connected to Azure services so you will need an Azure Subscription and ID. If you don’t already have one you can sign up for a free trial with £125 credit.

ESP8266 Wireless Transceiver ModuleESP8266 Wireless Transceiver

We are going to use ESP8266 to connect with Azure Services. This is a tiny device, almost size of a coin and it’s not very expensive (Purchase here).

PIR Sensor ModulePIR Sensor Module

We need a PIR sensor module to detect motion and report it to ESP8266 (Purchase here).

FTDI USB to TTL Serial Adapter

FTDI USB to TTL Serial AdapterWe need a FTDI adapter to connect our ESP8266 to the computer to program it. You can buy any FTDI device but try to get one which gives you 3.3 and 5v output. For this project, I am using FT232RL. This gives me 3.3 and 5v via a jumper setting (Purchase here).

A Breadboard and a Couple of Jumper WiresBreadboard and wires

We need a breadboard and a couple of jumper wires to connect all the components together.

Breadboard power supply

This is not necessary if you want to use FTDI to power the device. However, I’d recommend to have this as it’s a handy power source for breadboard prototypes.


Building the IoT device

Now we have all the required components, we can start building our IoT device.

I have broken the build down into 4 steps to keep things simple:

  1. Create an Azure Mobile Service
  2. Know your hardware and put things together
  3. Program the hardware and configure it to use Azure
  4. See its working and monitoring the movements on Azure

Create an Azure Mobile Service

Login to Azure Portal and follow the steps below to create the Mobile Service. We use this to monitor the motion detections.

  1. Once you have logged-in to the Azure Portal, click on NEW (Step 1)
  2. In the ‘Search the marketplace’ search box, type ‘mobile service’ (Step 2)
  3. From the search results, click on ‘Mobile Service (preview)’ (Step 3)

Azure Portal - Steps 1 - 3

4. Click on the ‘Create’  button as shown in the screenshot below:

Azure Portal - Create button

5. It will take you to another URL and will open the following dialog box. Please fill the details as shown in the screenshot below and click on next button:

Azure Portal - create a mobile service

6. In this step, select ‘Create a new SQL database instance’ from the ‘Database’ dropdown and follow the steps on screen. Alternatively, you can choose any existing database if you already have one.

7. Once the service is created, create a table to save the data.

a. Click on Mobile Service you have just created

Selected Device in Azure

b. Select the DATA tab, and click on “Add a table”

Data Tab in Azure

c. Create the table name “MotionLog”

Motionlog in Azure

8. Create new API to connect with Mobile Service

a. Select the API tab and click on “Create a Custom API”

Create a custom API

b. Name the API as “ESPAPI”


9. Select the “Dashboard” tab and Click on the ‘Manage Keys’ button to create the application keys:

Azure Portal - Manage keys

10. Copy the application key and save it somewhere in the notepad. We’ll need it shortly when we program the ESP8266.

Manage Access Keys

Now, we have Azure service ready to be used in ESP8266. Let’s move on to the next step and put the hardware together.

Know your hardware and put the things together

  1. PIR Sensors pin outs

PIR Module

2. FTDI Serial pin outs

FTDI Serial pin outs

3. ESP8266 (01) pin outs

ESP8266 (01) pin outs

Connect the ESP to FTDI

Connect ESP to FTDI

Programme your hardware and configure to use Azure

Once we have the hardware connected, it’s time to program the ESP8266.

There are many ESP loader tools available and you can use any of them. I am using “Lua Uploader” You can download it from here.

After downloading the zip file, please extract it to your local folder and double click on “LuaUploader.exe” to run the program.

Below is the code for ESP8266. Before uploading the code to ESP, you need to change two configurations in the following scripts. The configuration values are highlighted in RED and marked as TO DOs.

The two configuration values are:

  1. Your WiFi name and password to connect the device to the internet
  2. The application key of Azure Mobile Service you created above.

Please change both the configuration and copy and paste the script in the Lua Uploader.

Wifi setup and coding


Now connect the FTDI Serial to the computer USB and find the USB Port in the device manager.

Connect FTDI to USB

Once you know the port number, select that Port (mine is COM3 yours might be different), Baud rate and Line Delay as shown in the screenshot below:

COM3 Line delay

Once USB connection settings are in place, click on “Save to ESP” button. You should see a blue LED flashing in ESP8266 while program is being uploaded.

The Lua Uploader should look like this:

Save to ESP - Lua Uploader

Now ESP8266 is programmed and ready to upload the movement’s ‘state’ to Azure Service. But before that we need to connect the PIR sensor to the ESP8266 in the next step.

See it’s working – Monitor the movements on Azure

Now you need to connect the PIR sensor and power the device. You can power the device using FTDI if you want to monitor the serial log in Lua Uploader. This is useful for debugging purpose.

Connect PIR Sensor and Power the Device using FTDI

Disconnect the FTDI from computer and connect the PIR Sensor as below. Once PIR sensor is connected, then connect the FTDI to the computer again to power the device.

PIR module 2

Power the device using external Power Source

If you don’t want to debug the program, then you don’t need FTDI and can power the device using the batteries or external breadboard power device. You just need to make sure you supply 5v to the PIR sensor and 3.3v to the ESP8266.

power device using external power source - step 1

This is how you can connect the device using external power source:

Connect device to batteries

Once the device is powered on, and you put your hand in front of the PIR sensor, it’ll upload the movement’s status to the Azure.

Just go to the Mobile Application Service you created earlier and go to the DATA tab of the API. You should see the motion log as below:

Motion Log Data

With small changes in the program you can connect other sensor as well and upload the data on Azure.


This demonstration is a simple example of the power of IoT.  The combination of low cost sensor components and cloud services such as Azure make this technology accessible to everyone.

To see how your organisation can benefit contact us to book your free workshop and Proof Of Concept.

Our Awards & Accreditations