0% found this document useful (0 votes)
13 views2 pages

Arduino

Uploaded by

Mgm Mallikarjun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Arduino

Uploaded by

Mgm Mallikarjun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <Arduino.

h>
#include <ESP8266WiFi.h>
#include <DHT.h>
#define echoPin D5
#define trigPin D6
long duration;
int distance; // Variable to store distance calculated using
const char* ssid = "MGM12345";
const char* password = "MGM12345";
const char* host = "192.168.43.69";
//#define DHTPIN D1 // Digital pin D1 connected to the DHT sensor
//#define DHTTYPE DHT11 // DHT 11
//DHT dht(DHTPIN, DHTTYPE);
void setup()
{
pinMode(trigPin,OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
Serial.println(".");
}
Serial.println("WiFi connected");
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH); // turn on the Trigger to generate pulse
delayMicroseconds(10); // keep the trigger "ON" for 10 ms to generate
digitalWrite(trigPin,LOW); // Turn off the pulse trigger to stop
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.0344 / 2; // Expression to calculate
if(isnan(distance))// || isnan(moisture)){
{
Serial.println("Failed to read the Sensor");
}
else
{
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort))
{
Serial.println("connection failed"); //longitude latitude
return;
}
if(distance<=10)
{
String longitude = "16.859500455531283";
String latitude = "75.71231817124152";
Serial.println(distance);
client.print(String("GET http://localhost/e2/dht.php?") +
("&longitude=") + longitude +
("&latitude=") + latitude +
" HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0)
{
if (millis() - timeout > 1000)
{
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
while(client.available())
{
}
Serial.println("Write the code to insert data into php MySql
Database");
delay(10000);
}
}
}

You might also like