SMART DUST BIN || DIY PROJECT || HOME MADE || MKINVENTIONS # 119

  


HOME MADE SMART DUST BIN 



CIRCUIT DIAGRAM :-



COMPONENTS REQUIRED:-
  1. ARDUINO UNO/NANO.
  2. SERVO.
  3. ULTRASONIC SENSOR.
  4. BATTERY.
  5. JUMPER WIRES.

SOURCE CODE :-

#include <Servo.h>
Servo servo1;
int trigPin = A3;
int echoPin = A4;
long distance;
long duration;

void setup() 
{
servo1.attach(3); //SERVO
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
}

void loop() {
  ultra();
  servo1.write(80);
  
  if(distance <= 10){
  servo1.write(180);
  delay(5000);
  }
}

void ultra(){
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration*0.034/2;

  }

Post a Comment

0 Comments