Arduino Code
//define Pins
#include <Servo.h>
Servo servo;
int trigPin = 11;
int echoPin = 12;
// defines variables
long duration;
int distance;
void setup()
{
servo.attach(13);
servo.write(180);
delay(2000);
// Sets the trigPin as an Output
pinMode(trigPin, OUTPUT);
// Sets the echoPin as an Input
pinMode(echoPin, INPUT);
}
void loop()
{
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
if ( distance <= 25 ) // Change Distance according to Ultrasonic Sensor Placement
{
servo.write(180);
delay(3000);
}
else
{
servo.write(90);
}
}
How to make automatic car parking toll gate
ReplyDeletebenchor
DeleteHow to make automatic car parking toll gate system
ReplyDeleteHow to make automatic car parking toll gate system
Deletehi
ReplyDeleteVSF
DeleteI HAVE MADE THIS MODEL BUT THE CODE IS NOT GOING IN ARDUINO UNO HOW CAN I UPLOAD THE CODE
ReplyDelete#include
DeleteServo servo;
int trigPin = 11;
int echoPin = 12;
// defines variables
long duration;
int distance;
void setup() {
servo.attach(13);
servo.write(90); // Start with gate closed (adjust if reversed)
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600); // <-- Added this
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin HIGH for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
if (distance <= 25) { // Object detected within 25cm
servo.write(180); // Open gate (adjust angle if needed)
delay(3000); // Keep open for 3 sec
} else {
servo.write(90); // Close gate (adjust angle if needed)
}
}
try this
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved2025816-16248-pe8qze.na6sf\sketch_sep16a\sketch_sep16a.ino:1:9: error: #include expects "FILENAME" or
Delete#include
^
exit status 1
Compilation error: #include expects "FILENAME" or
THIS IS IT SHOWING
Delete