arutsch
Published © GPL3+

Measure the body height with HC-SR04 and W5100

This project is related to the measurement of the body with HC-SR04 and the ethernet shield.

IntermediateShowcase (no instructions)851
Measure the body height with HC-SR04 and W5100

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Arduino Ethernet Shield 2
Arduino Ethernet Shield 2
(W5100)
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Ethernet Cable, 1 m
Ethernet Cable, 1 m
5 meters is better
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

circuit diagram

Code

The Code

Arduino
#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(); 
        }
  
}

Credits

arutsch

arutsch

0 projects • 1 follower

Comments