Translate

Arduino Sensor jarak (Distance Sensor) MB1013 HRLV-MaxSonar-EZ1A

Arduino Sensor jarak (Distance Sensor) MB1013 HRLV-MaxSonar-EZ1A


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat menggunakan sensor jarak MB1013 HRLV-MaxSonar-EZ1A dengan menggunakan Arduino sebagai kontrollernya. alat ini sangat bagus sekali dipakai untuk mengukur jarak dengan tingkat ketelitian tinggi hingga milimeter. yang perlu diketahui dari sensor jarak ini yaitu sensor ini bisa diakses menggunakan 2 cara yaitu analog dan digital. untuk lebih jelasnya berikut adalah skema dan programnya.



a.Arduino Uno




b. Sensor Jarak MB1013 HRLV-MaxSonar-EZ1A




c. LCD 16x2 I2C






d. Program Arduino IDE ( Analog )

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F,16,2);

const int anPin1 = 0;
long distance1;

void setup(){
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
}

void loop(){
  
  distance1 = analogRead(anPin1)*5;
  
  lcd.setCursor(0,0);
  lcd.print("jarak= ");
  lcd.print(distance1);
  lcd.print(" mm       ");
  delay(200);
  
}




e. Program Arduino IDE ( Digital )

/*
Test code for the Arduino controllers
Written by Tom Bonar for testing
Sensors being used for this code are the HR-MaxSonar from MaxBotix
Used to Read the PW input.
*/
const int pwPin1 = 3; //this may be different depending on the Arduino being used, and the other PW pins being used.
long sensor1, cm, inches;

void setup () {
  Serial.begin(9600);
  pinMode(pwPin1, INPUT);
}

void read_sensor(){
  sensor1 = pulseIn(pwPin1, HIGH);
  cm = sensor1/10 // converts the range to cm
  inches = cm/2.54 // converts the range to inches
}

//This section of code is if you want to print the range readings to your computer too remove this from the code put /* before the code section and */ after the code
void printall(){         
  Serial.print("S1");
  Serial.print(" ");
  Serial.print(sensor1); //This can be made to match the measurement type you wish to have.
  Serial.println("mm"); //Typically will be the range reading increments.
}

void loop () {
  read_sensor();
  printall();
  delay(100); //make this match the refresh rate of the sensor
}





f. VIDEO HASILNYA











No comments:

Post a Comment