Arduino with ESP8266 – Reading Data from Internet




The ESP8266-01 has been a great module to quench all our thirsts for IOT projects. Since its release, it has developed a strong community and evolved into an easy to use, cheap and powerful Wi-Fi module. Another open-source platform which is much more popular is the Arduino, it already has tons of projects built around it. Combining these two platforms will open up doors for many innovative projects, so in this tutorial we will learn how to interface the ESP8266-01 module with Arduino. This way we will be able to send or receive data between the Arduino and Internet.

Arduino with ESP8266 - Reading Data from Internet

For the purpose of this tutorial we will read the time, date, temperature and humidity from the internet using an API with the ESP8266-01. Then send these values to an Arduino board and display them on the 16*2 LCD screen. Sounds cool right!! So let’s get started.




Materials Required:

  1. Arduino Board (Any version)
  2. ESP8266-01
  3. FTDI programmer board with 3.3V option
  4. 16×2 LCD
  5. Potentiometer
  6. Push button
  7. Connecting wires
  8. Breadboard

How things work?

Before we dive in, it is important to know how actually this thing is going to work. Basically, we have to start with the ESP8266-01 module. We will be using the Arduino IDE to program the ESP8266 and the code will be written to use an API to read a JSON file through http request. Then we will phrase this JSON file to extract only the required information from the complete JSON file.

Once the information is phrased we will print it out using the serial communication. These serial lines will then be connected to the Arduino, so that the Arduino could read the information sent from ESP8266. Once the information is read and processed we will display it on the LCD screen.

READ  Tutorial 19: Arduino Dice

It’s okay, if you have not completely understood this, for we will be learning the same in the rest of this tutorial.

Programming the ESP8266-01:

This tutorial assumes that you have some experience with the ESP8266 module. If not then it is recommended to read through the following three tutorials to understand completely about it.

  1. Getting started with ESP8266-01
  2. Programming ESP8266-01 using AT commands
  3. Programming the ESP8266-01 using Arduino IDE and Flashing its memory

You can also check our all ESP8266 projects here.

Here we are going to program the ESP8266-01 module using the Arduino IDE. For hardware we are using the FTDI board with 3.3V to program ESP8266, since it will make the hardware much simple. The circuit diagram for connecting your ESP8266 with FTDI board is shown below.

1. The ESP8266-01 is only 3.3V tolerant, do not use 5V. So set FTDI only in 3.3V mode.

2. GPIO_0 must be grounded for programming mode

3. The reset pin should be connected through a button to the ground pin. This button should be pressed just before uploading the code. Each time the button is pressed the blue LED on the ESP8266-01 module will go high to indicate that the module is reset.

Once the connections are done open the Arduino IDE and check if you are able to upload a sample program successfully. If you are not sure how to use the Arduino IDE to upload program to ESP8266 then follow the Programming ESP8266 with Arduino  to learn it. At this point I assume that you have successfully uploaded the blink program.

READ  Internet Datalogging With Arduino and XBee WiFi

Now let’s get into the actual program where we will get data from the internet and send it to the Arduino. The complete program is given at the end of this page further below I am explaining them as small snippets. The program also requires the Arduino JSON library to compile, so if you have not added the library to your Arduino IDE already, then add it by downloading from the Arduino JSON library from Github.

The ESP8266 has to connect with the internet to get the data about date, time, temperature and humidity. So you have to allow it to connect to your Wi-Fi by proving the SSID and Password in the below lines

const char* ssid = "JIO-Fi"; //Enter your Wi-Fi SSID
const char* password = "Pas123"; //Enter you Wi-Fi Password

Inside the setup() function we check if the ESP is able to connect with the Wi-Fi, if not it will wait there forever just by printing “Connecting..” on the serial monitor.

  while (WiFi.status() != WL_CONNECTED) { //Wait till Wi-Fi is connected
    delay(1000);
    Serial.print("Connecting.."); //Print Connecting.. till connection is established 
  }

The next step is the very important step. If the Wi-Fi connection is successful we have to invoke an http get request to read the JSON file from the internet. In this tutorial I am using the API provided by wunderground.com. So if you are planning to use the same you can get into link and signup for the free API key or use any API of your choice. Once you are finalised with your API you will end up with a link something like this below

READ  External Hardware Monitor

  http://api.wunderground.com/api/abcd124578qwert/conditions/q/IN/Chennai.json

Note: I have changed the API key of this link so this will not work. Keep your API key secured and do not share.

Arduino with ESP8266 - Reading Data from Internet schematics

My API here is used to get the weather data of Chennai. You can use any API. But when you load the API in any browser it should return a JSON file. For example my API returns the following JSON file

Read more: Arduino with ESP8266 – Reading Data from Internet




Leave a Comment

*
= 3 + 5

(Spamcheck Enabled)

Read previous post:
Reef Controller
Reef Controller

A Reef / Saltwater Aquarium controller based on an Arduino Mrk1000 and controlled remotely by an Universal Windows Platform app....

Close
Scroll to top