semor jarak




wiring Diagram


gambar jadi

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int trigPin =  8;
const int echoPin = 9;
const int led = 13;


void setup() 
{
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led, OUTPUT);
  lcd.begin(16, 2);
  lcd.print ("Ultrasonic ");
  lcd.setCursor(0, 1);
  lcd.print ("Range Meter");
  delay (5000);
    
}
long duration, r;
float distance;

void loop()
{
  lcd.clear();
  lcd.print("Distance in cm");
    
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  long r = 3.4 * duration / 2;     
  float distance = r / 100.00;
  
  lcd.setCursor(0, 1);
  lcd.print(distance);
  delay (300);

  
 
 if(distance<10)
  {
    digitalWrite(led,HIGH);
  }
 else
  {
    digitalWrite(led,LOW);
  }
  
 delay(300);
}
    
wiring diagram


code program



#define trigPin 7
#define echoPin 6
#define led 13
#define led2 12
#define led3 11
#define led4 10
#define led5 9
#define led6 8
#define buzzer 3

int sound = 250;


void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(buzzer, OUTPUT);

}

void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;


  if (distance <= 30) {
    digitalWrite(led, HIGH);
    sound = 250;
}
  else {
    digitalWrite(led,LOW);
  }
  if (distance < 25) {
      digitalWrite(led2, HIGH);
      sound = 260;
}
  else {
      digitalWrite(led2, LOW);
  }
  if (distance < 20) {
      digitalWrite(led3, HIGH);
      sound = 270;
}
  else {
    digitalWrite(led3, LOW);
  }
  if (distance < 15) {
    digitalWrite(led4, HIGH);
    sound = 280;
}
  else {
    digitalWrite(led4,LOW);
  }
  if (distance < 10) {
    digitalWrite(led5, HIGH);
    sound = 290;
}
  else {
    digitalWrite(led5,LOW);
  }
  if (distance < 5) {
    digitalWrite(led6, HIGH);
    sound = 300;
}
  else {
    digitalWrite(led6,LOW);
  }

  if (distance > 30 || distance <= 0){
    Serial.println("Jarak diluar jangkauan!");
    noTone(buzzer);
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
    tone(buzzer, sound);

  }
  delay(500);
}


sensor jarak

code program 1

Kode:

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
const int trigPin = 11;
const int echoPin = 10;
const int led = 13;


void setup() 
{
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led, OUTPUT);
  lcd.begin(16, 2);
  lcd.print ("Ultrasonic ");
  lcd.setCursor(0, 1);
  lcd.print ("Range Meter");
  delay (5000);
    
}
long duration, r;
float distance;

void loop()
{
  lcd.clear();
  lcd.print("Distance in cm");
    
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  long r = 3.4 * duration / 2;     
  float distance = r / 100.00;
  
  lcd.setCursor(0, 1);
  lcd.print(distance);
  delay (300);

  
 
 if(distance<10)
  {
    digitalWrite(led,HIGH);
  }
 else
  {
    digitalWrite(led,LOW);
  }
  
 delay(300);
}
code program 2 

// include the library code:
#include <LiquidCrystal.h>

#define echoPin 6             //inisialisai echo pin pada port 6
#define initPin 7             // inisialisasi triger pin pada port 5
unsigned long pulseTime = 0;  // variabel untuk membaca pulsa

// inisialisai LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
 //Setup LCD
 lcd.begin(16, 2);

 // setting output pada pin initPin
 pinMode(initPin, OUTPUT);
 //setting input untuk pin Echo
 pinMode(echoPin, INPUT);
}

void loop() {
 digitalWrite(initPin, HIGH);
 delayMicroseconds(10);
 digitalWrite(initPin, LOW);

 pulseTime = pulseIn(echoPin, HIGH);

 lcd.setCursor(0,0);
 lcd.print("Jarak = ");
 lcd.print(pulseTime / 58, DEC);
 lcd.print(" cm");
 lcd.setCursor(0,1);
 lcd.print(" arduino.web.id");

 delay(100);
 lcd.clear();
}

sensors parkir


code program

================================== SOURCE CODE ==================================
#include "LiquidCrystal.h"
#include "Servo.h"

LiquidCrystal lcd(13, 12, 11, 10, 9 ,8);  
Servo myservo;

#define trigPin A1
#define echoPin A0
#define buzzer 2
#define ledG1  7
#define ledG2  6
#define ledY1  5
#define ledY2  4
#define ledR   3
#define relay A2

void setup() {
  Serial.begin (9600);
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("-Parking System-");
  lcd.setCursor(1,1);
  lcd.print("---- Vers.1 ----");
  delay(1000);
  
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(buzzer,   OUTPUT);
  pinMode(ledG1,    OUTPUT);
  pinMode(ledG2,    OUTPUT);
  pinMode(ledY1,     OUTPUT);
  pinMode(ledY2,     OUTPUT);
  pinMode(ledR,     OUTPUT);
  pinMode(relay,   OUTPUT);


}

void loop() {
   long waktu, jarak;
   digitalWrite(trigPin, LOW);
   delayMicroseconds(2);
   digitalWrite(trigPin, HIGH);
   delayMicroseconds(10);
   digitalWrite(trigPin, LOW);
   waktu    = pulseIn(echoPin, HIGH);
   jarak    =(waktu/2)/29.1;
   
  if (jarak <= 30) {
      digitalWrite(ledG1, HIGH);
    }else{
      digitalWrite(ledG1,LOW);}
    
  if (jarak < 20) {
      digitalWrite(ledG2, HIGH);
    }else{
      digitalWrite(ledG2, LOW);}
      
  if (jarak < 15) {
      digitalWrite(ledY1, HIGH);
    }else {
      digitalWrite(ledY1, LOW);}
      
  if (jarak < 10) {
      digitalWrite(ledY2, HIGH);
    }else {
      digitalWrite(ledY2,LOW);}
 
  if (jarak < 5) {
      digitalWrite(ledR, HIGH);
      digitalWrite(buzzer, HIGH);
    }else {
      digitalWrite(ledR,LOW);
      digitalWrite(buzzer, LOW);}
      
      if (jarak > 30 || jarak <=0){
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("-Parking System-");
          lcd.setCursor(0,1);
          lcd.print("Jarak : ");
          lcd.print(jarak);
          lcd.setCursor(10,1);
          lcd.print("Cm");
      
       
  }else {
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("-Parking System-");
          lcd.setCursor(0,1);
          lcd.print(" ---- Aman ---- ");      
  }
}




sensor parkir 2

 
  

code.


#include <LiquidCrystal_I2C.h>

int trigPin = A0;
int echoPin = A1;
int Buzzer = 8;
int duration, distance;
unsigned long pulseTime = 0;

LiquidCrystal_I2C lcd(0x27, 16,2);

void setup() {
  lcd.init ();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("JARAK AMAN");
  lcd.setCursor(0,1);
  lcd.print("PARKIR KENDARAAN");
  delay(2000);
  lcd.clear();
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(Buzzer, OUTPUT);
       
}

void loop()
{
  long duration, inches, cm;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) /29.1;

  cm = microsecondsToCentimeters(duration);
 
  lcd.setCursor(1,0);
  lcd.print("Jarak : ");
  lcd.print(distance);
  lcd.print("cm");
  delay(500);
  lcd.clear();

  if (cm <= 80) // jarak sesuai dinginkan
  {
    lcd.setCursor(1,1);
    lcd.print("HARAP MENJAUH");
    delay(200);
    digitalWrite(Buzzer,HIGH);
    delay(400); 
    digitalWrite(Buzzer,LOW);
  }

}

long microsecondsToCentimeters(long microseconds)
{
  return microseconds / 29 / 1; //RUMUS MERUBAH MICROSECOND MENJADI CENTIMETER
}



sensor parkir 3 ultrasonic



////////////www.berbageilmu.blogspot.co.id/////////

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20,4);
#define trig1 7
#define echo1 6
#define trig2 5
#define echo2 4
#define trig3 3
#define echo3 2
void setup() {
  Serial.begin(9600);
  lcd.init ();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("JARAK AMAN");
  lcd.setCursor(0,1);
  lcd.print("PARKIR KENDARAAN");
  delay(2000);
  lcd.clear();
    pinMode(trig1, OUTPUT);
    pinMode(trig2, OUTPUT);
    pinMode(trig3, OUTPUT);
    pinMode(echo1, INPUT);
    pinMode(echo2, INPUT);
    pinMode(echo3, INPUT);
 
    lcd.begin(16, 2);// LCD yang digunakan 16x4  
}
void loop() {
  long duration1, distance1;
  digitalWrite(trig1, LOW);
  delayMicroseconds(2);
  digitalWrite(trig1, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig1, LOW);
  duration1 = pulseIn(echo1, HIGH);
  distance1 = (duration1/2) / 29.1;
  long duration2, distance2;
  digitalWrite(trig2, LOW);
  delayMicroseconds(2);
  digitalWrite(trig2, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig2, LOW);
  duration2 = pulseIn(echo2, HIGH);
  distance2 = (duration2/2) / 29.1;
  long duration3, distance3;
   digitalWrite(trig3, LOW);
  delayMicroseconds(2);
  digitalWrite(trig3, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig3, LOW);
  duration3 = pulseIn(echo3, HIGH);
  distance3 = (duration3/2) / 29.1;
        lcd.setCursor(0, 0);
        lcd.print("Informasi Parkir");

      if (distance1 >= 100) {
        lcd.setCursor(0, 1);
        lcd.print("P A : Kosong");
     
      } else if (distance1 <30) {
        lcd.setCursor(0, 1);
        lcd.print("P A : Terisi");
      }
      if (distance2 >= 100) {
        lcd.setCursor(0, 2);
        lcd.print("P B : Kosong");
      } else if (distance2 <30) {
        lcd.setCursor(0, 2);
        lcd.print("P B : Terisi");
      }
      if (distance3 >= 100) {
        lcd.setCursor(0, 3);
        lcd.print("P C : Kosong");
      } else if (distance3 <30) {
        lcd.setCursor(0, 3);
        lcd.print("P C : Terisi");
      }
      Serial.print("Jarak Sensor A :");
      Serial.print(distance1);
      Serial.println("cm");
      Serial.print("Jarak Sensor B :");
      Serial.print(distance2);
      Serial.println("cm");
      Serial.print("Jarak Sensor C :");
      Serial.print(distance3);
      Serial.println("cm");
      Serial.println("");
      delay(100);
}


Komentar

Postingan populer dari blog ini

jam digital

3 phase