Introduction: IOT - Smart Jar Using ESP8266 , Arduino and Ultrasonic Sensor Publishing Data in Local Server

Hello All ! Thanks For Viewing our Instructable . In this Instructable We will Show you the Steps for Making a prototype Like this . Here we are Creating a Database in Localhost Server . A link is made to communicate the ESP8266 to the DB through PHP Script . And the Details are displayed in another PHP Script . Please download the Images and view it properly ., because we have provided Photos so you can See it offline too . Happy Learning !

Step 1: Things Needed for Making a Smart Jar

As explained in the Introduction this Product is a Basic Prototype . It Doesn't Require Costly Elements . The Following are the Things and Software Needed to make this ! Happy DIYing !

Components :

  1. Arduino UNO
  2. Ultrasonic Sensor
  3. A Empty Jar ( Plastic or Transparent is Recommended )
  4. Bread Board
  5. Main Guy : ESP8266 (Wifi Module )
  6. Jumper Wires (15 - 20)
  7. Program loading Cable
  8. Resistors ( 2K ) - 2 Nos

Software :

  1. Arduino IDE
  2. Sublime Text or Notepad ++
  3. Apache Server or Any Hosted Server
  4. Mysql Database

Step 2: ESP 8266 and Ultrasonic Sensor Connection

The Above Image will Clearly explain the Connections For The ESP 8266 and Ultrasonic Sensor with Arduino .

Step 3: Programming Arduino for ESP and Bluetooth

#include <SoftwareSerial.h>

SoftwareSerial esp(2, 3);

long duration ;

int distance;

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

esp.begin(9600);

esp.println("AT");

response(3000);

esp.println("AT+CIOBAUD=9600");

response(1000);

esp.println("AT+CWMODE=1");

response(2000);

esp.println("AT+CWJAP=\"Wifi Name SSID \",\"Wifi Password\"");

response(10000);

pinMode(9,OUTPUT);

pinMode(10,INPUT);

}

void loop() {

// put your main code here, to run repeatedly:

digitalWrite(9,LOW);

delayMicroseconds(2);

digitalWrite(9,HIGH);

delayMicroseconds(10);

digitalWrite(9,LOW);

duration = pulseIn(10,HIGH);

distance = duration*0.034/2;

esp.println("AT+CIPSTART=\"TCP\",\"Your IP Address\",80");

response(5000);

esp.println("AT+CIPSEND=80");

response(2000);

esp.print("GET Your Link with the IP address You Used ");

esp.print(distance);

esp.println("\r\nabcd1234");

response(5000);

}

void response(int waitTime) {

for (int i = 0 ; i < waitTime; i++)

{ if (esp.available() > 0)

{ char x = esp.read();

Serial.print(x);

}

delay(1);

} }

Step 4: Website Programming - Inserting Data

The Following Code is to Typed in Text Editor . It is the Code for Inserting data into Database .

Step 5: Website Programming - Displaying Data

Please Refer the Image for the Code of Displaying Values .

Step 6: Setting Up the Database - I Have Used PHPMyAdmin Pannel

This is a General GUI . If you have doubts in SQL . Feel free to mail us at santhoshnarendra@gmail.com With Subject Instructable - Smart Jar .

Step 7: Done ! Time to Test

Please make sure you use the correct Baud Rate . If ESP8266 gives error We request you to set the baud rate properly . For any further queries don't hesitate to Mail UsThanks for Following the Steps .

Project Made By

Narendra Santhosh N <santhoshnarendra@gmail.com>

Ajay Karthik K <ajaykarthikkasinaathan14@gmail.com>

Subash C