Connecting Things to Internet (Part 3) – Device Setup

This is the third article of 5 part series on how to get things connected to Internet. The first article sets the stage for the series by explaining the objectives and the background while the second article focuses on creating the heart of the IoT project, The IoT Hub. In this third article, I will go more hands-on with setting up the physical remote sensing device that will be collecting and pushing telemetry to the IoT hub. Devices generally fall into two categories;

  • Devices that are directly connected to the Internet which has more computing power to support secure IP connections like, Intel Galileo, Particle Core and Windows Phone.
  • The second type is the simple devices requiring a gateway to connect to the Internet. In this article, I will configure Raspberry Pi to act as the gateway for Arduino UNO micro-controller.

Arduino UNO + DHTXX Setup

Before I go into much details, I assume that you have some basic electronics knowledge, basic understanding of Arduino and how to download a sketch code to the controller. if not, please check out the article Getting Started with Arduino. As I mentioned in my first article, a low-cost DHT11 humidity and temperature sensor is used for the project. These sensors are very basic and slow, but are great for hobbyists who want to do some basic data collection and logging. There is also a very basic chip inside that sensor that converts analog temperature and humidity readings to digital and spits out a digital signal.

  • DHTXX has four pins;







  • Connect the sensor to Arduino board as per the below sketch


  • Connect the board to your computer via USB cable


  • Make sure Arduino IDE is configured correctly with your Arduino board by following two steps;
    • Confirm IDE is connected to the correct board. in my case it’s Arduino
    • Confirm the COM port connection. based on your USB connection you will have different COM port


  • Compile and burn the below Arduino code into the board. make sure that you include the DHT library in to your Arduino libraries folder before you start compiling the code. this link provides more information how to import external libraries in to your development environment.

NOTE: Certain bloggers convert raw data into a format that is compatible with the IoT hub application before it’s written to the serial port. In my opinion, micro-controllers are not optimized to carry out heavy string operations and has limited memory capacity. But, they are optimized for read/write operations. Therefore, I will write only the raw data to the serial port and pass the responsibility of string formatting to more powerful gateway device.

  • Open serial monitor(Tools–>Serial Monitor in Arduino IDE) and note the raw data being written to the serial port.


Once you start getting raw data readings on serial port, you are ready for the next step, setting up the gateway device – the Raspberry Pi.

Raspberry Pi 2 B Setup

The next step of the device setup project is the configuration of the Internet gateway. This article assumes that you have fair bit of understanding of Raspberry Pi and it’s models, have a Raspberry Pi up and running which is connected to your wireless network (or wired), and able to connect to it using a remote client, such as Putty or Bitvise SSH Client. I am a fan of Bitvise and will be using it to remotely connect to RPi 2 B. If you don’t have the RPi setup yet, please download the OS and follow the installation guide.

For this article, I will use Node.js implementation of Azure IoT SDK. Please follow the provided steps below in the given order to get the RPi setup with Node SDK.

Installing Node on RPi

  • Update the existing OS by executing the following commands. it will take longer to update your OS if you have not done this for a while.

NOTE 1: If you wish to install the latest Node.js on your RPi, then make sure you have the latest OS, Raspbian Jessie, installed on your device. the latest Node installation will not work with older versions of the OS.

  • Download the latest Node package from Node-ARM site and install the package
  • NOTE 2: You also can install older version of Node.js if you have Raspbian Wheezy OS

  • Install older version of Node

    DISCLAIMER: My advice in this case is to install the older version of Node as Windows Azure IoT SDK does not require you to have latest Node and you always can upgrade to the latest if required. At the time of writing, serialport (Node package that is used to communicate with serial port) is compatible with Node 0.10.xx but, not 1.12.xx. If you are required to install latest Node for other projects, please make sure serialport package is compatibly with your Node version.
  • Verify the installation by typing the following command. it should give you the Node version on your RPi


  • Node Package Manager(npm) is used in the next step to install serialport package. therefore, verify npm instillation with the following command and install npm if not installed already.


Installing serialport package on RPi

  • In addition to setting up Node on your RPi, you also require to install serialport package that enables communication with the micro-controller serial port. please run the following command to have the serialport installed.
  • After installing serialport, run the following command to verify and validate the installation.If serialport is installed successfully, you will see the following output.


Configuring RPi with Arduino

Configuring RPi with Arduino to read serial data involves few steps that you have to follow in the order. First and foremost you have to detect the serial port which Arduino is connected via.

  • Connect Arduino to RPi over any available USB ports.



  • Save the following code into get-serial-ports.js and ftp the file to /home/pi/development/iot (or any working directory of your choice) in your RPi.

  • Execute get-serial-ports.js file



This code will scan the active serial ports in your RPi and return the list of port names to the terminal. Based on the configuration of the device, you will see different serial port names in the format /dev/ttyXXXX and you can choose the appropriate port that is connected to Arduino. In my configuration, /dev/ttyACM0 is connected to Arduino and /dev/ttyAMA0 is connected to wireless network card. Write down the serial port name that will be used in the next step.

  • Save below code into read-serial.js, upload the file to your working directory and run the node file.


If all the steps are followed in the given order you will have your very first IoT device setup that is capable of connecting to the Internet and you should now see RPi reading serial data sent from Arduino scrolling down the command window. As I mentioned earlier, I prefer not to process the data in Arduino, but send the raw data to the RPi that will take care of processing. Therefore, you will see comma separated temperature and humidity readings.

This concludes setting up Raspberry Pi and micro-controller which will be used for telemetry. In my next article, I will explain how to install, configure Windows Azure IoT SDK on your RPi and start sending data to Azure IoT hub that was created in my previous article.


2 thoughts on “Connecting Things to Internet (Part 3) – Device Setup

Leave a Comment