Connecting Arduino WiFi to the Cloud Using ESP8266

65,244

17

35

Introduction: Connecting Arduino WiFi to the Cloud Using ESP8266

About: IoT Maker, co-founder of asksensors.com

In this tutorial we will explain you how to connect your Arduino to the IoT cloud through WiFi.

We will configure a setup composed from an Arduino and an ESP8266 WiFi module as an IoT Thing and make it ready to communicate with the AskSensors cloud.

Let's get started!

Step 1: AskSensors Setup

As the first step we have to setup an account on AskSensors IoT platform. AskSensors is an IoT platform providing communication between internet connected devices and the cloud. It offers a free trial account so you don’t even have to open your wallet to get started!

I recommend to follow this getting started guide. This will show you how to create and account and setup a new sensor to send data to.

Step 2: Prepare Hardware

In this demonstration we will need the following hardware:

  1. Arduino, I'm using an Arduino Uno
  2. ESP8266 WiFi Module, I'm using an ESP-01S
  3. Computer running Arduino IDE
  4. Arduino USB cable
  5. Wires and a breadboard

The photo above shows my prototype.

Step 3: Build the Hardware

The connection between Arduino and ESP8266 is as follows:

  • ESP TX to Arduino pin 10, through 1K resistor.
  • ESP RX to Arduino pin 11, through 1K resistor.
  • ESP VCC to Arduino 3V3
  • ESP CH_PD to Arduino 3V3
  • ESP GND to Arduino GND

Note: The ESP8266 GPIOs require 3V3 signals (not 5V tolerent). For quick hack, you can only add a serial resistor of 1K between the Arduino pins and the ESP8266 pins to protect the ESP8266 GPIOs from damage. However, for production, a 5V/3V3 level shifter is needed to guarantee long term circuit reliability. You can check this page to get a 5V/3V3 level shifter module.

Step 4: Write the Code

Now let’s write the code to send a simple data from the Arduino to the AskSensors cloud through WiFi. The Arduino code communicates with the ESP8266 WiFi module using AT commands. Data will be sent to AskSensors over HTTP connection.

We will need to provide the 'Api Key In' that we got previously from AskSensors in order to send Data to the correct Sensor in the cloud.

Ready to Use code:

A ready to use code is provided in the AskSensors github page. Download the code and set the following variables to your setup (WiFi SSID, password and the 'Api Key In'):

String ssid     = "............."; //Wifi SSID 
String password = "............."; //Wifi Password 
String apiKeyIn = "............."; // API Key

Step 5: Run the Code

Now it's time to connect your board.

  1. Connect the Arduino to your computer through USB cable.
  2. Open Arduino IDE and flash the code.
  3. Open a serial terminal. You should see you Arduino handles AT commands with the ESP8266 which performs the connection to WiFi networks and sending data to the AskSensors cloud over HTTP requests.

Step 6: Visualize Your Data

You can visualize your Data using graph. Go to your AskSensors dashboard and open the sensor that you are sending data to. AskSensors allows user to visualize your data in different type of graphs including Line, Gauge, scatter and Bar. The attached image show the case of Line graph.

You may need:

Others functionalities are available such as visualizing data in full graph Live stream, share your graph with external apps and users, export data in CSV files and more!

Step 7: Well Done!

I hope that this tutorial helped you!

Please refer to this list of tutorials if you need support about connecting hardware like Arduino, ESP8266, ESP32, Raspberry Pi to the cloud.

Be the First to Share

    Recommendations

    • Make It Bridge

      Make It Bridge
    • Big and Small Contest

      Big and Small Contest
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge

    35 Comments

    0
    trollbert06
    trollbert06

    2 months ago

    i want to use

    ESP8266 ESP-01 Serial WiFi Wireless Adapter Module

    (sorry for the large text) with the module and to connect it to Alexa, how would i do that, code and all please, thank you
    note, i am using the nano

    0
    Wilson MK
    Wilson MK

    1 year ago on Step 6

    Hello I have followed all instructions from AskSensors tutorials but part of my code shows failed as shown in the image below.
    Please kindly respond as soon as possible and if possible connect me to a technician for inquiry. Give me a contact that I can call on to talk to someone. It's argent please. Thanks.

    F814CNTKVS3XG97.jpg
    0
    Wilson MK
    Wilson MK

    Question 1 year ago on Introduction

    Hello I have followed all instructions from AskSensors tutorials but part of my code shows failed as shown in the image below.
    Please kindly respond as soon as possible and if possible connect me to a technician for inquiry. Give me a contact that I can call on to talk to someone. It's argent please. Thanks.

    Screenshot_20211110-120524.jpg
    0
    joshemmanuel3
    joshemmanuel3

    3 years ago

    Esp8266 is connected to Wi-Fi but not to asksensors website. Please help.

    IMG20200209103821.jpg
    1
    askSensors
    askSensors

    Reply 3 years ago

    Hello,
    Please double check the cabling.
    can You try to connect to another server "google.com" ?

    0
    infinitehorizon100
    infinitehorizon100

    Reply 2 years ago

    Sir, I am facing the same problem. And it is not even connecting to the google.com servers.

    0
    askSensors
    askSensors

    Reply 2 years ago

    Hello,
    It looks like a hardware issue, please check the cabling.

    0
    askSensors
    askSensors

    Reply 3 years ago

    Please try to connect to AskSensors with 80 port not 443.

    0
    david.brewer80
    david.brewer80

    2 years ago

    I think these instructions destroyed my ESP8266. Everything else I'm reading says to use a voltage divider on the RX since Arduino is 5V and these are only 3.3v. Consider yourself warned if you follow this.

    0
    askSensors
    askSensors

    Reply 2 years ago

    Strange, I did lot of tests without connecting any voltage divider.
    As a precaution, I'm going to add a simple voltage divider between the ESP and the Arduino I/O.

    Thank you for getting in touch David.

    0
    ferasha21
    ferasha21

    Question 2 years ago on Step 4

    i cant find Api keyin where can i get it?, to connect my arduino to the asksensor cloud
    thanks

    0
    CMK_
    CMK_

    Question 3 years ago

    I followed this guideline but error occurred when uploading to the board.
    Error is occurred when board choose is uno and esp8266

    image_2020-02-29_16-38-06.png
    0
    LegendaryStar
    LegendaryStar

    Question 3 years ago

    Stuck please help receiving failed messages. Thank You!

    IMG_2147.jpgIMG_2145.jpg
    0
    askSensors
    askSensors

    Answer 3 years ago

    Hello,
    It looks like your Arduino+ESP8266 are not able to get connected to the AskSensors web servers. could you please check your WiFi connection to internet.

    0
    ojha1361
    ojha1361

    Question 3 years ago

    i did everything but its not working
    i just followed ur tutorial but still AT is failed

    0
    askSensors
    askSensors

    Answer 3 years ago

    Hello,
    AT failed, means your ESP module is not responding or the connection is wrong.
    please double check.