Tarantula3DIYables
Published

DIY - ARDUINO BASED CAR PARKING ASSISTANT

I am back again with another Arduino based home automation project.

BeginnerFull instructions provided1 hour10,793
DIY - ARDUINO BASED CAR PARKING ASSISTANT

Things used in this project

Hardware components

Perfboard
×1
Arduino Nano R3
Arduino Nano R3
×1
LED
DIYables LED
×1
Resistor
DIYables Resistor
×3
Ultrasonic Sensor HC-SR04
DIYables Ultrasonic Sensor HC-SR04
×1
Buzzer
DIYables Buzzer
×1
A 220v AC to 5v DC Buck step-down module
×1
Jumper Wires
DIYables Jumper Wires
×1
USB Cable for Arduino Nano
DIYables USB Cable for Arduino Nano
×1
Screw Terminal Shield For Arduino Nano
DIYables Screw Terminal Shield For Arduino Nano
×1
Starter Kit
DIYables Starter Kit
×1
Breadboard Shield for Arduino
DIYables Breadboard Shield for Arduino
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Assembly

Code

The Code

Arduino
int trigPin       = PD5;  // Sensor Trip pin connected to Arduino pin D5
int echoPin       = PD6;  // Sensor Echo pin connected to Arduino pin D6
int redLED        = PD2;  // Red LED connected to pin D2
int yellowLED     = PD3;  // Yellow LED connected to pin D3
int greenLED      = PD4;  // Green LED connected to pin D4
int buzzer        = A0;   // Buzzer connected to Analogue pin A0
long TempDistance = 0;    // A variable to store the temporary distance
int counter       = 0;    // Counter value to check if the object has stopped moving

void setup() {
  
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  pinMode(redLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);

  pinMode(buzzer, OUTPUT);

}

void loop() {

  long duration, Distance;
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  Distance = (duration/2) / 74;     // Distance in Inches

  if(counter < 20){                             // Do the rest if the car is still moving
    if (Distance > 200) {                       // Nothing in the garrage
        turnThemAllOff();
    }
    if ((Distance > 55) && (Distance <= 200)) { // Turn on Green LED
        digitalWrite(greenLED, HIGH);
        digitalWrite(yellowLED, LOW);
        digitalWrite(redLED, LOW);
        noTone(buzzer);
    } 
    if ((Distance > 15) && (Distance <= 55)) {  // Turn on Yellow LED
        digitalWrite(yellowLED, HIGH);
        digitalWrite(redLED, LOW);
        digitalWrite(greenLED,LOW);
        noTone(buzzer);
    } 
    if (Distance <= 15) {                       // Turn on Red LED
        digitalWrite(redLED, HIGH);
        digitalWrite(greenLED,LOW);
        digitalWrite(yellowLED, LOW);
        noTone(buzzer);
    }
    if (Distance < 8) {                         // Item is way to close - start the buzzer
        tone(buzzer, 500);
    }
  }
   
  if ((Distance == TempDistance) || ((Distance+1) == TempDistance) || ((Distance-1) == TempDistance)){ 
     if(counter >= 20){   // Turn off the lights if the object hasn't moved for 20 cycles (no change in distance)
        Serial.println("No movement detected, turning off the lights");
        turnThemAllOff();
     } else {
        counter++;
     }
  } else {
     counter = 0;         // Reset counter if there is a movement
  }
  TempDistance = Distance;
  
  Serial.print(Distance);
  Serial.println(" inches");

  Serial.print("Counter : ");
  Serial.println(counter);
  delay(500);
}

// Function to turn the LEDs off
void turnThemAllOff(){
  digitalWrite(redLED, LOW);
  digitalWrite(greenLED,LOW);
  digitalWrite(yellowLED, LOW);
  noTone(buzzer);
}

Credits

Tarantula3

Tarantula3

62 projects • 82 followers
There were 1000+ sperms but I was the fastest one..
DIYables

DIYables

0 projects • 62 followers
I would like to invite you to join and add your projects to DIYables platform https://www.hackster.io/diyables

Comments