So I am making a smart dustbin for a small project , basically when the ultra sensory detects a distance outside the dustbin that is less than 10 cm it triggers the servo to open the bin , but now i want to add another ultra sensor inside the bin to measure the amount of trash inside the dustbin so when it reaches a level
here is the code i am using :
include <Servo.h>
define trigPin 7
define echoPin 6
Servo servo;
int sound = 250;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.attach(8);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < 10) {
Serial.println("the distance is less than 10");
servo.write(90);
delay(100);
}
else {
servo.write(39);
}
if (distance > 10 || distance <= 0){
Serial.println("The distance is more than 10");
}
else {
Serial.print(distance);
Serial.println(" cm");
}
delay(2000);
}

