0% found this document useful (0 votes)
7 views2 pages

Parking Program

This document contains an Arduino sketch for an ESP32 microcontroller that controls a servo motor and LED indicators based on distance measurements from an ultrasonic sensor. The code initializes the servo and sets up pins for the sensor and LEDs, then continuously measures distance and updates the servo position and LED states accordingly. If the measured distance falls below certain thresholds, different LEDs are activated, and the servo is moved to a specified angle.

Uploaded by

sahbiworkgroup
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Parking Program

This document contains an Arduino sketch for an ESP32 microcontroller that controls a servo motor and LED indicators based on distance measurements from an ultrasonic sensor. The code initializes the servo and sets up pins for the sensor and LEDs, then continuously measures distance and updates the servo position and LED states accordingly. If the measured distance falls below certain thresholds, different LEDs are activated, and the servo is moved to a specified angle.

Uploaded by

sahbiworkgroup
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <Wire.

h>
#include <ESP32Servo.h>

static const int servoPin=33;


Servo servo1;

#define echoPin 27
#define trigPin 12
#define LEDB 4
#define LEDR 2
#define LEDY 17
long duration,distance;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(echoPin, INPUT);
pinMode(trigPin, OUTPUT);
pinMode(LEDB, OUTPUT);
pinMode(LEDR, OUTPUT);
pinMode(LEDY, OUTPUT);

servo1.attach(servoPin);
servo1.write(0);
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration=pulseIn(echoPin,HIGH);
distance= duration/58.2;

String disp=String(distance);

Serial.print(disp);
Serial.print(" cm");
if (distance<20) {
digitalWrite(LEDR, HIGH);
servo1.write(90);
}
else {
digitalWrite(LEDR, LOW);
servo1.write(0);
}
if (distance<15) {
digitalWrite(LEDB, HIGH);
}
else {
digitalWrite(LEDB, LOW);
}
if (distance<10) {
digitalWrite(LEDY, HIGH);
}
else {
digitalWrite(LEDY, LOW);
}
delay(1000); // this speeds up the simulation
}

You might also like