[Week 7 FYP2] Development of Easy Parking Finder System
Activity Title :
- Modify the previous code to suit with sensor (code 1).
- Make a status in web-page (code 2)
- Study java script using java editor
- Make a status in web-page (code 2)
- Study java script using java editor
Objective :
To show the range on the web-page.
To show the color represent the status of parking
To show the color represent the status of parking
Content :
I modify the previous code to make the code suitable for ultrasonic sensor.
Code1:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
const char* ssid = "abc"; // ssid
const char* password = "123456789";// password
//192.168.43.20
IPAddress ip(192, 168, 43, 23); //set static ip
IPAddress gateway(192, 168, 43, 1); //set getteway
IPAddress subnet(255, 255, 255, 0);//set subnet
// defines pins numbers
const int trigPin = 5; //D1
const int echoPin = 4; //D2
// defines variables
long duration;
int distance;
String page = "";
double data;
ESP8266WebServer server(80);
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(115200);
delay(10);
// Connection to wireless network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
server.begin();
Serial.println("Server started");
// Print the IP address in serial monitor. It must be the same we entered above
Serial.print("Type this address in URL to connect: ");
Serial.print("http://");
Serial.println(ip);
Serial.println("/");
server.on("/", [](){
page = "<html>\
<head>\
<meta http-equiv='refresh' content='5'/>\
<title>Parking Status:</title>\
<style>\
body { background-color: #ffe63b; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
</style>\
</head>\
<body>\
</body>\
</html>";
server.send(200, "text/html", page);
});
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration*0.034/2;
delay(2000);
data = distance;
delay(1000);
server.handleClient();
delay(1);
}
Code2:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
const char* ssid = "abc"; // ssid
const char* password = "123456789";// password
//192.168.43.20
IPAddress ip(192, 168, 43, 23); //set static ip
IPAddress gateway(192, 168, 43, 1); //set getteway
IPAddress subnet(255, 255, 255, 0);//set subnet
// defines pins numbers
const int trigPin = 5; //D1
const int echoPin = 4; //D2
const int ledA = 14; //d5
const int ledB = 12; //d6
// defines variables
long duration;
int distance;
String page = "";
double data;
String (stats);
ESP8266WebServer server(80);
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(ledA, OUTPUT);
pinMode(ledB, OUTPUT);
Serial.begin(115200);
delay(10);
// Connection to wireless network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
server.begin();
Serial.println("Server started");
// Print the IP address in serial monitor. It must be the same we entered above
Serial.print("Type this address in URL to connect: ");
Serial.print("http://");
Serial.println(ip);
Serial.println("/");
server.on("/", [](){
page = "<html>\
<head>\
<meta http-equiv='refresh' content='5'/>\
<title>Parking Status:</title>\
<style>\
body { background-color: #ffe63b; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
</style>\
</head>\
<body>\
</body>\
</html>";
server.send(200, "text/html", page);
});
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration*0.034/2;
delay(2000);
if(distance >= 15)
{
digitalWrite(ledA, HIGH); // set turn on when more than 15 cm
digitalWrite(ledB, LOW); // set off when less than 15
stats = "Not Available";
}
else if(distance <= 14)
{
digitalWrite(ledB, HIGH); // set off when less than 15
digitalWrite(ledA, LOW); // set off when less than 15
stats = "Available";
}
data = distance;
delay(1000);
server.handleClient();
delay(1);
}
Code1:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
const char* ssid = "abc"; // ssid
const char* password = "123456789";// password
//192.168.43.20
IPAddress ip(192, 168, 43, 23); //set static ip
IPAddress gateway(192, 168, 43, 1); //set getteway
IPAddress subnet(255, 255, 255, 0);//set subnet
// defines pins numbers
const int trigPin = 5; //D1
const int echoPin = 4; //D2
// defines variables
long duration;
int distance;
String page = "";
double data;
ESP8266WebServer server(80);
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(115200);
delay(10);
// Connection to wireless network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
server.begin();
Serial.println("Server started");
// Print the IP address in serial monitor. It must be the same we entered above
Serial.print("Type this address in URL to connect: ");
Serial.print("http://");
Serial.println(ip);
Serial.println("/");
server.on("/", [](){
page = "<html>\
<head>\
<meta http-equiv='refresh' content='5'/>\
<title>Parking Status:</title>\
<style>\
body { background-color: #ffe63b; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
</style>\
</head>\
<body>\
</body>\
</html>";
server.send(200, "text/html", page);
});
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration*0.034/2;
delay(2000);
data = distance;
delay(1000);
server.handleClient();
delay(1);
}
Code2:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
const char* ssid = "abc"; // ssid
const char* password = "123456789";// password
//192.168.43.20
IPAddress ip(192, 168, 43, 23); //set static ip
IPAddress gateway(192, 168, 43, 1); //set getteway
IPAddress subnet(255, 255, 255, 0);//set subnet
// defines pins numbers
const int trigPin = 5; //D1
const int echoPin = 4; //D2
const int ledA = 14; //d5
const int ledB = 12; //d6
// defines variables
long duration;
int distance;
String page = "";
double data;
String (stats);
ESP8266WebServer server(80);
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(ledA, OUTPUT);
pinMode(ledB, OUTPUT);
Serial.begin(115200);
delay(10);
// Connection to wireless network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
server.begin();
Serial.println("Server started");
// Print the IP address in serial monitor. It must be the same we entered above
Serial.print("Type this address in URL to connect: ");
Serial.print("http://");
Serial.println(ip);
Serial.println("/");
server.on("/", [](){
page = "<html>\
<head>\
<meta http-equiv='refresh' content='5'/>\
<title>Parking Status:</title>\
<style>\
body { background-color: #ffe63b; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
</style>\
</head>\
<body>\
</body>\
</html>";
server.send(200, "text/html", page);
});
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration*0.034/2;
delay(2000);
if(distance >= 15)
{
digitalWrite(ledA, HIGH); // set turn on when more than 15 cm
digitalWrite(ledB, LOW); // set off when less than 15
stats = "Not Available";
}
else if(distance <= 14)
{
digitalWrite(ledB, HIGH); // set off when less than 15
digitalWrite(ledA, LOW); // set off when less than 15
stats = "Available";
}
data = distance;
delay(1000);
server.handleClient();
delay(1);
}
Result and Analysis:
As a result, the web-page show the reading of ultrasonic sensor and also the background will change to green or red depend on parking availability.
Conclusion:
As a
conclusion, the code is successfully build to make it suit for the sensor.

Comments
Post a Comment