Translate

Mengakses Sensor Tekanan / Pressure HX710B Arduino

Mengakses Sensor Tekanan / Pressure HX710B Arduino
 
   
        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara mengakses sensor tekanan yang memiliki range 0 - 40 Kpa dengan menggunakan arduino. sensor ini sangat cocok untuk melakukan sensing pada tekanan yang rendah. untuk lebih jelasnya berikut adalah koding dan skemanya.

 
 
a. Skema 
sumber: https://www.teachmemicro.com/arduino-pressure-sensor-tutorial/



 
 b. Program Arduino IDE
 
#include <Wire.h>  // i2C Conection Library
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
#include "HX710B.h"

LiquidCrystal_I2C lcd(0x27, 16, 2);

int btok = 2;
int btup = 3;
int btdown = 4;
int btset = 5;
int btokx;
int btupx;
int btdownx;
int btsetx;
int dataadc;
int nilaimax = 3;
int nilaimin = 0;
float volt;
float mvolt;
float psi;

const int DOUT = 2;   //sensor data pin
const int SCLK  = 3;   //sensor clock pin

HX710B pressure_sensor;


void setup() {
  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  pinMode(btset,INPUT_PULLUP);
  pinMode(btok,INPUT_PULLUP);
  pinMode(btup,INPUT_PULLUP);
  pinMode(btdown,INPUT_PULLUP);
  pressure_sensor.begin(DOUT,SCLK);
}


void loop() {

  btsetx = digitalRead(btset);
  btupx = digitalRead(btup);
  btdownx = digitalRead(btdown);
  btokx = digitalRead(btok);
  psi = pressure_sensor.psi();
 
  if (pressure_sensor.is_ready()) {
    Serial.print("PSI: ");
    Serial.println(psi);
  } else {
    Serial.println("Pressure sensor not found.");
  }

  lcd.setCursor(0, 0);
  lcd.print("Psi=");
  lcd.print(psi);
  lcd.print("   ");

if(psi > nilaimax){
  lcd.setCursor(0, 1);
  lcd.print("Max pressure   ");
}

if((psi > nilaimin)&&(psi < nilaimax)){
  lcd.setCursor(0, 1);
  lcd.print("Normal        ");
}

if(psi < nilaimin){
  lcd.setCursor(0, 1);
  lcd.print("Min pressure  ");
}


if(btsetx == 0){
  batasatas();
  batasbawah();
}

delay(200);
}


void batasatas(){
 
  btsetx = digitalRead(btset);
  btupx = digitalRead(btup);
  btdownx = digitalRead(btdown);
  btokx = digitalRead(btok);

  lcd.setCursor(0, 0);
  lcd.print("Max=");
  lcd.print(nilaimax);
  lcd.print(" psi  ");  

  if(btupx == 0){
    delay(200);
    nilaimax++;
  }

  if(btdownx == 0){
    delay(200);
    nilaimax--;
  }

  if(btokx == 0){
    lcd.clear();
    delay(2000);
    return;
  }


batasatas();
}



void batasbawah(){
 
  btsetx = digitalRead(btset);
  btupx = digitalRead(btup);
  btdownx = digitalRead(btdown);
  btokx = digitalRead(btok);

  lcd.setCursor(0, 0);
  lcd.print("Min=");
  lcd.print(nilaimin);
  lcd.print(" pai  ");  

  if(btupx == 0){
    delay(200);
    nilaimin++;
  }

  if(btdownx == 0){
    delay(200);
    nilaimin--;
  }

  if(btokx == 0){
    lcd.clear();
    delay(2000);
    return;
  }


batasbawah();
}
 
 
 
 
c. Program Arduino Contoh
 
#include "HX710B.h"

const int DOUT = 2;   //sensor data pin
const int SCLK  = 3;   //sensor clock pin

HX710B pressure_sensor;

void setup() {
  Serial.begin(9600);
  pressure_sensor.begin(DOUT,SCLK);
}

void loop() {

  if (pressure_sensor.is_ready()) {
    Serial.print("PSI: ");
    Serial.println(pressure_sensor.psi());
  } else {
    Serial.println("Pressure sensor not found.");
  }

  delay(1000);
 
}
 
 
 
 
 
d. VIDEO HASILNYA



 
 

No comments:

Post a Comment