Parking lot System using arduino, ultrasonic, ldr, servo and laser point

Опубликовано: 21 Май 2026
на канале: G_Nyathikazi Arduino Projects
213
22

#C++ #arduino #parkinglot #ultrasonicsensor #ldr #servomotors #arduinoproject

//Code start here
//please note that the greater than and lessthan symbles can't be used on the description, therefore refer to the video code
#include Servo.h // Library for a servo motor


#define ldr A1 //Analog pin for LDR sensor


//Servo used for entrance gate
Servo Entrance;
int Entrance_pin = 7; //Initialize Digital pin for servo
int initial_position = 0; //Degree at which the servo is positioned


//Servo used for exit gate
Servo Exit;
int Exit_pin = 6; //Initialize Digital pin for servo
int initial_position2 = 180; //Degree at which the servo is positioned


//Ultrasonic Sensor
int trig = 9; // Initialize Digital pin for Ultrasonic trigger pin
int echo = 8; // Initialize Digital pin for Ultrasonic echo pin


void setup() {

//Positioning the Entrance servo to the initial position
Entrance.attach(Entrance_pin);
Entrance.write(initial_position);


//Positioning the Exit servo to the initial posirion
Exit.attach(Exit_pin);
Exit.write(initial_position2);


//Determining the Inputs and Outputs components
pinMode(ldr, INPUT);
pinMode(trig , OUTPUT);
pinMode(echo , INPUT);


//Enable Serial monitor
Serial.begin(9600);
}


void loop() {


//Setting up the Ultrason sensor
digitalWrite(trig , HIGH);
delayMicroseconds(500);
digitalWrite(trig , LOW);


int duration = pulseIn(echo , HIGH);
int distance = (duration / 2) / 28.5 ; //Calculate distance in CM
Serial.print("distance = "); //Printing "words" to the monitor
Serial.println(distance); //Printing the value next to =


int light = analogRead(ldr); //Initialize and read the sensor at analog pin
int laser = map(light, 0, 1023, 100, 0); //Initialize and range the value of the light intensity of LDR
Serial.print("laser = "); //Printing "words" to the monitor
Serial.println(laser); //Printing the value next to =


//IF and ELSE statement to open and close


//Entrence gate
if (laser less= 10) //When ligth intensity of LDR is lessthan = 10 the gate must be closed
{
Entrance.write ( initial_position ); //Servo position for closed gate
}


else //When ligth intensity of LDR is greaterthan 10 the gate must open
{
Entrance.write (100); //Servo position for open gate
delay(4000); //4 seconds delay before the gate closes
}


//Exit gate
if ( distance lessthan 6 ) //When Ultrasonic distance is lessthan 6 CM the gate must open
{
Exit.write (80); //Servo position for open gate
delay(4000); //4 seconds delay before the gate closes
}

else{ //Otherwise the gate must be closed
Exit.write ( initial_position2 ) ; //Servo position for closed gate
}

}
//...................END..................//