Project Untuk Kelompok 5
- Arduino (Versi apapun) >> 1 Buah.
- Sensor Jarak (Ultrasonic) >> 1 Buah.
- Servo >> 1 Buah.
- Buzzer >> 1 Buah.
- Kabel >> Seperlunya.
/*
* Generated Code by Kang Kamal
* kangkamal.blogspot.com
*/
#include <NewPing.h>
#include <Servo.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
Servo myservo;
int buzzer = 6;
int jarak = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(buzzer, OUTPUT);
digitalWrite(buzzer, LOW); //Set default buzzer >> OFF
myservo.attach(10); //Pin Servo
myservo.write(0); //Derajat servo di set ke 0
}
void loop() {
// put your main code here, to run repeatedly:
delay(20); //Diberikan jeda untuk membaca data dari sensor ultrasonic
jarak = sonar.ping_cm();
Serial.print("Jarak : ");
Serial.println(jarak);
if(jarak < 20){
digitalWrite(buzzer, HIGH); //Buzzer dinyalakan tanda ada objek mendekat
myservo.write(90); //Derajat servo di set ke 90
delay(2000);
myservo.write(0); //Derajat servo di set ke 0
digitalWrite(buzzer, LOW); //Buzzer dimatikan
}
}
4 comments:
bazer dsini fungsinya untuk apa bang ?
Cara rangkainya gimaa
Kok eror bg
Terima kasih tutorialnya. Alat berjalan dengan sempurna.. :D
Post a Comment