Subham Dash
Published © Apache-2.0

Moving Sensor Parking System

We can use a single ultrasonic sensor mounted on a servo which will help us to reduce the cost of the sensor and we can monitor the slots.

IntermediateWork in progress5 hours1,628
Moving Sensor Parking System

Things used in this project

Story

Read more

Code

code

Arduino
#include <Servo.h>
Servo servo;
int trigPin = 8;    // Trigger
int echoPin = 9;    // Echo
long duration, cm, inches;
long h;
int pos = 0, distcm = 0,slot;
void setup()
{
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  servo.attach(10);
}

void loop()
{
  for (pos = 15; pos <= 135; pos += 40) //the servo will cover from 15 to 135 deg
  {
    servo.write(pos);
     delay(4910);
      h=radar();
    if(h>18)
    {
      slot=pos/40;
      Serial.println("empty and u can park on slot");Serial.println(slot);
    }
    else
    {
      slot=pos/40;
      Serial.println("not available on slot");
      Serial.println(slot);
    }
    
  }
  for (pos = 95; pos >= 55; pos -= 40)
  {
    servo.write(pos);
     delay(4910);
      h=radar();
     if(h>18)
    {
      slot=pos/40;
      Serial.println("empty and u can park on slot");
      Serial.println(slot);
    } 
     else
    {
      slot=pos/40;
      Serial.println("not available on slot");Serial.println(slot);
    }
  }
}
long radar(void) //calulate the distance
{
  digitalWrite(trigPin, LOW);
  delayMicroseconds(10);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
 
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
  cm = (duration/2) / 29.1;     
 
  return cm;
}

Credits

Subham Dash
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.