Publish Your Arduino Data to the Cloud

Publish your Arduino input in real-time so it can be accessible on the internet without taking care of server side.

Publish Your Arduino Data to the Cloud

Overview

The object of this project is to show you how to make accessible on the internet what is being read in one of your Arduino input pins.

This is done without any web server on your Arduino but using an online service.

In our project we are using an Arduino Nano model. There is no problem on using another board model -as Nano is the one with les resources- but you have to pay attention on which are the proper pins for your case.

To reach the web will use an ESP8266 WIFI module

What we will read is the temperature of the environment. To get the measures we have chosen a typical DHT11 sensor.

Finally, to get rid if the server side, we will use the online service circusofthings.com where we can link devices and apps with a single social account.

Powering the Components On

Please note this is a prototype tutorial and not a perfectly chased stand-alone product. What I mean is that I will use a laboratory stabilized voltage source to achieve 3.3V needed for the ESP8266 and I am not posting all necessary to get this voltage from a 5V, batteries, or grid… just to make it easier.

… but, if you decide to get those 3, 3V from another source, take into account:

  • ESP8266 is very delicate. Voltage above 3.6V will fry it. There are some discussions on the net about if it could stand for more voltage, but it depends on how the other pins are connected or which maker is it from. Don’t take risks, remember: less than 3.6V.
  • What nobody told me and maybe saves you one day is that you may see your module perfectly powered, with shinning leds… but recurrent problems to reach the network. It seems that a tinny below the nominal voltage may suppose a shortage on the power that can affect the RF performance.
  • Be aware that ESP8266 might consume up to 250mA. Don’t ever try to source it from your “3.3V” pin of your Nano, it isn’t able to source this current.

Again, for simplicity, I won’t use an external 5Vdc source to power the Nano board as it will connected to the PC with the USB port (as you will find on this tutorial, the serial communication on USB will be monitored for an interesting debug).

… but, if you decide to get those 5V from another source, take into account:

  • Let the Nano have, not only the 5V voltage, but the enough current. Your source should be able to supply 1A or more.
  • Connect the source on the “Vin” pin of the Nano, not in the “5V” pin. The first is the right place as it is protected by an internal regulator (don’t be afraid to give 6V). The second is an output that can feed other components (will be nice for our DHT11 sensor).

Connecting the WiFi Module to the Board

Before we connect to board…

…do you really know which serial baud rate is set in your ESP8266 module by the maker or any other? If yes, skip to next point.

Makers usually set it to 9600 or 115200, but maybe another rate.

You may want to know it following a trial-and-error method when coding, just trying different baud rates and see if it works.

Or you may want to connect your PC to the ESP8266, interfaced in between by an FTDI module, to ask for the actual baud rate with ATT commands. I recommend this way as it is more illustrating and plus you can be sure your module is working properly (and not silently fried or corrupted). To achieve it I followed this tutorial, it’s really good and clear.

I recommend setting it at 9600bauds: easy and slow for your electronics, fast enough for your patience. The proper command will be AT+CIOBAUD=9600.

Connecting to the board

Now that we know which baud rate we have on our ESP8266 module we can go on.

We won’t use the RX/TX UART port of the Nano board to connect to the ESP8266. This is because we want to have this channel free for debugging from our PC.

Then we will use two different digital pins to have another serial port, what is called a “software serial port”. Let’s day D2 will be the TX and D3 will be the RX pin. Don’t worry on how to implement this new port, you will find in coding section how easy is to handle it with a library.

Then, this is how the connection between ESP8266 and Nano board should be.

Notice that the CHEN PIN on the ESP8266 has to be enabled by setting a high state (3.3V). A 10Kohm resistor is placed for protection.

Another concept to bear in mind is that de TX/RX is implented with different voltage levels in both devices. ESP8266 works between 0 and 3.3V, Nano does between 0 and 5V. As Nano is able to detect 3.3V as a high state, you can connect RX on Nano straight to TX on ESP8266. But for the opposite is recommended a tension divider to protect the RX input with a suitable 3.3V voltage when high.

… the thing is that me and many others have checked that it works fine during months without tension divider, ESP8266 seems protected enough. But don’t trust me on it, do it well.

Setting the Temperature Sensor

What we see is it has only 3 pins. The “+” is where 5V will be provided, connecting it to the “5V” of the Nano board. The “-” is the common ground with the rest of components. And the “out” is not an analog or resistive output as one might guess, actually it’s a digital serial output as this sensor is provided with on board intelligent components.

Don’t worry about this protocol, as seen in next sections, we will easily find the Arduino library that lets you manage it with zero effort. It seems the specifications of this protocol are hard to find due to the lack information (only in chinese) just for the case you are interested in it.

We will read this serial communication on PIN 5 in our example (yes, it could be any other digital pin of your board while you bear it in mind when coding).

So, the connection is as simply as follows:

The Whole Gadget

All together should be connected like this:

Registering Your Pin on the Service Online

Follow the process to sign up at circusofthings.com if you don’t have an account yet. It’s free and looking for testers.

In your dashboard, create a “new signal”. Note that it displays a key that identifies your signal. Remember it for the next step.

Give it a name and feel free to edit its description, parameters, tags, and so for you and/or the community.

Coding and Uploading the Software

Before we set the code, you will have to get some Arduino libraries:

  • DHT Sensor Library, to communicate withe the sensor. Get it here.
  • CircusWifiLib, to implement the API of the online community. Get it here.

(You don’t need any lib for Wifi/ESP8266 as it is done by CircusWifiLib).

Now we can take a look to the code:

/*
 WriteOneSignal.ino
 This example code that shows how to feed a signal using the circusofthings.com API through its CircusWifiLib-2.0.0 library for Arduino.
 With this code you can feed a signal taking the values read from a temperature sensor. 
 In this case, we assume we have a DHT11 sensor that is controlled by a propietary protocol implemented in its specific library.
 A software serial port is used, so the onboard serial port is used to monitor the process. You have 3 degrees for monitor: DEBUG_NO,DEBUG_YES and DEBUG_DEEP.
 There are no 3rd part libraries to use, beside SoftwareSerial and DHT Sensor Library Built in by Adafruit Version 1.3.0 
 Created by Jaume Miralles Isern, October 26, 2018.
*/ 
#include <CircusWifiLib.h>
// ------------------------------------------------
// These are the CircusWifiLib related declarations
// ------------------------------------------------
int TXPinForWifiModule = 2;               // IO port in your arduino you will use as TX for serial communication with the wifi module
int RXPinForWifiModule = 3;               // IO port in your arduino you will use as RX for serial communication with the wifi module
char ssid[] = "your_ssid_here";             // your wifi network SSID
char pass[] = "your_wifi_password_here";             // your wifi network password
int wifiSerialBaudRate = 9600;            // Baud rate between your arduino and your wifi module. Did you check that your module actually uses this baud rate?
int debugSerialBaudRate = 9600;           // Baud rate between your arduino and your computer
char token[] = "your_token_here";    // Your API token for Circus
char analogSignalTemperatureKey[] = "944668525";    // The key of the signal you have created at circusofthings.com
SoftwareSerial ss(RXPinForWifiModule,TXPinForWifiModule);
CircusWifiLib circus(Serial,&ss,ssid,pass,DEBUG_YES,KEEP_ALIVE);
// ------------------------------------------------
// These are the Example related declarations
// ------------------------------------------------
#define DHTPIN 5      // digital for serial propietary portocol of sensor DHT11
#define DHTTYPE DHT11 // exact model of temperature sensor DHT 11 for the general library
DHT dht(DHTPIN, DHTTYPE);
void setup() {
 Serial.begin(debugSerialBaudRate);
 ss.begin(wifiSerialBaudRate);
 dht.begin();
 circus.begin();  
}
void loop() {
 float t = dht.readTemperature();
 if (isnan(t)) {
   t=-1; // if so, check the connection of your DHT11 sensor
 }
 delay(3000);
 circus.write(analogSignalTemperatureKey,t,token); 
}

Put the SSID of your WIFI instead of your_wifi_SSID_here.

Put the WIFI password instead of your_wifi_password_here.

Put your account token instead of your_user_token_here.

Put the key of the signal you created instead of your_signal_key_here.

The code above will get the value of the sensor every 3 seconds and will post it to the signal defined by key you own.

Let’s put the sketch in the board as usual.

And open the serial monitor of the IDE (notice in our case we set 9600baud to debug).

Is it reaching the web?

Do the Magic

If everything goes right you should see your signal in your dashboard showing the temperature you actually have in your room.

Now, edit its visibility in your dashboard and set it to public.

Then you have the link to share it with those who don’t have an account at Circus

Now is accessible by any other device or app in the world.

Anyone who follows our next tutorial can get data from the cloud to your Arduino and read this signal from an Arduino board.

Hope it was interesting for you. Thanks for your attention!

Leave a Reply

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