Lampu Belajar Otomatis Berbasis Arduino

Project Untuk Kelompok 2


Komponen yang dibutuhkan :
  • Arduino (Versi apapun) >> 1 Buah.
  • Sensor Jarak (Ultrasonic) >> 2 Buah.
  • Lampu >> 1 Buah.
  • Kabel >> Seperlunya.

Wiring :

Source Code :
     /*  
      * Generated Code by Kang Kamal  
      * kangkamal.blogspot.com  
      */  
     #include <NewPing.h>  
     #define TRIGGER_PIN1 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.  
     #define ECHO_PIN1   11 // Arduino pin tied to echo pin on the ultrasonic sensor.  
     #define MAX_DISTANCE1 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.  
     #define TRIGGER_PIN2 4 // Arduino pin tied to trigger pin on the ultrasonic sensor.  
     #define ECHO_PIN2   3 // Arduino pin tied to echo pin on the ultrasonic sensor.  
     #define MAX_DISTANCE2 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.  
     NewPing sonar1(TRIGGER_PIN1, ECHO_PIN1, MAX_DISTANCE1); // NewPing setup of pins and maximum distance.  
     NewPing sonar2(TRIGGER_PIN2, ECHO_PIN2, MAX_DISTANCE2); // NewPing setup of pins and maximum distance.  
     int nilai1 = 0;  
     int nilai2 = 0;  
     void setup() {  
      // put your setup code here, to run once:  
      Serial.begin(9600);  
     }  
     void loop() {  
      // put your main code here, to run repeatedly:  
      delay(20); //Kasih jeda 20ms untuk memberikan sensor bekerja dengan akurat  
      nilai1 = sonar1.ping_cm();  
      nilai2 = sonar2.ping_cm();  
      Serial.print("Jarak1 : ");  
      Serial.print(nilai1);  
      Serial.print(", Jarak1 : ");  
      Serial.println(nilai2);  
      if (nilai1 < 10 && nilai2 < 10){ //Jika sensor 1 dan 2 tertutupi oleh buku  
       //Isi program disini  
      }   
     }  
    

    comment 0 comments:

    Post a Comment

    CNC Tutorial Cetak si SAM Assistant

     
    © All 4 You... | Design by Blog template in collaboration with Concert Tickets, and Menopause symptoms
    Powered by Blogger