안진희
Published

Parking System with Ethernet in Arduino

This is Parking System with Ethernet and in arduino. Ethernet is WIZnet W5500 Ethernet shield. It is very easy possible using the ethernet.

BeginnerFull instructions provided2 hours3,144
Parking System with Ethernet in Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
Arduino Uno & Arduino Clone board
×1
W5500
WIZnet W5500
WIZnet W5500 Ethernet shield
×1
Servos (Tower Pro MG996R)
SG-90 Servo motor
×1
Ultrasonic Sensor
HC-SR04
×1
Proximity Sensor
Proximity Sensor
infrared rays sensor
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

IMG_0987.JPG

Schematics

Schematic

Component List
1. Arduino Uno

2. WIZnet W5500 Ethernet shield

3. Ultra Sonic Sensor(HC-SR04)

4. Servo motor (SG-90)

5. infrared rays sensor (GP2Y0A41SK0F)

6. Bread board

7. Wire

Code

Source code (in arduino)

Arduino
/*
 Parking System with Ethernet(Web Server) in Arduino
 
 created 25 Mar 2016
 by Jinhee Ahn
*/

#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>

#if defined(WIZ550io_WITH_MACADDRESS) // WIZ550io MAC   .
;
#else
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // mac  
#endif

//#define __USE_DHCP__ // DHCP  Define

// Static IP 
IPAddress ip(192,168,1,177);  //    IP  .
IPAddress gateway( 192, 168, 1, 1 );
IPAddress subnet( 255, 255, 255, 0 );
// fill in your Domain Name Server address here:
IPAddress myDns(8, 8, 8, 8); // google puble dns

//  80  
//   Socket      .
// HTTP    80  .
// IANA(Internet Assigned Numbers Authority) HTTP  80  .
//       .
// https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt
EthernetServer server(80);

void check_led_status();

#define close_led 5
#define open_led 3
#define trig 8 //   8 .
#define echo 9 //   9 .

//   
int pinNum = A1; // 0 
int distance = 0; //  
//  
float distance2 = 0; //  

Servo servo; 

void setup() {
  servo.attach(7);
  Serial.begin(9600);
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(close_led, OUTPUT);
  pinMode(open_led, OUTPUT);
  pinMode(pinNum, INPUT); //A1 INPUT 
  servo.write(95);
  digitalWrite(close_led, LOW);
  digitalWrite(open_led, HIGH);
   while (!Serial) {
    ; //      ,    
  }
  
//   
#if defined __USE_DHCP__ // DHCP   (  DHCP )
#if defined(WIZ550io_WITH_MACADDRESS) // WIZ550io  MAC   
  Ethernet.begin();
#else
  Ethernet.begin(mac); // MAC    
#endif  
#else // Static    (    )
#if defined(WIZ550io_WITH_MACADDRESS) 
  Ethernet.begin(ip, myDns, gateway, subnet);
#else
  Ethernet.begin(mac, ip, myDns, gateway, subnet);
#endif  
#endif 

  //   
  server.begin();
  Serial.println("Parking Control System");
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP()); //  IP   
}

void loop() { 
  EthernetClient client = server.available(); //    Data "size" 
  // loop       
  if (client) { //   '1' . (  ESTABLISHED  )  Data "Size" .
    Serial.println("new client");   
    boolean currentLineIsBlank = true;
    String buffer = ""; //   
    //       .
    // LISTEN, CLOSE, FIN_WAIT, CLOSE_WAIT  Connection  .
    while (client.connected()) {
      
      // 
      int data = analogRead(pinNum); //     
      int volt = map(data, 0, 1023, 0, 5000); // volt 0 5000  
      distance = (21.61/(volt-0.1696))*1000; //   

      long start = millis();

      //      ,
      //      .
      //     ,     .
      //  2       .
      //   ,       .
      digitalWrite(trig, LOW);
      digitalWrite(echo, LOW);
      delayMicroseconds(2);
      digitalWrite(trig, HIGH);
      delayMicroseconds(10);
      digitalWrite(trig, LOW);
    
      //    HIGH ,    ROW     .
      //   .
      unsigned long duration = pulseIn(echo, HIGH);
    
      //    340 , 29  1 .
      // ,    = duration( ) / 29 / 2 .
      distance2 = duration / 29.0 / 2.0;
          
      if (client.available()) { //     
        char c = client.read(); //  1byte  c  
        buffer += c;  // 1 byte    
        Serial.write(c); //      
        
        if (c == '\n' && currentLineIsBlank) { // currentLineIsBlank True 
          //   HTTP   (\n)  ,  HTTP    
          // HTTP 
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println("Refresh: 5");
          client.println();
          
          //      
          // client.println("<!DOCTYPE HTML>"); // HTML5 
          // HTML 
          client.println("<html>");  // HTML   
          client.println("<body>");

          if (distance > 10) {
            client.println("Parking is <font color='blue'>Empty</font>");
          } 
          else {
            client.println("Parking is <font color='red'>Full</font>");
          }

          client.println("<br />");
          client.println("<br />");

          if(distance2 > 7){
            client.println("<font color='red'>There is not a car in front of door !!</font>");
          }
          else if (distance2 < 7) {
            client.println("<font color='green'>There is a car in front of door !!.</font>");
          }

          client.println("<br />");
          client.println("<br />");

          if (digitalRead(open_led) == LOW) {   // LED PORT '1' LED ON,  LED OFF
            client.println("<font color='blue'>Door is open</font>"); // LED ON
          } 
          else {
            client.println("<font color='red'>Door is close</font>"); // LED OFF
          }
          client.println("<br />");
          client.println("<FORM method=\"get\" action=\"/parking.htm\">");
          client.println("<P> <INPUT type=\"radio\" name=\"status\" value=\"1\">Door is OPEN");
          client.println("<P> <INPUT type=\"radio\" name=\"status\" value=\"0\">Door is CLOSE");
          client.println("<P> <INPUT type=\"submit\" value=\"Submit\"> </FORM>");
          client.println("</body>");
          client.println("</html>");
          /*
          if(distance2 > 20){
            servo.write(0);
            digitalWrite(close_led, LOW);
            digitalWrite(open_led, HIGH);
          }
          else if (distance2 < 20) {
            servo.write(90);
            digitalWrite(close_led, HIGH);
            digitalWrite(open_led, LOW);
          }*/
          // HTML 
          break;
        }
        if (c == '\n') { //       Clear         
          currentLineIsBlank = true;
          buffer="";
        }
        // LED ON 
        else if ( c == '\r') { //    "GET /led.cgi?status=1"  
          if(buffer.indexOf("GET /parking.htm?status=1")>=0){
            // HTTP
            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: text/html");
            client.println();
            // HTML
            client.println("<html>");
            client.println("<body>");
            
            if(distance2 > 20){
              client.println("<font color='red'>There is not a car in front of door.</font>");
            }
            else if (distance2 < 20) {
              client.println("<font color='green'>There is a car in front of door.</font>");
            }
             
            client.println("<br />");
            client.println("<a href=\"/parking.htm\">Go to control-page</a>"); // Main   
            client.println("</body>");
            client.println("</html>");
            servo.write(10);
            digitalWrite(close_led, HIGH);
            digitalWrite(open_led, LOW);
            // HTML DONE
            currentLineIsBlank = false;
            break;
          }

          // LED OFF
          if(buffer.indexOf("GET /parking.htm?status=0")>=0){ // "GET /led.cgi?status=0"  
            // HTTP
            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: text/html");
            client.println();
            // HTML
            client.println("<html>");
            client.println("<body>");
                
            if(distance2 > 20){
              client.println("<font color='red'>There is not a car in front of door.</font>");
            }
            else if (distance2 < 20) {
              client.println("<font color='green'>There is a car in front of door.</font>");
            }
            
            client.println("<br />");
            client.println("<a href=\"/parking.htm\">Go to control-page</a>"); // Main   
            client.println("</body>");
            client.println("</html>");
            servo.write(95);
            digitalWrite(close_led, LOW);
            digitalWrite(open_led, HIGH);
            // HTML DONE
            currentLineIsBlank = false;
            break;
          }
        }
        // \r \n     Data      .
        else{ //if( c != '\r') { 
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    
    delay(1);
    client.stop(); // TCP Connection 
    Serial.println("client disonnected");
  }
}

Credits

안진희
1 project • 3 followers
Contact

Comments

Please log in or sign up to comment.