Introducing the automatic trash can💻.||The can opens when an object is detected within 20cm💯

Поділитися
Вставка
  • Опубліковано 2 гру 2024

КОМЕНТАРІ • 6

  • @asantedavid-gn5zp
    @asantedavid-gn5zp 11 місяців тому +1

    Heattttt🔥

  • @ebenblaqstv4890
    @ebenblaqstv4890 11 місяців тому +1

    Slow by sure we will get to the peak of it all❤

  • @acstudiosgh
    @acstudiosgh 9 місяців тому +1

    ❤❤❤

  • @richardanokye3145
    @richardanokye3145 2 місяці тому

    Proud of you son
    Go higher

  • @phegengmusicandcomedy3443
    @phegengmusicandcomedy3443 11 місяців тому +1

    That’s my guys

  • @benambitiousinventions
    @benambitiousinventions  10 місяців тому

    #include
    const int trigPin = 9; // Trig pin of the ultrasonic sensor
    const int echoPin = 10; // Echo pin of the ultrasonic sensor
    const int servoPin = 3; // Pin to which the servo is connected
    Servo myServo; // Create a servo object to control the servo motor
    void setup() {
    Serial.begin(9600); // Initialize serial communication for debugging
    myServo.attach(servoPin); // Attach the servo to its pin
    pinMode(trigPin, OUTPUT); // Set trig pin as output
    pinMode(echoPin, INPUT); // Set echo pin as input
    }
    void loop() {
    long duration, distance;
    // Triggering the ultrasonic sensor to measure distance
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    // Calculating the distance based on the time taken by the sound wave
    duration = pulseIn(echoPin, HIGH);
    distance = (duration / 2) / 29.1; // Divide by 29.1 or use your sensor's conversion factor
    Serial.print("Distance: ");
    Serial.println(distance);
    // Set the servo position based on the distance
    if (distance < 30) { // Adjust this value based on your setup
    myServo.write(90); // If an object is close, set servo to 90 degrees
    } else {
    myServo.write(0); // If no object is detected, set servo to 0 degrees
    }
    delay(100); // Add a small delay for stability
    }