#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //The mac adress
byte ip[] = {
192, 168, 178, 43 }; //The IP adress
byte gateway[] = {
192, 168, 178, 1 }; //The gateway
byte subnet[] = {
255, 255, 255, 0 }; //The subnet-mask
EthernetServer server(80);
const int trigPin = 8;
const int echoPin = 9;
float duration, distance;
float body;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Wire.begin();
Ethernet.begin(mac, ip);
server.begin();
}
void loop() {
EthernetClient client = server.available();
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration*.0343)/2;
body = (181 - distance); // The height of the sensor subtracted by the distance
//Note: The height must be set like that of the sensor
if (client) {
server.print("HTTP/1.0 200 OK\r\nServer: arduino\r\nContent-Type: text/html\r\n\r\n");
client.println("<meta http-equiv=\"refresh\" content=\"7\">"); //The website is updated every 7 seconds
server.print("<HTML><HEAD><TITLE>");
server.print("The height of the body");
server.print("</TITLE>");
server.print("</HEAD><BODY>");
server.print("<h2 align=center><font size=7><b>The height of the body </b></font></h2>");
server.print("<center><font size=5><b>The height of the body is </font>");
server.print( body);
server.print("cm.");
delay(500);
client.stop();
}
}
Comments