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);


 }


}

Comments

  1. How to make automatic car parking toll gate

    ReplyDelete
  2. How to make automatic car parking toll gate system

    ReplyDelete
    Replies
    1. How to make automatic car parking toll gate system

      Delete
  3. I HAVE MADE THIS MODEL BUT THE CODE IS NOT GOING IN ARDUINO UNO HOW CAN I UPLOAD THE CODE

    ReplyDelete
    Replies
    1. #include

      Servo 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

      Delete
    2. C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved2025816-16248-pe8qze.na6sf\sketch_sep16a\sketch_sep16a.ino:1:9: error: #include expects "FILENAME" or
      #include
      ^
      exit status 1

      Compilation error: #include expects "FILENAME" or

      Delete
    3. THIS IS IT SHOWING

      Delete
    4. Some thing is wrong

      Delete
  4. The servomotor is not moving

    ReplyDelete
    Replies
    1. Not working bro

      Delete
    2. this is not working it is trash gon i am still stuck in between fucking and licking my gf's pussy and fuck you then xx love you too babe xx

      Delete
  5. FUCKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK

    ReplyDelete
  6. fuckkkkkkkk you its not working trach

    ReplyDelete
  7. C:\Users\nj computers\AppData\Local\Temp\.arduinoIDE-unsaved202604-9796-o2dv01.j3pcg\sketch_jan4e\sketch_jan4e.ino:5:10: fatal error: LiquidCrystal_I2C.h: No such file or directory
    #include
    ^~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    exit status 1

    Compilation error: LiquidCrystal_I2C.h: No such file or directory

    ReplyDelete
  8. Why is this not working u MF

    ReplyDelete
  9. this is not working

    ReplyDelete
  10. Does it work or nah

    ReplyDelete
  11. Sketch uses 4124 bytes (12%) of program storage space. Maximum is 32256 bytes.
    Global variables use 241 bytes (11%) of dynamic memory, leaving 1807 bytes for local variables. Maximum is 2048 bytes.
    Error: cannot open port \\.\COM5: Access is denied.


    Error: unable to open port COM5 for programmer arduino
    Failed uploading: uploading error: exit status 1


    this is not working please send new code

    ReplyDelete
  12. //define Pins
    #include

    Servo 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(2000); // Keep open for 3 sec
    } else {
    servo.write(90); // Close gate (adjust angle if needed)
    }
    }

    ReplyDelete

Post a Comment

Popular posts from this blog

Solar Tracking System

Arduino Code Car Parking System