Guruashish Choudhary
Published © GPL3+

Automatic Parking System

Automatic Parking System is an easy project. Information given below demonstrates how to code, connect the various components of the system.

BeginnerProtip2 hours1,313
Automatic Parking System

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematics

Code

Detects the Distance and controls Servo

C/C++
#include<Servo.h>
Servo Serv1;
int trig=10; //trig pin of HC-SR04 is connected to pin 10 of Arduino
int echo=9;  //echo pin of HC-SR04 is connected to pin 9 of Arduino
int distance;
int duration;
void setup() {
pinMode(trig,OUTPUT);  //trig pin of HC-SR04 is set as Output
pinMode(echo,INPUT);   //echo pin of HC-SR04 is set as Input
Serial.begin(9600);
Serv1.attach(3);       //Servo is attached to pin 3 of Arduino
}

void loop() {
digitalWrite(trig,LOW);   //pulse generation started here
delayMicroseconds(2000);
digitalWrite(trig,HIGH);
delayMicroseconds(100);
digitalWrite(trig,LOW);    //pulse generated 
duration=pulseIn(echo,HIGH);  //detects the time till the pulse is High
distance=duration*0.034/2;
Serial.println(distance);
if(distance>5 && distance<14)
{
  Serv1.write(0);
  delay(2000);
}
Serv1.write(90);
delay(100);
}

Credits

Guruashish Choudhary

Guruashish Choudhary

2 projects • 0 followers

Comments