Arduino Iot Parking system

details

Description:

Ethernet or Internet communication originally, a protocol has been defined between peer-to-peer and configured to communicate with that protocol.Ethernet shield uses the chip of Wiznet W5500 which solves the TCP/IP Protocols.

Components:

Arduino Uno

Wiznet W5500 Ethernet Shield

Ultra Sonic Sensor(HC-SR04)

ServoMotor(SG-90)

Infrared rays sensor(GP2Y0A41SK0F)

Breadboard

Wires

Ultrasonic Sensor (HC-SR04)

the principle for generating the ultrasonic  piezoelectric effect ( the piezoelectric effect *) equal to .
– The ultrasonic sensor used generates a frequency of about  40KHz  and can measure the distance from 5 ~ 7m .
– These ultrasonic sensors are used for distance measurement .
– an ultrasonic sensor and transmitter  to the receiver and divided ,  a transmission signal is reflected  to the receiver to receive the calculated distance based on the time difference for it .
– Operation  triger the pin 10us  enough high  main surface of the ultrasonic sensor signal is  40kHz  automatically the pulse  8 raises times .
– Immediately after the pulse that caused the  echo pin is high when the reflected ultrasonic waves are detected  echo pin is LOW it is a .
– Measure the time it takes for this  echo pin to go  high and go  low , then divide the time by the speed of the ultrasonic wave / 2 ( round trip / 2) to get the distance .
118
Ultrasonic Sensor (HC-SR04)
The speed of the ultrasonic wave is about  340m / s
– transmission of the ultrasonic sensor ( triger ) spaced a certain time from the emission of short ultrasonic pulses ,  the pulse in the return hit the object  receiver (echo) received in , and calculates a distance based on the time difference for it .
– The time taken to move 1cm can be obtained as follows .
– Therefore , t = 2 * 0.01 / 340 = 58.824us to ,  ultrasound is 1cm time it takes to move is about  29us takes .
– distance (cm) = duration ( round trip time ) / 29/2 ( round trip )

119
More description on ultrasonic sensors follow the below link

Infrared sensor (GP2Y0A21YK0F)

Infrared sensors are usually measured distance ,  the human body detection  is used a lot .
– an infrared sensor that emits light of a certain frequency  the light emitting portion , the light emitting is reflected for detecting  a light receiving portion composed of .
– Infrared sensor detects the light reflected by this metaphor of the object , you can see the distance to the object or free .
– The above element is   a device composed of integrated light emitting part and light receiving part .
– infrared light to external  noise because the receive too much ,  there are disadvantages that should be used only indoors.

Servo Motor (SG90):

Servo motors are  widely used in robotics field by taking advantage of precise angle control  .
– Angle control is  possible from 0-180 degrees or 360 degrees  .
– In other words , the motor can fit your exact position and speed along the predetermined command  called servo motors must .
– The servomotor is controlled by adjusting the pulse width using PWM (Pulse Width Modulation) .
– At this time , when controlling the angle , it is possible to control by adjusting the length of duty cycle shown below  .
– using  SG90 is a cycle is  20ms , and fixed to , in the one period  Duty Cycle is a few yinya the angle moving along varies
– There are two ways to control the  servo motor in Arduino .
– How to enter a direct angle
– How to control the duty cycle  width yourself

Each sensor can be used as above.

The above sensors are configured as shown below.

Schematic

120
  Photos of all works
121

All of this can be confirmed by Ethernet (Web browser).

Ethernet (Web browser):
122
 Source code
#include <SPI.h>
 #include <Ethernet.h> 
#include <Servo.h>

#if defined (WIZ550io_WITH_MACADDRESS) // WIZ550io is a module with built-in MAC address. ; 
#else 
byte mac [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // enter mac address #endif
// Static IP setting 
IPAddress ip (192,168,1,177); // You must use an independent IP on the local network. 
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 pdf dns
EthernetServer server 80; 
void check_led_status ();
 #define close_led 5
 #define open_led 3 
#define trig 8 // Set the transmitter of the ultrasonic sensor to pin 8. #define echo 9 // Set the receiver of the ultrasonic sensor to pin 9.

// Infrared sensor 
int pinNum = A1; // Use analog pin number 0 
int distance = 0; // Create distance variable // Ultrasonic sensor float distance2 = 0; // Create distance variable 
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); // Set A1 pin to INPUT 
servo.write (95); digitalWrite (close_led, LOW); 
digitalWrite (open_led, HIGH); 
while (! Serial) { ; // Wait until serial port is connected, only on Leonardo board }

// Initialize the Ethernet device
 #if defined __USE_DHCP__ // When using DHCP (network information assigned by DHCP) 
#if defined (WIZ550io_WITH_MACADDRESS) // When using the MAC address assigned to WIZ550io 
Ethernet.begin ();
 #else Ethernet.Begin (mac); // For Ethernet devices without MAC 
#endif 
#else // Static address (network information user arbitrarily specified) #if defined (WIZ550io_WITH_MACADDRESS) 
Ethernet.begin (ip, myDns, gateway, subnet);
 #else Ethernet.begin (mac, ip, myDns, gateway, subnet); 
 // Start server connection 
server.begin (); 
Serial.println ("Parking Control System"); 
Serial.print ("server is at"); Serial.println (Ethernet.localIP ()); // Output as configured IP serial message
}
void loop () 
{ EthernetClient client = server.available (); // return the data "size" from the client // loop from loop to loop, waiting for client to connect if (client) {// '1' when connected to client. (The chip is internally ESTABLISHED) and reads the Data "Size". Serial.println ("new client");
 boolean currentLineIsBlank = true; 
String buffer = ""; // Declare a string buffer 
// Read the server's current socket state for exception handling. 
// If LISTEN, CLOSE, FIN_WAIT, CLOSE_WAIT state, it does not judge Connection. while (client.connected ()) { 
// infrared ray int data = analogRead (pinNum); // read the measured value from the infrared distance sensor 
int vol = map (data, 0, 1023, 0, 5000); // Convert the measured volt value to a value between 0 and 5000 
distance = (21.61 / (volt-0.1696)) * 1000; // Calculate the distance through the measure 
long start = millis ();
// Ultrasonic sensor is divided into transmitter and receiver, 
// Measure the distance based on the time from transmission to reception. 
// The trigger connected pin is responsible for the transmitter, and the echoed pin is the receiver. 
// Transmitter generates ultrasonic wave for 2 microseconds or more.
 // Prevent current from being sent to eliminate noise before and after ultrasonic wave generation. 
digitalWrite (trig, LOW); 
digitalWrite (echo, LOW); 
delayMicroseconds (2); 
digitalWrite (trig, HIGH); 
delayMicroseconds (10); 
digitalWrite (trig, LOW);

// Set the initial logic level of the receiver to HIGH and measure the time until the ROW level is changed by reflected ultrasonic waves.
 // units are microseconds. 
unsigned long duration = pulseIn (echo, HIGH); 
// The speed of the ultrasonic waves travels 340 meters per second, or 1 centimeter per 29 microseconds.
 // Therefore, the travel distance of the ultrasonic wave = duration (time taken for the round trip) / 29/2.
 distance2 = duration / 29.0 / 2.0;
if (client.available ()) {// If there is data received from the client char c = client.read (); // Read data one byte at a time and store it in variable c 
buffer + = c; // Store 1 byte of data in a string buffer 
Serial.write (c); // Output data serial from client 
if (c == '\ n' && currentLineIsBlank) {// when currentLineIsBlank is True
 // When the HTTP request from the client ends with an empty line (\ n), start sending a standard HTTP response header 
// HTTP start 
client.println ("HTTP / 1.1 200 OK"); 
client.println ("Content-Type: text / html"); 
client.println ("Connection: close"); client.println ("Refresh: 5"); client.println ();

// Transfer to the data client specified in the server
 // client.println ("<! DOCTYPE HTML>"); // When using HTML5 
// Start HTML 
client.println ("<html>"); // Write code in HTML language 
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 a car in front of the 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 ON if LED PORT is '1', or 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);

} * 
/ // Exit HTML
 break; } 
if (c == '\ n') {// Receive a blank line from the client and clear the buffer 
currentLineIsBlank = true;
 buffer = ""; } 
// LED ON 
else if (c == '\ r') {// If you receive the "GET /led.cgi?status=1" data instead of an empty line 
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 a car in front of the door. </ font>"); 
}
 else if (distance2 <20) { client.println ("<font color = 'green'> There is a car in front of the door. </ font>");
 }
client.println ("<br />"); 
client.println ("<a href=\"/parking.htm\"> Go to control-page </a>"); // Return to main page
 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 a car in front of the door. </ font>"); 
} else if (distance2 <20)
 { 
client.println ("<font color = 'green'> There is a car in front of the door. </ font>");
 } 
client.println ("<br />"); 
client.println ("<a href=\"/parking.htm\"> Go to control-page </a>"); // Return to main page 
client.println ("</ body>"); 
client.println ("</ html>"); 
servo.write (95); 
digitalWrite (close_led, LOW); 
digitalWrite (open_led, HIGH); 
// HTML DONE currentLineIsBlank = false; 
break;
} 
}
 // If it is not \ r and \ n, the server will wait for the data, knowing there is still data to send.
 else {// if (c! = '\ r')
 { 
// you've gotten a character on the current line currentLineIsBlank = false; 
} 
} 
} delay (1);
 client.stop ();
 // Terminate TCP connection 
Serial.println ("client disconnected");
 } 
}

















 

 

 

 

 

COMMENTS

Please Login to comment
  Subscribe  
Notify of