Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
askasa
Published © LGPL

Build your own parking space!

A parking place management system (A basic tutorial for those are new to Arduino)

BeginnerProtip389
Build your own parking space!

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×1
LDR, 5 Mohm
LDR, 5 Mohm
×5
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 330 ohm
Resistor 330 ohm
×1
LED (generic)
LED (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

The parking space

A parking space for model car

Code

The parking place management system

C/C++
Updating soon
#include <Wire.h> 
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
// the libaries for 16x2 I2C is from github:
// https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Pins that recives the analoge signal from the ldr to arduino
const int ldrPin1 = A0;
const int ldrPin2 = A1;
const int ldrPin3 = A2; 
const int ldrPin4 = A3;
const int ldrPin5 = A4; 
Servo myservo;
int re = 4; //count the car place remain

void setup() {
  // put your setup code here, to run once:
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Spaces available");
  
  myservo.attach(9); // attach the servo to our servo object
  myservo.write(90); // set the servo motor speed to zero
}
void loop() {
  // put your main code here, to run repeatedly:
  re = 4; // update the value
  lcd.setCursor(0,1); // set the cursor for the lcd scream to the second row
  delay(20);
  int ldrStatus1 = analogRead(ldrPin1); // read the value from the pin
  int ldrStatus2 = analogRead(ldrPin2);
  int ldrStatus3 = analogRead(ldrPin3);
  int ldrStatus4 = analogRead(ldrPin4);
  int ldrStatus5 = analogRead(ldrPin5);
  
  if (ldrStatus2 < 300) { // *important: change the variable for you own ldr
    re--;
  }
  if (ldrStatus3 < 300) {
    re--;
  }
  if (ldrStatus4 < 300) {
    re--;
  }
  if (ldrStatus5 < 300) {
    re--;
  }
  if (ldrStatus1 < 300) { //check if there is car trying to enter
    if(re == 0){ // the parking place is full
      lcd.print("              ");// clear the screem by rewrite on it
      lcd.setCursor(0,1);
      lcd.print(" Bad Luck  ");
      delay(3000); // display it on the screem for 3 sec
      lcd.setCursor(0,1);
      lcd.print("               ");
    }
    else{
      lcd.clear(); // clear the whole screem
      for(int i=-7; i<17; i++){ // let the message roll though the screem
        lcd.clear();
        lcd.setCursor(i,0);
        lcd.print("Welcome             ");
        delay(200);
      }
      myservo.write(45); // 360 degree sg90 turn clockwise
      delay(200); // around 90 degree under this time delay
      myservo.write(90);// stop
      delay(5000); // wait 5 sec let the car pass
      myservo.write(135);// 360 degree sg90 turn anticlockwise
      delay(200);
      myservo.write(90);
    }
    lcd.setCursor(0,0);
    lcd.print("Spaces available");
    lcd.setCursor(0,1);
  }
  lcd.print(re); // print the space remain
}

Credits

askasa
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.