Abdul Aziz M. Abullais

Maker

Web Designer

Graphic Designer

Drone Specialist

Photographer

Blogger

Freelancer

0

No products in the cart.

Abdul Aziz M. Abullais

Maker

Web Designer

Graphic Designer

Drone Specialist

Photographer

Blogger

Freelancer

Blog Post

Smart Dustbin

Smart Dustbin

In the project, students will turn a normal dustbin into a Smart Dustin by attaching an ultrasonic sensor and servo to it, the Ultrasonic sensor will read the distance from the dustbin to any approaching object, if the distance reads below 60cm (ann approaching hand most probably) it will activate the servo and hence the dustbin will open up.

Steps:

  1. Attach a mechanism to open the cover of the dustbin
  2. Attach the Servo & Ultrasonic sensor according to the diagram below
  3. Upload the code below
int yellow = 13;
int white = 12;
int red = 11;
int blue = 10;
int green = 9;
const int trigPin = 7;
const int echoPin = 2;         
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication

}
void loop() {
    {
      SetDelay=500;
      delay(3000);
        digitalWrite(yellow, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(50);               // wait for a second
  digitalWrite(yellow, LOW);    // turn the LED off by making the voltage LOW
  delay(50);               // wait for a second
  digitalWrite(white, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(50);               // wait for a second
  digitalWrite(white, LOW);    // turn the LED off by making the voltage LOW
  delay(50); 
  digitalWrite(red, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(50);               // wait for a second
  digitalWrite(red, LOW);    // turn the LED off by making the voltage LOW
  delay(50); 
  digitalWrite(blue, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(50);               // wait for a second
  digitalWrite(blue, LOW);    // turn the LED off by making the voltage LOW
  delay(50); 
  digitalWrite(green, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(50);               // wait for a second
  digitalWrite(green, LOW);    // turn the LED off by making the voltage LOW
  delay(50); 
  digitalWrite(trigPin, LOW);
    }
    else{
      SetDelay=100;
    } 
  delay(SetDelay); 
}
float readPosition() {
  delay(40);                                  
  long duration, var;
  int distance; 
  // 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
  duration = pulseIn(echoPin, HIGH);
  
  // Calculating the distance
   distance = duration/(29*2); 
  
  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance);
 
  if(distance <68) {
    var=160;
  }
  else{
    var=100;
  } 
  //Returns distance value.
  return var;            
}
Write a comment