Dalam arduino tutorial ini saya akan menujukan
kepada anda bagaimana anda dapat membuat tempat sampah otomatis.Anda dapat
menonton video berikut atau membaca tutorial tertulis di bawah ini untuk lebih
jelasnya :
Yang anda butuhkan untuk proyek arduino ini adalah sensor ultrasonic motor servo untuk membuka tempat sampah dan juga tempat sampah plastic. Komponen yang dibutuhkan untuk projek arduino ini : Ultrasonic Sensor HC-SR04 Servo Motor Arduino Board Kabel jumper
Membangun perangkat :
Pertama, saya membuat lubang dua pada tempat sampah untuk mengabungkan sensor ultrasonic
Saya juga memasang motor servo untuk membuka tutup sampah dan dihubungkan ke sensor ultrasonic
.
Gambar Skematik :
Saya menghubungkan sensor Ultrasonik HC-SR04 ke pin 9 dan 10 dan motor servo pada pin no 6 pada arduino .
Program Arduino Tempat Sampah Otomatis
#include
// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;
Servo myservo; // create servo object to control a 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(6);
}
void loop() {
// 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, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
///////////////////////////////////////
if (distance <= 20)
{
myservo.write(0); // sets the servo position according to the scaled value
delay(3000);
}
else {
myservo.write(90); // sets the servo position according to the scaled value
delay(1);
}
///////////////////////////////////////
}
EmoticonEmoticon