Create an IoT Hub and connect your IoT Device

1 min read


In this article I will show you how to create an IoT Hub and connect your IoT Device. This article is part of the IoT Virtual Bootcamp –  Predict Temperature using Azure IoT & Raspberry Pi3.


  • Execution Time: 30 minutes.
  • Required Hardware:
    • Windows 10 PC
    • IoT Hardware kit: or similar hardware.
    • Access to a WiFi network (without a captive portal aka web page login)
  • Required Operating System:
    • Windows 10
  • Other Requirements:
    • Azure Subscription
  • Required Software:
    •  IoT Device Explorer, download :


Lets Create an IoT Hub and connect your IoT Device!

  1. Verify you properly setup your IoT Device – please follow this instructions:
  2. Now you will create an IoT Hub in the Azure Portal. Go to the Azure Portal, click on Create new and type “iot hub”:Create IoT Hub
  3. Now provide the following parameters to create your IoT Hub:


IoT Hub Parameters4. Now verify the IoT Hub is successfully created:


IoT Hub created

5. Now go the Shared Access Policies


IoT Shared Access Policies

6. Then click Shared Access Policies, select “iothubowner” and enable “registry write” and copy the Shared access keys:


7. Now go back to your desktop and open the Device Explorer Twin, If not already installed, install ( ) and run the Device Explorer:


IoT Device Explorer Twin - wikiazure

8. Now select the Management label and Click on Create Device, provide a name for your IoT Device and then paste the Shared Access Credentials you previously copied:

Create IoT Device on Device Explorer Twin - wikiazure

You will see a notification when the device is successfully created:


Iot Device created - wikiazure


9. Now in the Management label, right click on the device you just created and click on “Copy connection string for the selected device”


Device Explorer copy connection - wikiazure

10. Now Launch Arduino. You can download it from here: .

Now add the Microsoft IoT and Arduino libraries by clicking Sketch -> Include Library -> Manage Libraries and search for “AzureIoT”. Install the library AzureIoTHub by Arduino, the AzureIoTProtocol_MQTT by Microsoft and AzureIoTUtility by Microsoft, as shown below.

Add Microsoft IoT library to Arduino - wikiazure

11. Starting with a new sketch and copy the following code: Download code


Now modify the ssid, pass, and connectionString on lines 18 – 20 as shown below and click the “Compile and Upload” button:


String ssid                         = "iot";        // your network SSID (name)
String pass                         = "microsoft";  // your network password (use for WPA, or use as key for WEP)
static const char* connectionString = ";DeviceId=kevinsay;SharedAccessKey=GDTkiREMOVEDVC458=";
#define DHTPIN 2                                   // what digital pin we're connected to
#define DHTTYPE DHT22                               // DHT11 or DHT22


12. Now go back to the Device Explorer,  Click Message To Device. Type a message add any desired properties and click send, as shown below:



Tried to take a closer picture of my device in case you want to validate your sensor connectivity:

sensor IoT Device - wikiazure

Using Serial Monitor, you should be able to look the Humidity Percentage, temperature in °C and °F:


You should also be able to monitor the messages through Serial Monitor as shown below:

IoT Device Serial Monitor - wikiazure

This completes the Lab on how to Create an IoT Hub and connect your IoT Device. Please refer to the  IoT Virtual Bootcamp –  Predict Temperature using Azure IoT & Raspberry Pi3.

Leave a Reply

Your email address will not be published. Required fields are marked *