IoT: Connecting the Arduino to the Internet



The Internet of Things (IoT) generally refers to devices capable of collecting data and communicating that data to servers and other devices over the Internet without human intervention. Every “thing” does something unique, like sensing the temperature of the environment, or monitoring the foods you take out of your fridge. IoT devices perform limited functions; therefore, they require far fewer resources as compared to regular computers like phones and laptops. They are implemented with microcontrollers which are extremely small computers that have limited computing resources (in order to reduce price and power consumption). Microcontrollers also have peripherals that allow them to interact with the physical world through sensors (e.g. temperature sensors) and actuators (e.g. motors).

This post focuses on implementing IoT with the Arduino microcontroller because it is a popular platform with an active community and tons of resources. Of course IoT devices must be able to connect to the Internet, and this post will show how to do that with an ESP8266 Wi-Fi module.
List of Items

  1. Arduino Uno
  2. Breadboard
  3. ESP8266 Wi-Fi module
  4. Jumper wires

Getting Sensor Data

In this post, we will be implementing a mini weather station that measures the temperature of a room and sends that to a server. We can measure temperature with an Arduino using the LM35 temperature sensor. To use it, connect the ground pin to ground the VCC pin to 5V on the Arduino, the ground pin to ground, and the output pin to analog pin 0.

Copy and paste the following code into your Arduino IDE and upload it onto your board.

You should now be able to see the temperature readings from the LM35 in your serial monitor. Note that the Arduino reads analog input from 0V to 5V in 1024 quantized levels. The formula for converting the analog readings to temperature in degrees Celsius can be found in the get_temp function.

Sending Sensor Data over the Internet

The next step is to upload the following code onto the Wi-Fi module using the instructions in this post

The code allows the module to connect to an existing Wi-Fi network and relay data received from the Arduino over serial communication to a server on the Internet or a local network.

Next, upload the following code onto the Arduino board to enable communication between the Wi-Fi module and the Arduino.

Finally, connect the Wi-Fi module to the Arduino (as shown below) to establish serial communication through software serial. Software serial allows us to use PWM on the Arduino pins as serial pins. Next, connect the Wi-Fi module (as shown in the diagram below) and paste the code above into your Arduino IDE.

After performing these steps, we can now see the new IoT device in action. You can set up a server on the same network as my IoT device so I can see the readings being received.

Do you think you can beat this Sweet post?

If so, you may have what it takes to become a Sweetcode contributor... Learn More.

Stephan is a third-year student at Ashesi pursuing an undergraduate degree in computer engineering. Stephan is passionate about technology and is focused on continuous learning to gain new skills. He has worked in software development, and has worked on IoT projects and designing products for the health sector.


Click on a tab to select how you'd like to leave your comment

Leave a Comment

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