Translate

AUDIOMETRI (Alat Test / Cek Pendengaran) ARDUINO

 Membuat Alat Audiometri (Alat Test / Cek Pendengaran) Menggunakan Arduino


    ()       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk melakukan test pendengaran seseorang, alat ini menggunakan arduino dan outputnya menggunakan headset. interface alat ini menggunakan LCD dan kendali menggunakan 4 buah pushbutton. untuk lebih jelasnya berikut adalah program dan daftar komponennya.


a. Arduino Uno




b. LCD I2C




c. Headset




d. Program Arduino IDE

#include <PWM.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);

int bt1 = 7;
int bt2 = 6;
int bt3 = 5;
int bt4 = 4;

int bt1x = 0;
int bt2x = 0;
int bt3x = 0;
int bt4x = 0;
int cacah = 1;

//use pin 11 on the Mega instead, otherwise there is a frequency cap at 31 Hz
int pwmpin = 9;         // the pin that the LED is attached to
int duty = 125;         // duty cycle


void setup()
{
  lcd.begin();  
  lcd.clear(); 
  
  pinMode(bt1,INPUT_PULLUP);
  pinMode(bt2,INPUT_PULLUP);
  pinMode(bt3,INPUT_PULLUP);
  pinMode(bt4,INPUT_PULLUP);
  
  InitTimersSafe();
  Serial.begin(9600);
 
}

void loop()
{
  
  bt1x = digitalRead(bt1);
  bt2x = digitalRead(bt2);
  bt3x = digitalRead(bt3);
  bt4x = digitalRead(bt4);
  
  if(bt1x == 0){
  delay(200);  
  cacah++;
  }
  
  if(bt2x == 0){
  delay(200);  
  cacah--;
  }
  
  if(cacah < 1){
    cacah = 1;
  }
  
  if(cacah > 9){
    cacah = 9;
  }
  
  if((cacah == 1)&&(bt3x == 0)){
  mode1();
  }
  if((cacah == 2)&&(bt3x == 0)){
  mode2();
  }
  if((cacah == 3)&&(bt3x == 0)){
  mode3();
  }
  if((cacah == 4)&&(bt3x == 0)){
  mode4();
  }

  if((cacah == 5)&&(bt3x == 0)){
  mode5();
  }
  if((cacah == 6)&&(bt3x == 0)){
  mode6();
  }
  if((cacah == 7)&&(bt3x == 0)){
  mode7();
  }
  if((cacah == 8)&&(bt3x == 0)){
  mode8();
  }
  
  if(cacah == 1){
  lcd.setCursor(0,0);
  lcd.print(">20 DB");
  lcd.setCursor(0,1);
  lcd.print(" 30 DB");
  lcd.setCursor(0,2);
  lcd.print(" 40 DB");
  lcd.setCursor(0,3);
  lcd.print(" 50 DB");
  
  lcd.setCursor(12,0);
  lcd.print(" 60 DB");
  lcd.setCursor(12,1);
  lcd.print(" 70 DB");
  lcd.setCursor(12,2);
  lcd.print(" 80 DB");
  lcd.setCursor(12,3);
  lcd.print(" 90 DB");  
  }
  
  
  if(cacah == 2){
  lcd.setCursor(0,0);
  lcd.print(" 20 DB");
  lcd.setCursor(0,1);
  lcd.print(">30 DB");
  lcd.setCursor(0,2);
  lcd.print(" 40 DB");
  lcd.setCursor(0,3);
  lcd.print(" 50 DB");
  
  lcd.setCursor(12,0);
  lcd.print(" 60 DB");
  lcd.setCursor(12,1);
  lcd.print(" 70 DB");
  lcd.setCursor(12,2);
  lcd.print(" 80 DB");
  lcd.setCursor(12,3);
  lcd.print(" 90 DB");  
  }
  
  if(cacah == 3){
  lcd.setCursor(0,0);
  lcd.print(" 20 DB");
  lcd.setCursor(0,1);
  lcd.print(" 30 DB");
  lcd.setCursor(0,2);
  lcd.print(">40 DB");
  lcd.setCursor(0,3);
  lcd.print(" 50 DB");
  
  lcd.setCursor(12,0);
  lcd.print(" 60 DB");
  lcd.setCursor(12,1);
  lcd.print(" 70 DB");
  lcd.setCursor(12,2);
  lcd.print(" 80 DB");
  lcd.setCursor(12,3);
  lcd.print(" 90 DB");  
  }
  
  if(cacah == 4){
  lcd.setCursor(0,0);
  lcd.print(" 20 DB");
  lcd.setCursor(0,1);
  lcd.print(" 30 DB");
  lcd.setCursor(0,2);
  lcd.print(" 40 DB");
  lcd.setCursor(0,3);
  lcd.print(">50 DB");
  
  lcd.setCursor(12,0);
  lcd.print(" 60 DB");
  lcd.setCursor(12,1);
  lcd.print(" 70 DB");
  lcd.setCursor(12,2);
  lcd.print(" 80 DB");
  lcd.setCursor(12,3);
  lcd.print(" 90 DB");  
  }
  
  if(cacah == 5){
  lcd.setCursor(0,0);
  lcd.print(" 20 DB");
  lcd.setCursor(0,1);
  lcd.print(" 30 DB");
  lcd.setCursor(0,2);
  lcd.print(" 40 DB");
  lcd.setCursor(0,3);
  lcd.print(" 50 DB");
  
  lcd.setCursor(12,0);
  lcd.print(">60 DB");
  lcd.setCursor(12,1);
  lcd.print(" 70 DB");
  lcd.setCursor(12,2);
  lcd.print(" 80 DB");
  lcd.setCursor(12,3);
  lcd.print(" 90 DB");  
  }
  
  if(cacah == 6){
  lcd.setCursor(0,0);
  lcd.print(" 20 DB");
  lcd.setCursor(0,1);
  lcd.print(" 30 DB");
  lcd.setCursor(0,2);
  lcd.print(" 40 DB");
  lcd.setCursor(0,3);
  lcd.print(" 50 DB");
  
  lcd.setCursor(12,0);
  lcd.print(" 60 DB");
  lcd.setCursor(12,1);
  lcd.print(">70 DB");
  lcd.setCursor(12,2);
  lcd.print(" 80 DB");
  lcd.setCursor(12,3);
  lcd.print(" 90 DB");  
  }
  
  if(cacah == 7){
  lcd.setCursor(0,0);
  lcd.print(" 20 DB");
  lcd.setCursor(0,1);
  lcd.print(" 30 DB");
  lcd.setCursor(0,2);
  lcd.print(" 40 DB");
  lcd.setCursor(0,3);
  lcd.print(" 50 DB");
  
  lcd.setCursor(12,0);
  lcd.print(" 60 DB");
  lcd.setCursor(12,1);
  lcd.print(" 70 DB");
  lcd.setCursor(12,2);
  lcd.print(">80 DB");
  lcd.setCursor(12,3);
  lcd.print(" 90 DB");  
  }
  
  if(cacah == 8){
  lcd.setCursor(0,0);
  lcd.print(" 20 DB");
  lcd.setCursor(0,1);
  lcd.print(" 30 DB");
  lcd.setCursor(0,2);
  lcd.print(" 40 DB");
  lcd.setCursor(0,3);
  lcd.print(" 50 DB");
  
  lcd.setCursor(12,0);
  lcd.print(" 60 DB");
  lcd.setCursor(12,1);
  lcd.print(" 70 DB");
  lcd.setCursor(12,2);
  lcd.print(" 80 DB");
  lcd.setCursor(12,3);
  lcd.print(">90 DB");  
  }
  
  pwmWrite(pwmpin, 0);  
  delay(20);
}

void mode1(){
  
bt4x = digitalRead(bt4);

int32_t frequency = 100; //frequency (in Hz)
bool success = SetPinFrequencySafe(pwmpin, frequency);

lcd.setCursor(0,0);
lcd.print(" Running..");

pwmWrite(pwmpin, duty);

if(bt4x == 0){
lcd.clear(); 
return;
}

mode1();
}

void mode2(){
  
bt4x = digitalRead(bt4);

int32_t frequency = 200; //frequency (in Hz)
bool success = SetPinFrequencySafe(pwmpin, frequency);

lcd.setCursor(0,1);
lcd.print(" Running..");

pwmWrite(pwmpin, duty);

if(bt4x == 0){
lcd.clear();  
return;
}

mode2();
}

void mode3(){
  
bt4x = digitalRead(bt4);

int32_t frequency = 300; //frequency (in Hz)
bool success = SetPinFrequencySafe(pwmpin, frequency);

lcd.setCursor(0,2);
lcd.print(" Running..");

pwmWrite(pwmpin, duty);

if(bt4x == 0){
lcd.clear();  
return;
}

mode3();
}

void mode4(){
  
bt4x = digitalRead(bt4);

int32_t frequency = 400; //frequency (in Hz)
bool success = SetPinFrequencySafe(pwmpin, frequency);

lcd.setCursor(0,3);
lcd.print(" Running..");

pwmWrite(pwmpin, duty);

if(bt4x == 0){
lcd.clear();  
return;
}

mode4();
}

void mode5(){
  
bt4x = digitalRead(bt4);

int32_t frequency = 500; //frequency (in Hz)
bool success = SetPinFrequencySafe(pwmpin, frequency);

lcd.setCursor(12,0);
lcd.print(" Running..");

pwmWrite(pwmpin, duty);

if(bt4x == 0){
lcd.clear();  
return;
}

mode5();
}

void mode6(){
  
bt4x = digitalRead(bt4);

int32_t frequency = 600; //frequency (in Hz)
bool success = SetPinFrequencySafe(pwmpin, frequency);

lcd.setCursor(12,1);
lcd.print(" Running..");

pwmWrite(pwmpin, duty);

if(bt4x == 0){
lcd.clear();  
return;
}

mode6();
}

void mode7(){
  
bt4x = digitalRead(bt4);

int32_t frequency = 700; //frequency (in Hz)
bool success = SetPinFrequencySafe(pwmpin, frequency);

lcd.setCursor(12,2);
lcd.print(" Running..");

pwmWrite(pwmpin, duty);

if(bt4x == 0){
lcd.clear();  
return;
}

mode7();
}

void mode8(){
  
bt4x = digitalRead(bt4);

int32_t frequency = 800; //frequency (in Hz)
bool success = SetPinFrequencySafe(pwmpin, frequency);

lcd.setCursor(12,3);
lcd.print(" Running..");

pwmWrite(pwmpin, duty);

if(bt4x == 0){
lcd.clear();  
return;
}

mode8();
}



e. VIDEO HASILNYA









No comments:

Post a Comment