Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

/***************************************

* Project 23 : Ultrasonic Range Meter dg Webpage


* Board : NodeMCU ESP8266 V3
* Input : Sensor Ultrasonik HC-SR04
* Output : web page
* IoT Starter Pack
* www.ardutech.com
****************************************/
#include <ESP8266WiFi.h>
//---GANTI SESUAI DENGAN JARINGAN WIFI
//---HOTSPOT ANDA
const char* ssid = "OPPO A9 2020"; // ssid/hotspot
const char* password = "12345678"; // Password

WiFiServer server(80);
//=====================================
char mystring[20];
void setup() {
Serial.begin(9600);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi is connected");
server.begin();
Serial.println("Server started");
Serial.println(WiFi.localIP());
delay(4000);
}
//=========================================
void loop() {

if(Serial.available()>0){
String fix_string ="";
int rlen = Serial.readBytes(mystring,4);
for(int i = 0; i < rlen; i++){
fix_string += mystring[i];
}
Serial.print("Nilai= ");
Serial.print(fix_string);
Serial.println(" cm");

WiFiClient client = server.available();


client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 1");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print("<p style='text-align: center;'><span style='font-size: x-
large;'><strong>Ultrasonic Range Meter</strong></span></p>");
client.println("<hr size='5px' color='red' width='20%' align='centre'>");
client.print("<p style='text-align: center;'><span style='font-size: x-
large;'>www.ardutech.com</span></p>");
client.print("<p style='text-align: center;'><span style='color:
#0000ff;'><strong style='font-size: x-large;'>Range = ");
client.print(fix_string);
client.println(" cm");
client.print("</p>");
client.println("</html>");
delay(200);
}
}

You might also like