You need to enable javaScript to run this app.

TEMPAT SAMPAH OTOMATIS

  • Senin, 18 November 2024
  • Elektronika
  • Administrator
  • 0 komentar

WIRING :

 

Komponen:

  1. Mikrokontroler ESP32
  2. Sensor Ultrasonik Servo
  3. Breadboard
  4. Kabel Jumper

 

PROGRAM :

#include . // Link Library https://drive.google.com/file/d/1lxsSndsS7Ko1NGPxBYUNNZfGB6NLQUE5/view?usp=share_link
// Defines Tirg and Echo pins of the Ultrasonic Sensor

// Tentukan pin Trigonometri dan Gema Sensor Ultrasonik
const int trigPin = 25;
const int echoPin = 26;
// Variabel untuk durasi dan jarak
long duration;
float distance;

int tutup = 0;
int buka = 100;

Servo myServo; // Creates a servo object for controlling the servo motor

void setup() {
// put your setup code here, to run once:
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input

Serial.begin(112500); // memulai dan menggunakan serial monitor dengan baud rate 112500
myServo.attach(27); // Defines on which pin is the servo motor attached
}

void loop() {
// put your main code here, to run repeatedly:
calculateDistance();
if (distance <= 50) {
myServo.write(buka);
Serial.println("Servo Buka");
delay(3000);
} else {
myServo.write(tutup);
Serial.println("Servo Tutup");
}
delay(1000);
}
int calculateDistance() {

digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds
distance = duration * 0.034 / 2;
Serial.print("Jarak : ");
Serial.println(distance);
return distance;
}

 

LIBRARY 

 

 atau ini ada suara pakai DF player

komponen :

  1. Tempat sampah injak
  2. Arduino uno :
  3. Sensor ultrasonik:
  4. Motor servo: 
  5. DFPlayer mini: 
  6. Speaker 3W: 
  7. Memory card: 

KODING DISINI

PRYEK LAIN DISINI :

Components Used - 1) Ultrasonic Sensor 2) Arduino nano 3) Servo Motor 4) Dustbin 5) Wires 6) Micro USB Soket

KODING:

#include<Servo.h>
const int trigPin = A2;
const int echoPin = A1;
const int servoPin = A0;
// defines variables
double SetDelay, Input, Output, ServoOutput;
Servo myServo; //Initialize Servo.
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
myServo.attach(servoPin); //Attach Servo
Input = readPosition();
}
void loop() {
Input = readPosition();
ServoOutput=Input;
myServo.write(ServoOutput);
if(ServoOutput ==140)
{
SetDelay=3000;
}
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=140;
}
else{
var=50;
}
//Returns distance value.
return var;
}
ATAU DOWNLOAD DISINI

 

 

Bagikan artikel ini:

Beri Komentar

Jajak Pendapat

PELAJARAN ELEKTRONIKA YANG PALING ANDA SUKAI ADALAH ?

Hasil
Banner