Translate

Monitor Suhu tubuh, BPM dan SPO2 via BLYNK (IOT) Sensor MLX90614 dan MAX30100/30102

Monitor Suhu tubuh, BPM dan SPO2 via BLYNK (IOT) Sensor MLX90614 dan MAX30100/30102 


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa memonitor suhu, bpm dan spo2 via aplikasi blynk dengan media internet, untuk microcontroller yang digunakan yaitu nodemcu esp8266. untuk lebih jelasnya berikut adalah program dan komponen penyusunnya. 



a. Skema dan Komponen Penyusun





b. Interface Blynk





c. Program Arduino IDE

#include <Wire.h>
#define BLYNK_PRINT Serial   
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_MLX90614.h>  
#include <MAX30100_PulseOximeter.h>
#define REPORTING_PERIOD_MS 5000
#include "MAX30100.h" //library sensor

LiquidCrystal_I2C lcd(0x27,16,2); //library lcd

MAX30100* pulseOxymeter;   //library

int cacah; //membuat variabel
int spo;
float bpm;
Adafruit_MLX90614 mlx = Adafruit_MLX90614();

float TargetC;
int dataadc;
int suhunya;
int bpmku;
int counter;

PulseOximeter pox;

uint32_t tsLastReport = 0;
String hrData = "";
void onBeatDetected()
{
//    Serial.println("Beat!");
}

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "jhgjhgkjhuyjbdiuyi48789ujhdkjhkfjhku879";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "myhotspotku";
char pass[] = "123456789";

SimpleTimer timer;

int pinreset = D6;

void setup() {
 Blynk.begin(auth, ssid, pass);
 timer.setInterval(1000L, sendSensor);
 
 Wire.begin();
 mlx.begin();
 Serial.begin(9600);
 lcd.begin();
 lcd.clear();
 pinMode(pinreset,OUTPUT);
 digitalWrite(pinreset,HIGH);
  
   //Serial.print("Initializing pulse oximeter..");
 
    if (!pox.begin()) {
        //Serial.println("FAILED");
        for(;;);
    } else {
        //Serial.println("SUCCESS");
    }
 
   pox.setIRLedCurrent(MAX30100_LED_CURR_11MA);
   pox.setOnBeatDetectedCallback(onBeatDetected);


}
   
void loop(){
  
pox.update();
    
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {

    bpm = pox.getHeartRate();
    spo = pox.getSpO2();
    bpmku = bpm;
       
    lcd.setCursor(0,1);
    lcd.print("B/S:");
    lcd.print(pox.getHeartRate());
    lcd.print("/");
    lcd.print(pox.getSpO2());
    lcd.print("     ");
       
    tsLastReport = millis();
}

mlx.begin();
TargetC = mlx.readObjectTempC();
suhunya = TargetC;

lcd.setCursor(0,0);
lcd.print("T: ");
lcd.print(suhunya);
lcd.print(" C   ");


if((bpm > 50)&&(spo > 0)){ 
 Blynk.run();
 timer.run();
}
 
delay(1);
}


void sendSensor()
{
 Blynk.virtualWrite(V3, suhunya);
 Blynk.virtualWrite(V4, bpm);
 Blynk.virtualWrite(V5, spo);
 delay(1000);
 digitalWrite(pinreset,LOW);
}



d. VIDEO HASILNYA




Monitor Suhu Tubuh, BPM dan SPO2 Nodemcu ESP8266 Sensor MLX90614 dan Max30100/30102

Monitor Suhu Tubuh, BPM dan SPO2 Nodemcu ESP8266 Sensor MLX90614 dan Max30100/30102 


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor 3 parameter yaitu suhu tubuh, BPM dan SPO2 secara bersamaan dengan menggunakan sensor mlx90614 dan max30100/30102. mikrokontroller yang dipakai yaitu nodemcu esp8266. berikut adalah program dan komponennya.



a. Sistem Keseluruhan





b. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_MLX90614.h>  
#include <MAX30100_PulseOximeter.h>
#define REPORTING_PERIOD_MS 5000
#include "MAX30100.h" //library sensor

LiquidCrystal_I2C lcd(0x27,16,2); //library lcd

MAX30100* pulseOxymeter;   //library

int cacah; //membuat variabel
int spo;
float bpm;
Adafruit_MLX90614 mlx = Adafruit_MLX90614();

float TargetC;
int dataadc;
int suhunya;
int bpmku;

PulseOximeter pox;

uint32_t tsLastReport = 0;
String hrData = "";
void onBeatDetected()
{
//    Serial.println("Beat!");
}

void setup() {
  Wire.begin();
  mlx.begin();
  Serial.begin(9600);
  lcd.begin();
  lcd.clear();

   //Serial.print("Initializing pulse oximeter..");
 
    if (!pox.begin()) {
        //Serial.println("FAILED");
        for(;;);
    } else {
        //Serial.println("SUCCESS");
    }
 
   pox.setIRLedCurrent(MAX30100_LED_CURR_11MA);
   pox.setOnBeatDetectedCallback(onBeatDetected);
 
}
   
void loop(){
 
   pox.update();
    
   if (millis() - tsLastReport > REPORTING_PERIOD_MS) {

       bpm = pox.getHeartRate();
       spo = pox.getSpO2();
       bpmku = bpm;
       
       lcd.setCursor(0,1);
       lcd.print("B/S:");
       lcd.print(pox.getHeartRate());
       lcd.print("/");
       lcd.print(pox.getSpO2());
       lcd.print("     ");
       
    tsLastReport = millis();
}

mlx.begin();
TargetC = mlx.readObjectTempC();
suhunya = TargetC;

lcd.setCursor(0,0);
lcd.print("T: ");
lcd.print(suhunya);
lcd.print(" C   ");

delay(1);
}



c. VIDEO HASILNYA





Kendali Servo dan Led via Bluetooth Handphone / Smartphone

Kendali Servo dan Led via Bluetooth Handphone / Smartphone


         Pada kesempatan kali ini saya akan menjelaskan mengenai sebuah alat yang dapat mengendalikan 6 buah servo dan dua buah led dengan menggunakan bluetooth dan device handphone / smartphone. jadi alat ini menggunakan arduino nano sebagai kendalinya dan modul HC-05 untuk koneksi bluetooth. untuk lebih jelasnya berikut adalah koding dan komponennya.



a. Komponen Penyusun 




b. Aplikasi Handphone





c. Program Arduino IDE

#include<Wire.h>
#include <Servo.h> 

int datain;
int a1 = 0;
int a2 = 0;
int a3 = 0;
int a4 = 0;
int a5 = 0;
int a6 = 0;
int a7 = 0;
int a8 = 0;

Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;
Servo myservo6;


void setup(){
Serial.begin(9600);  
myservo1.attach(3);
myservo1.write(100);
myservo2.attach(5);
myservo2.write(100);
myservo3.attach(6);
myservo3.write(100);
myservo4.attach(9);
myservo4.write(100);
myservo5.attach(10);
myservo5.write(100);
myservo6.attach(11);
myservo6.write(100);
pinMode(8,OUTPUT);
pinMode(12,OUTPUT);
digitalWrite(8,HIGH);
digitalWrite(12,HIGH);
}


void loop(){  

  
if (Serial.available() > 0)
{
  datain = Serial.parseInt();
  Serial.println(datain);

//==========================================

if ((datain == 100)&&(a1 == 1))
{
a1 = 0;
datain = 0;
}

if ((datain == 100)&&(a1 == 0))
{
a1 = 1;
datain = 0;
}

//==========================================

//==========================================

if ((datain == 200)&&(a2 == 1))
{
a2 = 0;
datain = 0;
}

if ((datain == 200)&&(a2 == 0))
{
a2 = 1;
datain = 0;
}

//==========================================

//==========================================

if ((datain == 300)&&(a3 == 1))
{
a3 = 0;
datain = 0;
}

if ((datain == 300)&&(a3 == 0))
{
a3 = 1;
datain = 0;
}

//==========================================

//==========================================

if ((datain == 400)&&(a4 == 1))
{
a4 = 0;
datain = 0;
}

if ((datain == 400)&&(a4 == 0))
{
a4 = 1;
datain = 0;
}

//==========================================

//==========================================

if ((datain == 500)&&(a5 == 1))
{
a5 = 0;
datain = 0;
}

if ((datain == 500)&&(a5 == 0))
{
a5 = 1;
datain = 0;
}

//==========================================

//==========================================

if ((datain == 600)&&(a6 == 1))
{
a6 = 0;
datain = 0;
}

if ((datain == 600)&&(a6 == 0))
{
a6 = 1;
datain = 0;
}

//==========================================

//==========================================

if ((datain == 700)&&(a7 == 1))
{
digitalWrite(8,LOW);
a7 = 0;
datain = 0;
}

if ((datain == 700)&&(a7 == 0))
{
digitalWrite(8,HIGH);
a7 = 1;
datain = 0;
}

//==========================================

//==========================================

if ((datain == 800)&&(a8 == 1))
{
digitalWrite(12,LOW);
a8 = 0;
datain = 0;
}

if ((datain == 800)&&(a8 == 0))
{
digitalWrite(12,HIGH);
a8 = 1;
datain = 0;
}

//==========================================

}


if(a1 == 1){
  myservo1.write(100);
  delay(1000);
  myservo1.write(150);
  delay(1000);
}

if(a2 == 1){
  myservo2.write(100);
  delay(1000);
  myservo2.write(150);
  delay(1000);
}

if(a3 == 1){
  myservo3.write(100);
  delay(1000);
  myservo3.write(150);
  delay(1000);
}

if(a4 == 1){
  myservo4.write(100);
  delay(1000);
  myservo4.write(150);
  delay(1000);
}

if(a5 == 1){
  myservo5.write(100);
  delay(1000);
  myservo5.write(150);
  delay(1000);
}

if(a6 == 1){
  myservo6.write(100);
  delay(1000);
  myservo6.write(150);
  delay(1000);
}

}



d. VIDEO HASILNYA





MEMBUAT TIMBANGAN DIGITAL DAN PENGUKUR TINGGI / PANJANG BADAN ATAU BENDA

MEMBUAT TIMBANGAN DIGITAL DAN PENGUKUR TINGGI / PANJANG BADAN ATAU BENDA
 

        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk mengukur berat badan bayi atau lainnya dengan menggunakan mikrokontroller arduino. Alat ini menggunakan loadcell sehingga membutuhkan amplifier untuk merubah nilai tegangan menjadi data digital sehingga mudah untuk dibaca arduino, amplifier yang dipakai yaitu modul hx711 yang mana memiliki harga yang terjangkau. untuk lebih jelasnya berikut adalah komponen dan kodingnya.
 
 
 
a. Arduino Uno
 

 

b. Timbangan loadcell dan HX711




c. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include "HX711.h"

// HX711.DOUT    - pin #4
// HX711.PD_SCK    - pin #5

#define trigPin 6
#define echoPin 7

HX711 scale(4, 5);       

long duration, distance;
float tera = 0;
int berat;
float fix;
int x;
int jarak;
int sp = 30;

void setup() {

  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
 
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
 
  scale.set_scale(2280.f);       // this value is obtained by calibrating the scale with known weights; see the README for details
  scale.tare();                  // reset the scale to 0

   lcd.setCursor (0,0);
   lcd.print ("LOADING... ");
   delay(5000);
   lcd.clear();
}

void loop() {

  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  jarak = sp - distance;
 
  berat = scale.get_units(10) * -1;
  fix = (berat - 0.4233)/0.1586;

 if (fix < 0 ) {
  fix = 0;
  }

 if(jarak < 0){
  jarak = 0;
  }  
 
   lcd.setCursor (0,0);
   lcd.print ("Berat= ");
   lcd.print (fix);
   lcd.print (" gr  ");
   
   lcd.setCursor (0,1);
   lcd.print ("Tinggi= ");
   lcd.print (distance);
   lcd.print (" cm   ");
   
  scale.power_down();                  
  delay(200);
  scale.power_up();

}



d. Hasil Kalibrasi 





e. VIDEO HASILNYA



 
 

Monitor Tekanan Pressure dan Flow Air Fitur PID Sebagai Stabilisator Aliran Air

Monitor Tekanan Pressure  dan Flow Air Fitur PID Sebagai Stabilisator Aliran Air


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor tekanan air dan flow aliran air yang mana jumlahnya tiap-tiap sensor berjumlah 4 buah. alat  ini memiliki fitur yaitu pid yang digunakan untuk menstabilkan aliran air sehingga aliran bisa dikendalikan dengan pemantauan melalui sensor tekanan. 



a. Gambar Sistem Keseluruhan




b. Program Arduno IDE

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

Servo myservo;
//=====================================================
byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin       = 2;
float calibrationFactor = 4.5;
volatile byte pulseCount; 
unsigned int frac;
float flowRate;
unsigned int flowMilliLitres;
float totalMilliLitres;
unsigned long oldTime;

//====================================================

byte sensorInterrupt1 = 1;  // 1 = digital pin 3
byte sensorPin1       = 3;
float calibrationFactor1 = 4.5;
volatile byte pulseCount1; 
unsigned int frac1;
float flowRate1;
unsigned int flowMilliLitres1;
float totalMilliLitres1;
unsigned long oldTime1;

//======================================================

byte sensorInterrupt2 = 4;  // 4 = digital pin 19
byte sensorPin2       = 19;
float calibrationFactor2 = 4.5;
volatile byte pulseCount2; 
unsigned int frac2;
float flowRate2;
unsigned int flowMilliLitres2;
float totalMilliLitres2;
unsigned long oldTime2;

//==========================================================
byte sensorInterrupt3 = 5;  // 5 = digital pin 18
byte sensorPin3       = 18;
float calibrationFactor3 = 4.5;
volatile byte pulseCount3; 
unsigned int frac3;
float flowRate3;
unsigned int flowMilliLitres3;
float totalMilliLitres3;
unsigned long oldTime3;

int dataadc1;
int x1;
float v1;
float kpa1;

int dataadc2;
int x2;
float v2;
float kpa2;

int dataadc3;
int x3;
float v3;
float kpa3;

int dataadc4;
int x4;
float v4;
float kpa4;

float kp = 1.15;
float ki = 0.67;
float kd = 0.15;

float p,i,d,pid;
float error,errorx,sumerr;
float sp = 10.0; //setpoint tekanan 10 psi

float pressure_pascal1;
float pressure_bar1;

float pressure_pascal2;
float pressure_bar2;

float pressure_pascal3;
float pressure_bar3;

float pressure_pascal4;
float pressure_bar4;

float psi1;
float psi2;
float psi3;
float psi4;
float rasio;
int relay = 4;
int buzzer = 5;

//pwm servo buka = 0 dan tutup maksimal = 60 

void setup() {

  pinMode(relay, OUTPUT);
  pinMode(buzzer, OUTPUT);
  digitalWrite(relay,LOW);
  digitalWrite(buzzer,HIGH);
  
  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);

  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;

  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);

  pinMode(sensorPin1, INPUT);
  digitalWrite(sensorPin1, HIGH);

  pulseCount1        = 0;
  flowRate1          = 0.0;
  flowMilliLitres1   = 0;
  totalMilliLitres1  = 0;
  oldTime1           = 0;

  attachInterrupt(sensorInterrupt1, pulseCounter1, FALLING);
   
  pinMode(sensorPin2, INPUT);
  digitalWrite(sensorPin2, HIGH);

  pulseCount2        = 0;
  flowRate2          = 0.0;
  flowMilliLitres2   = 0;
  totalMilliLitres2  = 0;
  oldTime2           = 0;

  attachInterrupt(sensorInterrupt2, pulseCounter2, FALLING);
 
  pinMode(sensorPin3, INPUT);
  digitalWrite(sensorPin3, HIGH);

  pulseCount3        = 0;
  flowRate3         = 0.0;
  flowMilliLitres3   = 0;
  totalMilliLitres3  = 0;
  oldTime3           = 0;

  attachInterrupt(sensorInterrupt3, pulseCounter3, FALLING);
 
  Serial.begin(9600); 
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  myservo.attach(9);
  myservo.write(100);
}


void loop() {
 
if((millis() - oldTime) > 1000)    // Only process counters once per second
  {
    detachInterrupt(sensorInterrupt);
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    oldTime = millis();
    flowMilliLitres = (flowRate / 60) * 1000;
    totalMilliLitres += flowMilliLitres;
    pulseCount = 0;
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
  }

    if((millis() - oldTime1) > 1000)    // Only process counters once per second
  {
    detachInterrupt(sensorInterrupt1);
    flowRate1 = ((1000.0 / (millis() - oldTime1)) * pulseCount1) / calibrationFactor1;
    oldTime1 = millis();
    flowMilliLitres1 = (flowRate1 / 60) * 1000;
    totalMilliLitres1 += flowMilliLitres1;
    pulseCount1 = 0;
    attachInterrupt(sensorInterrupt1, pulseCounter1, FALLING);
  }
 
 if((millis() - oldTime2) > 1000)    // Only process counters once per second
  {

    detachInterrupt(sensorInterrupt2);
    flowRate2 = ((1000.0 / (millis() - oldTime2)) * pulseCount2) / calibrationFactor2;
    oldTime2 = millis();
    flowMilliLitres2 = (flowRate2 / 60) * 1000;
    totalMilliLitres2 += flowMilliLitres2;
    pulseCount2 = 0;
    attachInterrupt(sensorInterrupt2, pulseCounter2, FALLING);
  }

   if((millis() - oldTime3) > 1000)    // Only process counters once per second
  {
    detachInterrupt(sensorInterrupt3);
    flowRate3 = ((1000.0 / (millis() - oldTime3)) * pulseCount3) / calibrationFactor3;
    oldTime3 = millis();
    flowMilliLitres3 = (flowRate3 / 60) * 1000;
    totalMilliLitres3 += flowMilliLitres3;
    pulseCount3 = 0;
    attachInterrupt(sensorInterrupt3, pulseCounter3, FALLING);
  }

rasio = (flowRate - flowRate1) / flowRate;
rasio = rasio * 100.0;

if(rasio >= 20){
  digitalWrite(relay,HIGH);
  digitalWrite(buzzer,LOW);  
}
else{
  digitalWrite(relay,LOW);
  digitalWrite(buzzer,HIGH);
}


  x1 = analogRead(A0);
  v1 = x1*(5.0/1023.0);
  psi1 = 250 * (v1/5.0);
  psi1 = psi1 - 25;

  x2 = analogRead(A1);
  v2 = x2*(5.0/1023.0);
  psi2 = 250 * (v2/5.0);
  psi2 = psi2 - 25;
     
  x3 = analogRead(A2);
  v3 = x3*(5.0/1023.0);
  psi3 = 250 * (v3/5.0);
  psi3 = psi3 - 25;
       
  x4 = analogRead(A3);
  v4 = x4*(5.0/1023.0);
  psi4 = 250 * (v4/5.0);
  psi4 = psi4 - 25;

if(psi1 < 0){
  psi1 = 0;
}
if(psi2 < 0){
  psi2 = 0;
}
if(psi3 < 0){
  psi3 = 0;
}
if(psi4 < 0){
  psi4 = 0;
}

  error = sp - psi2;
  p = error * kp;
  sumerr = error + errorx;
  i = ki * sumerr;
  d = kd * (error - errorx) ;
  pid = p + i + d;
  pid = 60 - pid;
  
  if(pid < 0){
  pid = 0;
  }
 
  if(pid > 60){
  pid = 60;
  }

  myservo.write(pid);
       
  lcd.setCursor(0,0);
  lcd.print("FP1=");
  lcd.print(flowRate,1);
  lcd.print("/");
  lcd.print(psi1,1);
  lcd.print(" ");
  lcd.print(rasio,1);
  lcd.print("%     ");
  
  lcd.setCursor(0,1);
  lcd.print("FP2=");
  lcd.print(flowRate1,1);
  lcd.print("/");
  lcd.print(psi2,1);
  lcd.print(" ");
  lcd.print(pid,1);
  lcd.print("      ");

  lcd.setCursor(0,2);
  lcd.print("FP3=");
  lcd.print(flowRate2,1);
  lcd.print("/");
  lcd.print(psi3,1);
  lcd.print("  ");
  
  lcd.setCursor(0,3);
  lcd.print("FP4=");
  lcd.print(flowRate3,1);
  lcd.print("/");
  lcd.print(psi4,1);
  lcd.print("  ");


errorx = error;
  
delay(200);
}


void pulseCounter()
{
  pulseCount++;
}

void pulseCounter1()
{
  pulseCount1++;
}

void pulseCounter2()
{
  pulseCount2++;
}

void pulseCounter3()
{
  pulseCount3++;
}




c. VIDEO HASILNYA





Alat Pendeteksi Kebakaran Sensor Asap dan Api Bascom AVR

Alat Pendeteksi Kebakaran Sensor Asap dan Api Bascom AVR 


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk pendeteksi kebakaran dengan menggunakan ATMega16 sebagai mikrokontrollernya. alat ini juga dilengkapi sensor smoke atau asap yang digunakan untuk pendeteksi asap jika terjadi kebakaran, selain itu juga ada sensor api yang mana jika terdapat api maka akan membunyikan alarm / buzzer dan menyalakan led sebagai indikatornya. untuk lebih jelasnya berikut komponen dan programnya.  



a. Minimum System ATMega16




b. Sensor Asap MQ-2




c. Sensor Api 





d. Program Bascom AVR

$regfile = "m16def.dat"
$crystal = 8000000

Config Lcdpin = Pin , Rs = Portc.0 , E = Portc.1 , Db4 = Portc.2
Config Lcdpin = Pin , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5
Config Lcd = 16 * 2
Cursor Off
Cls

'led
Ddrd.2 = 1
Ddrd.3 = 1
Ddrd.4 = 1

'buzzer
Ddrd.5 = 1
Portd.5 = 1

Led1 Alias Portd.2
Led2 Alias Portd.3
Led3 Alias Portd.4

Buzzer Alias Portd.5

Led1 = 0
Led2 = 0
Led3 = 0

Config Adc = Single , Prescaler = Auto , Reference = Avcc

Dim Gas As Word
Dim Volt1 As Single
Dim Api As Word
Dim Volt2 As Single

Cls
Cursor Off

Start Adc

Do

Gas = Getadc(0)
Api = Getadc(1)

Upperline
Lcd "Asap= " ; Gas ; "   "
Lowerline
Lcd "Api= " ; Api ; "   "

If Gas > 500 And Api < 800 Then
Led1 = 0
Led3 = 1
Buzzer = 0
End If

If Gas < 500 And Api > 800 Then
Led1 = 1
Led3 = 0
Buzzer = 1
End If

Waitms 100
Loop



e. VIDEO HASILNYA




Monitor Peak Flow / Peak Expiratory Flow Rate (PEF) Sensor Water / Air Flow untuk Penyakit Asma

Monitor Peak Flow / Peak Expiratory Flow Rate (PEF) Sensor Water / Air Flow untuk Deteksi Penyakit Asma


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa memonitor flow rate untuk deteksi penyakit asma. jadi alat ini sangatlah sederhana karena menggunakan satu sensor yaitu water flow sensor, jadi data yang diambil yaitu flow rate hembusan pertama lalu hembusan kedua setelah itu dimasukkan kedalam rumus sehingga didapatkanlah hasilnya. untuk lebih jelasnya berikut koding dan komponennya.



a. Arduino Mega




b. Sensor Flow




c. LCD 20x4 + I2C





d. Program Aduino IDE

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

byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin       = 2;

float calibrationFactor = 4.5;
int flowMilliLitres1;
int flowMilliLitres2;
int FLMa;
int FLMb;
volatile byte pulseCount;

unsigned int  frac;
float flowRate;
unsigned int flowMilliLitres;
float totalMilliLitres;
int tbmulai = 12;
int tbmulaix;

unsigned long oldTime;

unsigned long start_times[100];
unsigned long stop_times[100];
unsigned long values[100];

int i1;
float z1;
int i2;
float z2;
int counter1;
int counter2;
float rumus;

void setup() {
  
  //lcd.init();
  //lcd.backlight(); 
  lcd.begin();
  pinMode(tbmulai, INPUT_PULLUP);

  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);

  lcd.setCursor(4, 0);
  lcd.print("ALAT");
  lcd.setCursor(1, 1);
  lcd.print("ALAT UKUR ASMA");
  delay(3000);
  lcd.clear();
  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;
  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}

void loop() {

tbmulaix = digitalRead(tbmulai);  

if(tbmulaix == 0){
  z1 = 0;
  z2 = 0;
  lcd.clear();
  mulai1(); //berlangsung 10 detik
  mulai2(); //berlangsung 10 detik 
}

if(z1 > z2){
rumus = (z1 - z2) / z1;
rumus = rumus * 100.0; 
lcd.setCursor(0, 3);
lcd.print("FL1 > FL2");
}

if(z2 > z1){
rumus = (z2 - z1) / z2;
rumus = rumus * 100.0; 
lcd.setCursor(0, 3);
lcd.print("FL1 < FL2");
}

  lcd.setCursor(0, 0);
  lcd.print("Hasil= ");
  lcd.print(rumus);
  lcd.print("  % ");
  lcd.setCursor(0, 1);
  lcd.print("FL1= ");
  lcd.print(z1);
  lcd.print("   ");
  lcd.setCursor(0, 2);
  lcd.print("FL2= ");
  lcd.print(z2);
  lcd.print("   ");  

delay(200);
}

void mulai1(){

counter1++; //countup

  //mencari nilai tertinggi
  for(i1=0;i1<100;i1++) {
    start_times[i1] = micros();

  //aktifkan sensor flow
  if((millis() - oldTime) > 1000)
  {
    detachInterrupt(sensorInterrupt);
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    oldTime = millis();
    flowMilliLitres1 = (flowRate / 60) * 1000;
    totalMilliLitres += flowMilliLitres1;
    pulseCount = 0;   
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
  }

  //nilai dimasukkan ke values
  values[i1] = flowMilliLitres1;            

  //bandingkan nilai yg terbesar
  if (values[i1] >= z1) {
  z1 = values[i1]; //nilai terbesar dimasukkan ke z1
  }
   
    stop_times[i1] = micros(); //stop pengukuran
  }

  //menampilkan nilai tertinggi ke lcd atas
  lcd.setCursor(0, 0);
  lcd.print("FL1= ");
  lcd.print(z1);
  lcd.print("  mL/s ");

if(counter1 > 1000){ //jika sudah 10 detik maka selesai 1000 * 10ms = 10000 ms
counter1 = 0; //reset counter  
return; //kembali ke loop
}

delay(10); //waktu looping
mulai1();    
}

void mulai2(){

counter2++; //countup

  //mencari nilai tertinggi
  for(i2=0;i2<100;i2++) {
    start_times[i2] = micros();

  //aktifkan sensor flow  
  if((millis() - oldTime) > 1000)
  {
    detachInterrupt(sensorInterrupt);
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    oldTime = millis();
    flowMilliLitres2 = (flowRate / 60) * 1000;
    totalMilliLitres += flowMilliLitres2;
    pulseCount = 0;  
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
  }
  
  //nilai dimasukkan ke values
  values[i2] = flowMilliLitres2;            

  //bandingkan nilai yg terbesar
  if (values[i2] >= z2) {
  z2 = values[i2]; //nilai terbesar dimasukkan ke z1
  }
 
    stop_times[i2] = micros(); //stop pengukuran
  }

  //menampilkan hasilnya ke lcd bawah
  lcd.setCursor(0, 1);
  lcd.print("FL2= ");
  lcd.print(z2);
  lcd.print("  mL/s ");

  if(counter2 > 1000){ //jika sudah 10 detik maka selesai 10ms x 1000 = 10000 ms
  counter2 = 0; //reset nilai counter 
  lcd.clear(); //clear nilai lcd
  delay(1000); //delay 1 detik
  return; //kembali ke void loop
  }

  delay(10); //waktu sampli 10ms
  mulai2();    
}

//counter nilai flow
void pulseCounter()
{
  pulseCount++;
}




e. VIDEO HASILNYA






Cara Kalibrasi dengan Metode Regresi Linier

Cara Kalibrasi dengan Metode Regresi Linier


          Pada kesempatan kali ini saya akan menjelaskan mengenai sebuah metode untuk kalibrasi sebuah sensor yang memiliki output linier sehingga jika ingin merubah parameter sensor dari nilai adc ke nilai yang terukur bisa mengunakan metode ini. yang diperlukan untuk melakukan kalibrasi dengan metode ini yaitu kalibrator atau sample yang telah terkalibrasi dan sebuah sensor yang sudah di program untuk menampilkan nilai adc. kemudian siapkan software ms.excel dan catat hasil pengukurannya. untuk lebih jelasnya berikut adalah program dan hasilnya.


a. Program Menampilkan Nilai ADC
  
#include <Wire.h>  
#include <LiquidCrystal_I2C.h>  

//LiquidCrystal_I2C lcd(0x3F, 16, 2);
LiquidCrystal_I2C lcd(0x27, 16, 2);

int dataadc;

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

void loop(){

 dataadc = analogRead(A0);

 lcd.setCursor(0,0);
 lcd.print("PH= ");
 lcd.print(dataadc);
 lcd.print("    ");

 delay(200);
}


         Setelah program tersebut diupload maka yang harus dilakukan yaitu mencatat nilai hasil adc yang tertera pada lcd, untuk program diatas fungsinya untuk menampilkan nilai adc pada lcd i2c namun jika ingin menggunakan serial monitor juga bisa yaitu dengan menggunakan library di arduino yaitu AnalogReadSerial seperti cara berikut ini. setelah diupload maka dapatlah rumus pada ms.excel setelah itu masukkan rumus tersebut ke Arduino.




b.  Hasil Pencatatan ADC




c. Program Arduino setelah mendapatkan rumus

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

//LiquidCrystal_I2C lcd(0x3F, 16, 2);
LiquidCrystal_I2C lcd(0x27, 16, 2);

int dataadc;
float ph;

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

void loop(){

 dataadc = analogRead(A0);
 dataadc = analogRead(A0);
 ph = (dataadc + 11.026)/58.009;

 lcd.setCursor(0,0);
 lcd.print("PH= ");
 lcd.print(ph);
 lcd.print("    ");

 delay(200);
}



d. VIDEO HASILNYA





Monitor PH dan Suhu dengan Fitur Datalogger dan Kalibrasi

Monitor PH dan Suhu dengan Fitur Datalogger dan Kalibrasi 


           Pada kesempata kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengukur PH dan suhu dengan fitur penyimpanan data di microSD card, alat ini memliki fitur self adjustment atau self calibration dengan menggunakan 4 buah tombol sebagai input nilainya. jadi jika nilai yg tertampil kuang tepat maka bisa dilakukan kalibrasi dengan menggunakan input 4 buah tombol tersebut. untuk lebih jelasnya berikut adalah komponen dan programnya. 


a. Arduino Uno




b. Sensor PH 




c. Sensor Suhu DS18B20




d. Modul RTC





e. Modul MicroSD Card




f. Hasil Penyimpanan MicroSD Card



g. Kalibrasi PH





h. Program Arduino IDE

#include <OneWire.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <DS3231.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

DS3231  rtc(SDA, SCL);
OneWire  ds(7);// on pin 7 (a 4.7K resistor is necessary)

int suhu;
int dataadc;
float ph;

int btset = 2;
int btup = 3;
int btdown = 5;
int btok = 6;

int btsetx;
int btupx;
int btdownx;
int btokx;
int layar;
float kal;
int positionCounter; 

File myFile;

// change this to match your SD shield or module;
//     Arduino Ethernet shield: pin 4
//     Adafruit SD shields and modules: pin 10
//     Sparkfun SD shield: pin 8
const int chipSelect = 4;

void setup() {
   
Serial.begin(9600);

  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
   pinMode(SS, OUTPUT);
   
  if (!SD.begin(chipSelect)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

lcd.begin(); //setting lcd
lcd.clear(); //clear screen
lcd.noCursor(); //tidak ada kursor
rtc.begin();

//The following lines can be uncommented to set the date and time
//rtc.setDOW(SUNDAY);     // Set Day-of-Week to SUNDAY
//rtc.setTime(15, 46, 0);     // Set the time to 12:00:00 (24hr format)
//rtc.setDate(3, 4, 2022);   // Set the date to January 1st, 2014
 
pinMode(btset,INPUT_PULLUP); 
pinMode(btup,INPUT_PULLUP); 
pinMode(btdown,INPUT_PULLUP); 
pinMode(btok,INPUT_PULLUP); 

}

void loop(void) {
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;

  if ( !ds.search(addr)) {
    ds.reset_search();
    delay(250);
    return;
  }

  for( i = 0; i < 8; i++) {

  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
      return;
  }

  switch (addr[0]) {
    case 0x10:
      type_s = 1;
      break;
    case 0x28:
      type_s = 0;
      break;
    case 0x22:
      type_s = 0;
      break;
    default:
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end

  delay(1000);     // maybe 750ms is enough, maybe not

  present = ds.reset();
  ds.select(addr);  
  ds.write(0xBE);         // Read Scratchpad

  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
  }

  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms

 
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms

  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  suhu = celsius;

dataadc = analogRead(A0);
ph = (dataadc + 11.026)/58.009;
ph = ph + kal;

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

if(btokx == 0){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("SAVING.... ");  
simpan(); 
delay(3000);
lcd.clear(); 
}

if(btsetx == 0){
lcd.clear(); 
delay(200);
setting(); 
lcd.clear(); 
}

if(btupx == 0){
layar++;  
}

if(layar > 1){
layar = 0;  
}

if(layar == 0){
  lcd.setCursor(0,0);
  lcd.print("T: ");
  lcd.print(suhu);
  lcd.print(" C      ");
  lcd.setCursor(0,1);
  lcd.print("PH: ");
  lcd.print(ph);
  lcd.print("       ");
}

if(layar == 1){
  lcd.setCursor(0,0);
  lcd.print(rtc.getDateStr());
  lcd.print("      ");
  lcd.setCursor(0,1);
  lcd.print(rtc.getTimeStr());
  lcd.print("       ");
}  
    
  delay(100);
}

void setting(){

dataadc = analogRead(A0);
ph = (dataadc + 11.026)/58.009;
ph = ph + kal;

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

lcd.setCursor(0,0);
lcd.print("Kal PH: ");
lcd.print(ph);
lcd.print("     ");  
lcd.setCursor(0,1);
lcd.print("Kal: ");
lcd.print(kal);
lcd.print("   "); 

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

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

if(btokx == 0){
delay(200);  
return;  
}

setting();
}


void simpan(){
 
while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  //pinMode(10, OUTPUT);

  if (!SD.begin(chipSelect)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    myFile.print("Tanggal=");
    myFile.print(rtc.getDateStr()); 
    myFile.print("  Waktu=");
    myFile.println(rtc.getTimeStr()); 
    myFile.print("PH= ");
    myFile.print(ph);
    myFile.print("  Suhu= ");
    myFile.println(suhu);
    myFile.println();
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

}



i. VIDEO HASILNYA