A Person Who Never Made A Mistake Never Tried Anything New.
- Albert Einstein


SR04 Ultrasonic Distance Sensor Real-Time Cloud Data

Update and Oil Level Monitoring






___________________________________________________________________________________________________________________

#1 Cloud Registration and IOT Web Panel


Elins Technolgies is providing cloud services to create IIOT based applications. These services are free, in order to use these services, register on Elins Cloud Server page as discussed in steps below:

Step1: Click on this icon to register :



Step2: For Registration enter your "Name" and your "email ID".

Step3: Click on "Submit" button.







This is Services page of Elins Cloud Server. Here You can select which Sensor based IIOT Ecosystem Service you wants to use, on this page, you can click on any Icon to open its IIOT Web Panel:







Watch this Video to see the Registration Process:








If you are already Registered User then Login directly through process explained below:

Step1: Click on this icon to Login :



Step2: For Login enter your "Id" which you have recieved after Registration.

Step3: Click on "Submit" button.







This is IIOT Web Panel to see Real-Time Oil Level served through Ultrasonic Distance sensor :







Watch this Video to see the Login process:






___________________________________________________________________________________________________________________


#1 Hardware Connections





___________________________________________________________________________________________________________________


#3 Code Explain


NodeMCU required a code to communicate with the cloud server. Let us discuss this code in detail.

Cloud Arduino code: elins_edu_sr04_code1.zip, Download it from link below:

Unzip the file and open the .INO file





Tutorial for Ultrasonic Sensor (SR04) Code Explain | IOT Learning Kit | Elins Cloud |



This is the Code of NodeMCU to communicate with Elins Cloud Server.

#include < Arduino.h >
#include < ESP8266HTTPClient.h >
#include < ESP8266WiFi.h >

#define LED D0 // DECLARE LED TO PIN D0 (ON BOARD LED)
#define TRIG D5 // DECLARE TRIG TO PIN D5 (IR SENSOR IS CONNECTED)
#define ECHO D6 // DECLARE ECHO TO PIN D6 (IR SENSOR IS CONNECTED)

long microsecondsToCentimeters(long microseconds);

const char* ssid = "Elins Tech."; // PUT SSID OF YOUR WIFI HERE
const char* password = "jaimatadi21"; // PUT PASSWORD OF YOUR WIFI HERE


void setup() {
      delay(5000);
      Serial.begin(9600); // INITIALIZE UART SERIAL MONITOR TO DISPLAY EVENTS
      pinMode(LED,OUTPUT); // DECLARE LED PIN AS OUTPUT PIN
      pinMode(TRIG,OUTPUT); // DECLARE TRIG PIN AS OUTPUT PIN
      pinMode(ECHO,INPUT); // DECLARE ECHO PIN AS INPUT PIN
      digitalWrite(LED,0); // INITIALIZE LED PIN WITH 0 - ON LED

      Serial.println();
      Serial.println();
      Serial.println();

      WiFi.begin(ssid,password); // START WIFI CONNECTION WITH SSID PASSWORD
      Serial.print("[CONNECTING] WAIT ...");

      while (WiFi.status() != WL_CONNECTED) // WAIT TILL WIFI IS CONNECTED
      {
         delay(100);
         Serial.print(".");
      }

      Serial.println("WIFI CONNECTED SUCCESSFULLY");
}

String payload="";
String DeviceId="juvinagrawal651"; // CHANGE IT WITH DEVICE ID RECEIVED FROM CLOUD
HTTPClient http;

int distance;
long duration;

void loop(){


    // ULTRASONIC SENSOR CODE TO MEASURE OIL LEVEL IN TANK
    // Sensor is triggered by a HIGH pulse of 2 or more microseconds.
    // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
    digitalWrite(TRIG, LOW);
    delayMicroseconds(2);
    digitalWrite(TRIG, HIGH);
    delayMicroseconds(5);
    digitalWrite(TRIG, LOW);

    // duration is the time (in microseconds) from the sending of the ping
    // to the reception of its echo off of an object.
    duration = pulseIn(ECHO, HIGH);

    // convert the time into a distance
    distance = microsecondsToCentimeters(duration);

    Serial.print("Distance: ");
    Serial.print(distance);
    Serial.println("cm");


// CODE TO UPLOAD SENSOR DATA ON ELINS CLOUD
      String URL = "";
      URL = URL + "http://elinstechnologies.com/netobox_v1/http_sr_device.php?id=" + DeviceId + "&sr=" + distance; // CLOUD URL
      http.begin(URL); // MAKE HTTP CONNECTION WITH CLOUD
      http.addHeader("Content-Type", "application/x-www-form-urlencoded"); // SPECIFY CONTENT-TYPE HEADER
      int httpCode = http.GET(); // SEND HTTP GET REQUEST TO CLOUD
      payload = http.getString(); // RESPONSE FROM CLOUD
      Serial.println(payload); // PRINT PAYLOAD
      http.end(); // Close connection


            // BLINK LED TO INDICATE ONE CYCLE OF HTTP REQUEST
            digitalWrite(LED,1);
            delay(500);
            digitalWrite(LED,0);
            delay(500);
            digitalWrite(LED,1);
            delay(500);
            digitalWrite(LED,0);
            delay(500);

delay(5000);
// END OF CODE
}

long microsecondsToCentimeters(long microseconds) {
    // The speed of sound is 340 m/s or 29 microseconds per centimeter.
    // The ping travels out and back, so to find the distance of the object we
    // take half of the distance travelled.
     return microseconds / 29 / 2;
}



___________________________________________________________________________________________________________________


#4 Working Demo


We have completed following steps upto now:
# Elins Cloud Registration (Got IIOT Web Panel from it).
# Cloud Arduino Device Code (NodeMCU is ready and communicating with Elins Cloud)

Now Let us RUN the complete IOT Ecosystem all together. For this follow the steps below:


Step1: Click on this icon to Login :



Step2: For Login enter your "Id" which you have recieved after Registration.

Step3: Click on "Submit" button.




This is IIOT Web Panel to see Real-Time Oil Level sensed through Ultrasonic Distance sensor :







Step4: Give Power supply to IOT Kit, Now device LED is blinking, it means device connected with internet.Now real-time data will be displayed on this IIOT Web Panel. To see How this IIOT Ecosystem Work all together, watch this video :




Working Demo SR04 (Ultrasonic Sensor) with Elins Cloud | IOT Learning Kit Extension Board



Step5: So in this way, real time data will be displayed on this IIOT Web Panel.

For next tutorial, Click NEXT.




We hope you enjoyed and learn properly how to create

complete IOT Ecosystem.



for any doubt or query email us at info@elinstechnologies.com

or Whatsapp us







# IOT LEARNING KIT




IOT Learning Kit is a development board based on NodeMCU. IOT Learning Kit Includes:
1. NodeMCU.
2. NodeMCU Board with Relay.
3. Extension Board.
4. DHT11 Temperature and Humidity Sensor.
5. Infrared Sensor.
6. SR04 Ultrasonic Sensor.
7. LDR Sensor



Actual Price : Rs.2999
For Now : Rs.1999 Only
Free Delivery
For Details: Whatsapp at +91-8750853539