Introduction: Connecting Arduino WiFi to the Cloud Using ESP8266
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:
- Arduino, I'm using an Arduino Uno
- ESP8266 WiFi Module, I'm using an ESP-01S
- Computer running Arduino IDE
- Arduino USB cable
- 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.
- Connect the Arduino to your computer through USB cable.
- Open Arduino IDE and flash the code.
- 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.
35 Comments
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 younote, i am using the nano
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.
Reply 12 months ago
Please look at this fix: https://github.com/asksensors/AskSensors-Arduino-W...
12 months ago on Step 7
Please note that there's en error in the source code: https://github.com/asksensors/AskSensors-Arduino-W...
Extra space at the command "AT+CIPSTART" before "TCP".
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.
3 years ago
Esp8266 is connected to Wi-Fi but not to asksensors website. Please help.
Reply 3 years ago
Hello,
Please double check the cabling.
can You try to connect to another server "google.com" ?
Reply 2 years ago
Sir, I am facing the same problem. And it is not even connecting to the google.com servers.
Reply 2 years ago
Hello,
It looks like a hardware issue, please check the cabling.
Reply 3 years ago
I tried to go to the website api.asksensors.com in browser. It was temporarily unavailable.
Reply 3 years ago
Please try to connect to AskSensors with 80 port not 443.
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.
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.
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
Reply 2 years ago
Hello,
Please follow this guide, it describes you how to create a sensor device and get your API KEY IN.
https://asksensors.com/doc/create-sensor-device.ht...
This image shows you where the API KEY is located.
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
Question 3 years ago
Stuck please help receiving failed messages. Thank You!
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.
Question 3 years ago
i did everything but its not working
i just followed ur tutorial but still AT is failed
Answer 3 years ago
Hello,
AT failed, means your ESP module is not responding or the connection is wrong.
please double check.