Translate

Monitor Suhu dan Berat Fuzzy Logic Mamdani IOT Firebase ESP32 (thermocouple tipe K dan Hx711)

Monitor Suhu dan Berat Fuzzy Logic Mamdani IOT Firebase ESP32 (thermocouple tipe K dan Hx711)

      
         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengukur suhu dan berat dengan menggunakan thermocouple tipe K dan loadcell + Hx711. alat ini dimonitor dengan IOT Firebase dan metode Fuzzy logic Mamdani. untuk lebih jelasnya berikut adalah koding dan komponennya.


1. Komponen



2. Interface Firebase



3. Program Arduino IDE

#include <Fuzzy.h>
#include <Wire.h>
#include <max6675.h> 
#include "HX711.h"
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <FirebaseClient.h>

int thermoDO = 25; //bisa juga S0
int thermoCS = 32;
int thermoCLK = 33; //bisa juga SCK

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

int suhunya;
int beratnya;
int waktunya;

// HX711.DOUT    - pin #26
// HX711.PD_SCK    - pin #27

HX711 scale(26, 27);   
float tera = 0;
int berat;
float fix;
int x;
float output1;

// Network and Firebase credentials
#define WIFI_SSID "hotspothpku"
#define WIFI_PASSWORD "123456789"

#define Web_API_KEY "hjhkjhkgjygjfhtfhgfrert34fdgfgfxdxfd657f"
#define DATABASE_URL "https://alamatdaratabseyangdipakai-pilihdireatimedatabase/"
#define USER_EMAIL "alamatemail pengguna"
#define USER_PASS "paswordemailnya"

// User function
void processData(AsyncResult &aResult);

// Authentication
UserAuth user_auth(Web_API_KEY, USER_EMAIL, USER_PASS);

// Firebase components
FirebaseApp app;
WiFiClientSecure ssl_client;
using AsyncClient = AsyncClientClass;
AsyncClient aClient(ssl_client);
RealtimeDatabase Database;

// Timer variables for sending data every 10 seconds
unsigned long lastSendTime = 0;
const unsigned long sendInterval = 10000; // 10 seconds in milliseconds

// Variables to send to the database
int intValue = 0;
float floatValue = 0.01;
String stringValue = "";

Fuzzy *fuzzy = new Fuzzy();

// FuzzyInputn suhu
FuzzySet *light = new FuzzySet(0, 0, 195, 212);
FuzzySet *medium = new FuzzySet(203, 200, 200, 221);
FuzzySet *dark = new FuzzySet(212, 223, 223, 230);

// FuzzyInput berat
FuzzySet *sedikit = new FuzzySet(0, 0, 100, 100);
FuzzySet *banyak = new FuzzySet(100, 200, 200, 250);

// FuzzyInput durasi
FuzzySet *singkat = new FuzzySet(0, 0, 8, 11);
FuzzySet *normal = new FuzzySet(9, 11, 11, 13);
FuzzySet *lama = new FuzzySet(11, 13, 15, 15);

// FuzzyOutput
FuzzySet *lambat = new FuzzySet(0, 0, 50, 75);
FuzzySet *sedang = new FuzzySet(60, 75, 75, 90);
FuzzySet *cepat = new FuzzySet(75, 90, 100, 100);

void setup()
{

  Serial.begin(115200);

   // Connect to Wi-Fi
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("Connecting to Wi-Fi");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(300);
  }
  Serial.println();
  
  // Configure SSL client
  ssl_client.setInsecure();
  //ssl_client.setConnectionTimeout(1000);
  ssl_client.setHandshakeTimeout(5);
  
  // Initialize Firebase
  initializeApp(aClient, app, getAuth(user_auth), processData, "🔐 authTask");
  app.getApp<RealtimeDatabase>(Database);
  Database.url(DATABASE_URL);
  
  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

   delay(5000);
   
  // FuzzyInput suhu
  FuzzyInput *suhu = new FuzzyInput(1);

  suhu->addFuzzySet(light);
  suhu->addFuzzySet(medium);
  suhu->addFuzzySet(dark);
  fuzzy->addFuzzyInput(suhu);

  // FuzzyInput berat
  FuzzyInput *berat = new FuzzyInput(2);

  berat->addFuzzySet(sedikit);
  berat->addFuzzySet(banyak);
  fuzzy->addFuzzyInput(berat);

  // FuzzyInput durasi
  FuzzyInput *durasi = new FuzzyInput(3);

  durasi->addFuzzySet(singkat);
  durasi->addFuzzySet(normal);
  durasi->addFuzzySet(lama);
  fuzzy->addFuzzyInput(durasi);
  
  // FuzzyOutput 
  FuzzyOutput *pwmout = new FuzzyOutput(1);

  pwmout->addFuzzySet(lambat);
  pwmout->addFuzzySet(sedang);
  pwmout->addFuzzySet(cepat);
  fuzzy->addFuzzyOutput(pwmout);

  // Building FuzzyRule 1
  FuzzyRuleAntecedent *suhuLightAndDurasiSingkat = new FuzzyRuleAntecedent();
  suhuLightAndDurasiSingkat->joinWithAND(light, singkat); 
  FuzzyRuleAntecedent *ifSuhuLightAndDurasiSingkatAndBeratSedikit = new FuzzyRuleAntecedent();
  ifSuhuLightAndDurasiSingkatAndBeratSedikit->joinWithAND(suhuLightAndDurasiSingkat, sedikit);
  FuzzyRuleConsequent *thenPwmoutLambat= new FuzzyRuleConsequent();
  thenPwmoutLambat->addOutput(lambat);
  FuzzyRule *fuzzyRule1 = new FuzzyRule(1, ifSuhuLightAndDurasiSingkatAndBeratSedikit, thenPwmoutLambat);
  fuzzy->addFuzzyRule(fuzzyRule1);

  // Building FuzzyRule 2
  //FuzzyRuleAntecedent *suhuLightAndDurasiSingkat = new FuzzyRuleAntecedent();
  suhuLightAndDurasiSingkat->joinWithAND(light, singkat); 
  FuzzyRuleAntecedent *ifSuhuLightAndDurasiSingkatAndBeratBanyak = new FuzzyRuleAntecedent();
  ifSuhuLightAndDurasiSingkatAndBeratBanyak->joinWithAND(suhuLightAndDurasiSingkat, banyak);
  FuzzyRuleConsequent *thenPwmoutSedang= new FuzzyRuleConsequent();
  thenPwmoutSedang->addOutput(sedang);
  FuzzyRule *fuzzyRule2 = new FuzzyRule(2, ifSuhuLightAndDurasiSingkatAndBeratBanyak, thenPwmoutSedang);
  fuzzy->addFuzzyRule(fuzzyRule2);

  // Building FuzzyRule 3
  FuzzyRuleAntecedent *suhuLightAndDurasiNormal = new FuzzyRuleAntecedent();
  suhuLightAndDurasiNormal->joinWithAND(light, normal); 
  FuzzyRuleAntecedent *ifSuhuLightAndDurasiNormalAndBeratSedikit = new FuzzyRuleAntecedent();
  ifSuhuLightAndDurasiNormalAndBeratSedikit->joinWithAND(suhuLightAndDurasiNormal, sedikit);
  //FuzzyRuleConsequent *thenPwmoutLambat= new FuzzyRuleConsequent();
  thenPwmoutLambat->addOutput(lambat);
  FuzzyRule *fuzzyRule3 = new FuzzyRule(3, ifSuhuLightAndDurasiNormalAndBeratSedikit, thenPwmoutLambat);
  fuzzy->addFuzzyRule(fuzzyRule3);

  // Building FuzzyRule 4
  //FuzzyRuleAntecedent *suhuLightAndDurasiNormal = new FuzzyRuleAntecedent();
  suhuLightAndDurasiNormal->joinWithAND(light, normal); 
  FuzzyRuleAntecedent *ifSuhuLightAndDurasiNormalAndBeratBanyak = new FuzzyRuleAntecedent();
  ifSuhuLightAndDurasiNormalAndBeratBanyak->joinWithAND(suhuLightAndDurasiNormal, banyak);
  //FuzzyRuleConsequent *thenPwmoutSedang= new FuzzyRuleConsequent();
  thenPwmoutSedang->addOutput(sedang);
  FuzzyRule *fuzzyRule4 = new FuzzyRule(4, ifSuhuLightAndDurasiNormalAndBeratBanyak, thenPwmoutSedang);
  fuzzy->addFuzzyRule(fuzzyRule4);

  // Building FuzzyRule 5
  FuzzyRuleAntecedent *suhuLightAndDurasiLama = new FuzzyRuleAntecedent();
  suhuLightAndDurasiLama->joinWithAND(light, lama); 
  FuzzyRuleAntecedent *ifSuhuLightAndDurasiLamaAndBeratSedikit = new FuzzyRuleAntecedent();
  ifSuhuLightAndDurasiLamaAndBeratSedikit->joinWithAND(suhuLightAndDurasiLama, sedikit);
  //FuzzyRuleConsequent *thenPwmoutSedang= new FuzzyRuleConsequent();
  thenPwmoutSedang->addOutput(sedang);
  FuzzyRule *fuzzyRule5 = new FuzzyRule(5, ifSuhuLightAndDurasiLamaAndBeratSedikit, thenPwmoutSedang);
  fuzzy->addFuzzyRule(fuzzyRule5);

  // Building FuzzyRule 6
  //FuzzyRuleAntecedent *suhuLightAndDurasiLama = new FuzzyRuleAntecedent();
  suhuLightAndDurasiLama->joinWithAND(light, lama); 
  FuzzyRuleAntecedent *ifSuhuLightAndDurasiLamaAndBeratBanyak = new FuzzyRuleAntecedent();
  ifSuhuLightAndDurasiLamaAndBeratBanyak->joinWithAND(suhuLightAndDurasiLama, banyak);
  FuzzyRuleConsequent *thenPwmoutCepat= new FuzzyRuleConsequent();
  thenPwmoutCepat->addOutput(cepat);
  FuzzyRule *fuzzyRule6 = new FuzzyRule(6, ifSuhuLightAndDurasiLamaAndBeratBanyak, thenPwmoutCepat);
  fuzzy->addFuzzyRule(fuzzyRule6);

  // Building FuzzyRule 7
  FuzzyRuleAntecedent *suhuMediumAndDurasiSingkat = new FuzzyRuleAntecedent();
  suhuMediumAndDurasiSingkat->joinWithAND(medium, singkat); 
  FuzzyRuleAntecedent *ifSuhuMediumAndDurasiSingkatAndBeratSedikit = new FuzzyRuleAntecedent();
  ifSuhuMediumAndDurasiSingkatAndBeratSedikit->joinWithAND(suhuMediumAndDurasiSingkat, sedikit);
  //FuzzyRuleConsequent *thenPwmoutSedang= new FuzzyRuleConsequent();
  thenPwmoutSedang->addOutput(sedang);
  FuzzyRule *fuzzyRule7 = new FuzzyRule(7, ifSuhuMediumAndDurasiSingkatAndBeratSedikit, thenPwmoutSedang);
  fuzzy->addFuzzyRule(fuzzyRule7);

  // Building FuzzyRule 8
  //FuzzyRuleAntecedent *suhuMediumAndDurasiSingkat = new FuzzyRuleAntecedent();
  suhuMediumAndDurasiSingkat->joinWithAND(medium, singkat); 
  FuzzyRuleAntecedent *ifSuhuMediumAndDurasiSingkatAndBeratBanyak = new FuzzyRuleAntecedent();
  ifSuhuMediumAndDurasiSingkatAndBeratBanyak->joinWithAND(suhuMediumAndDurasiSingkat, banyak);
  //FuzzyRuleConsequent *thenPwmoutCepat= new FuzzyRuleConsequent();
  thenPwmoutCepat->addOutput(cepat);
  FuzzyRule *fuzzyRule8 = new FuzzyRule(8, ifSuhuMediumAndDurasiSingkatAndBeratBanyak, thenPwmoutCepat);
  fuzzy->addFuzzyRule(fuzzyRule8);

 // Building FuzzyRule 9
  FuzzyRuleAntecedent *suhuMediumAndDurasiNormal = new FuzzyRuleAntecedent();
  suhuMediumAndDurasiNormal->joinWithAND(medium, normal); 
  FuzzyRuleAntecedent *ifSuhuMediumAndDurasiNormalAndBeratSedikit = new FuzzyRuleAntecedent();
  ifSuhuMediumAndDurasiNormalAndBeratSedikit->joinWithAND(suhuMediumAndDurasiNormal, sedikit);
  //FuzzyRuleConsequent *thenPwmoutSedang= new FuzzyRuleConsequent();
  thenPwmoutSedang->addOutput(sedang);
  FuzzyRule *fuzzyRule9 = new FuzzyRule(9, ifSuhuMediumAndDurasiNormalAndBeratSedikit, thenPwmoutSedang);
  fuzzy->addFuzzyRule(fuzzyRule9);

  // Building FuzzyRule 10
  //FuzzyRuleAntecedent *suhuMediumAndDurasiNormal = new FuzzyRuleAntecedent();
  suhuMediumAndDurasiNormal->joinWithAND(medium, normal); 
  FuzzyRuleAntecedent *ifSuhuMediumAndDurasiNormalAndBeratBanyak = new FuzzyRuleAntecedent();
  ifSuhuMediumAndDurasiNormalAndBeratBanyak->joinWithAND(suhuMediumAndDurasiNormal, banyak);
  //FuzzyRuleConsequent *thenPwmoutCepat= new FuzzyRuleConsequent();
  thenPwmoutCepat->addOutput(cepat);
  FuzzyRule *fuzzyRule10 = new FuzzyRule(10, ifSuhuMediumAndDurasiNormalAndBeratBanyak, thenPwmoutCepat);
  fuzzy->addFuzzyRule(fuzzyRule10);
  
  // Building FuzzyRule 11
  FuzzyRuleAntecedent *suhuMediumAndDurasiLama = new FuzzyRuleAntecedent();
  suhuMediumAndDurasiLama->joinWithAND(medium, lama); 
  FuzzyRuleAntecedent *ifSuhuMediumAndDurasiLamaAndBeratSedikit = new FuzzyRuleAntecedent();
  ifSuhuMediumAndDurasiLamaAndBeratSedikit->joinWithAND(suhuMediumAndDurasiLama, sedikit);
  //FuzzyRuleConsequent *thenPwmoutCepat= new FuzzyRuleConsequent();
  thenPwmoutCepat->addOutput(cepat);
  FuzzyRule *fuzzyRule11 = new FuzzyRule(11, ifSuhuMediumAndDurasiLamaAndBeratSedikit, thenPwmoutCepat);
  fuzzy->addFuzzyRule(fuzzyRule11);

  // Building FuzzyRule 12
  //FuzzyRuleAntecedent *suhuMediumAndDurasiLama = new FuzzyRuleAntecedent();
  suhuMediumAndDurasiLama->joinWithAND(medium, lama); 
  FuzzyRuleAntecedent *ifSuhuMediumAndDurasiLamaAndBeratBanyak = new FuzzyRuleAntecedent();
  ifSuhuMediumAndDurasiLamaAndBeratBanyak->joinWithAND(suhuMediumAndDurasiLama, banyak);
  //FuzzyRuleConsequent *thenPwmoutCepat= new FuzzyRuleConsequent();
  thenPwmoutCepat->addOutput(cepat);
  FuzzyRule *fuzzyRule12 = new FuzzyRule(12, ifSuhuMediumAndDurasiLamaAndBeratBanyak, thenPwmoutCepat);
  fuzzy->addFuzzyRule(fuzzyRule12);

  // Building FuzzyRule 13
  FuzzyRuleAntecedent *suhuDarkAndDurasiSingkat = new FuzzyRuleAntecedent();
  suhuDarkAndDurasiSingkat->joinWithAND(dark, singkat); 
  FuzzyRuleAntecedent *ifSuhuDarkAndDurasiSingkatAndBeratSedikit = new FuzzyRuleAntecedent();
  ifSuhuDarkAndDurasiSingkatAndBeratSedikit->joinWithAND(suhuDarkAndDurasiSingkat, sedikit);
  //FuzzyRuleConsequent *thenPwmoutSedang= new FuzzyRuleConsequent();
  thenPwmoutSedang->addOutput(sedang);
  FuzzyRule *fuzzyRule13 = new FuzzyRule(13, ifSuhuDarkAndDurasiSingkatAndBeratSedikit, thenPwmoutSedang);
  fuzzy->addFuzzyRule(fuzzyRule13);

  // Building FuzzyRule 14
  //FuzzyRuleAntecedent *suhuDarkAndDurasiSingkat = new FuzzyRuleAntecedent();
  suhuDarkAndDurasiSingkat->joinWithAND(dark, singkat); 
  FuzzyRuleAntecedent *ifSuhuDarkAndDurasiSingkatAndBeratBanyak = new FuzzyRuleAntecedent();
  ifSuhuDarkAndDurasiSingkatAndBeratBanyak->joinWithAND(suhuDarkAndDurasiSingkat, banyak);
  //FuzzyRuleConsequent *thenPwmoutCepat= new FuzzyRuleConsequent();
  thenPwmoutCepat->addOutput(cepat);
  FuzzyRule *fuzzyRule14 = new FuzzyRule(14, ifSuhuDarkAndDurasiSingkatAndBeratBanyak, thenPwmoutCepat);
  fuzzy->addFuzzyRule(fuzzyRule14);

 // Building FuzzyRule 15
  FuzzyRuleAntecedent *suhuDarkAndDurasiNormal = new FuzzyRuleAntecedent();
  suhuDarkAndDurasiNormal->joinWithAND(dark, normal); 
  FuzzyRuleAntecedent *ifSuhuDarkAndDurasiNormalAndBeratSedikit = new FuzzyRuleAntecedent();
  ifSuhuDarkAndDurasiNormalAndBeratSedikit->joinWithAND(suhuDarkAndDurasiNormal, sedikit);
  //FuzzyRuleConsequent *thenPwmoutCepat= new FuzzyRuleConsequent();
  thenPwmoutCepat->addOutput(cepat);
  FuzzyRule *fuzzyRule15 = new FuzzyRule(15, ifSuhuDarkAndDurasiNormalAndBeratSedikit, thenPwmoutCepat);
  fuzzy->addFuzzyRule(fuzzyRule15);

  // Building FuzzyRule 16
  //FuzzyRuleAntecedent *suhuDarkAndDurasiNormal = new FuzzyRuleAntecedent();
  suhuDarkAndDurasiNormal->joinWithAND(dark, normal); 
  FuzzyRuleAntecedent *ifSuhuDarkAndDurasiNormalAndBeratBanyak = new FuzzyRuleAntecedent();
  ifSuhuDarkAndDurasiNormalAndBeratBanyak->joinWithAND(suhuDarkAndDurasiNormal, banyak);
  //FuzzyRuleConsequent *thenPwmoutCepat= new FuzzyRuleConsequent();
  thenPwmoutCepat->addOutput(cepat);
  FuzzyRule *fuzzyRule16 = new FuzzyRule(16, ifSuhuDarkAndDurasiNormalAndBeratBanyak, thenPwmoutCepat);
  fuzzy->addFuzzyRule(fuzzyRule16);

 // Building FuzzyRule 17
  FuzzyRuleAntecedent *suhuDarkAndDurasiLama = new FuzzyRuleAntecedent();
  suhuDarkAndDurasiLama->joinWithAND(dark, lama); 
  FuzzyRuleAntecedent *ifSuhuDarkAndDurasiLamaAndBeratSedikit = new FuzzyRuleAntecedent();
  ifSuhuDarkAndDurasiLamaAndBeratSedikit->joinWithAND(suhuDarkAndDurasiLama, sedikit);
  //FuzzyRuleConsequent *thenPwmoutCepat= new FuzzyRuleConsequent();
  thenPwmoutCepat->addOutput(cepat);
  FuzzyRule *fuzzyRule17 = new FuzzyRule(17, ifSuhuDarkAndDurasiLamaAndBeratSedikit, thenPwmoutCepat);
  fuzzy->addFuzzyRule(fuzzyRule17);

  // Building FuzzyRule 18
  //FuzzyRuleAntecedent *suhuDarkAndDurasiLama = new FuzzyRuleAntecedent();
  suhuDarkAndDurasiLama->joinWithAND(dark, lama); 
  FuzzyRuleAntecedent *ifSuhuDarkAndDurasiLamaAndBeratBanyak = new FuzzyRuleAntecedent();
  ifSuhuDarkAndDurasiLamaAndBeratBanyak->joinWithAND(suhuDarkAndDurasiLama, banyak);
  //FuzzyRuleConsequent *thenPwmoutCepat= new FuzzyRuleConsequent();
  thenPwmoutCepat->addOutput(cepat);
  FuzzyRule *fuzzyRule18 = new FuzzyRule(18, ifSuhuDarkAndDurasiLamaAndBeratBanyak, thenPwmoutCepat);
  fuzzy->addFuzzyRule(fuzzyRule18);
  
}

void loop()
{

  suhunya = thermocouple.readCelsius();
  beratnya = scale.get_units(10) * 1;
 
  Serial.print("Suhu: ");
  Serial.print(suhunya);
  Serial.print("|| berat: ");
  Serial.print(beratnya);
  Serial.print("|| waktu: ");
  Serial.println(waktunya);
  
  fuzzy->setInput(1, suhunya);
  fuzzy->setInput(2, beratnya);
  fuzzy->setInput(3, waktunya);
  
  fuzzy->fuzzify();

  Serial.print("Suhu : Light-> ");
  Serial.print(light->getPertinence());
  Serial.print(", Medium-> ");
  Serial.print(medium->getPertinence());
  Serial.print(", Dark-> ");
  Serial.println(dark->getPertinence());

  Serial.print("waktu : singkat-> ");
  Serial.print(singkat->getPertinence());
  Serial.print(", Normal-> ");
  Serial.print(normal->getPertinence());
  Serial.print(", Lama-> ");
  Serial.println(lama->getPertinence());
  
  Serial.print("Berat: Sedikit-> ");
  Serial.print(sedikit->getPertinence());
  Serial.print(",  Banyak-> ");
  Serial.println(banyak->getPertinence());


  output1 = fuzzy->defuzzify(1);

  Serial.println("Output: ");
  Serial.print("PWMOUT: lambat-> ");
  Serial.print(lambat->getPertinence());
  Serial.print(", sedang-> ");
  Serial.print(sedang->getPertinence());
  Serial.print(", cepat-> ");
  Serial.println(cepat->getPertinence());

  Serial.print("HASIL: ");
  Serial.print("PWM: ");
  Serial.println(output1);
  Serial.println("  ");
  Serial.println("  ");

  kirimdata();
   
  delay(1000);
}

void kirimdata(){
  app.loop();

  if (app.ready()){ 

    // Periodic data sending every 10 seconds
    unsigned long currentTime = millis();
    if (currentTime - lastSendTime >= sendInterval){
      // Update the last send time
      lastSendTime = currentTime;
         
      // send an int
      Database.set<int>(aClient, "/test/suhu", suhunya, processData, "RTDB_Send_Int");
      Database.set<int>(aClient, "/test/berat", beratnya, processData, "RTDB_Send_Int");
      Database.set<int>(aClient, "/test/output", output1, processData, "RTDB_Send_Int");
      waktunya = Database.get<int>(aClient, "/test/waktu");
    }
    
  }  
}


void processData(AsyncResult &aResult) {
  if (!aResult.isResult())
    return;

  if (aResult.isEvent())
    Firebase.printf("Event task: %s, msg: %s, code: %d\n", aResult.uid().c_str(), aResult.eventLog().message().c_str(), aResult.eventLog().code());

  if (aResult.isDebug())
    Firebase.printf("Debug task: %s, msg: %s\n", aResult.uid().c_str(), aResult.debug().c_str());

  if (aResult.isError())
    Firebase.printf("Error task: %s, msg: %s, code: %d\n", aResult.uid().c_str(), aResult.error().message().c_str(), aResult.error().code());

  if (aResult.available())
    Firebase.printf("task: %s, payload: %s\n", aResult.uid().c_str(), aResult.c_str());
}



4. VIDEO HASILNYA





Membuat Alat Blood Warmer Arduino Fuzzy Logic Mamdani

Membuat Alat Blood Warmer Arduino Fuzzy Logic Mamdani


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk Bloodwarmer yang mana menggunakan 2 buah sensor suhu yaitu sensor mlx90614 dan ds18b20. alat ini menggunakan metode Fuzzy Logic mamdani dan penampil LCD 16x2. untuk aktuator on off heater menggunakan solid state relay. untuk lebih jelasnya berikut adalah koding dan skemanya.


1. Skema Fuzzy





2. Program Arduino IDE

#include <Fuzzy.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <DallasTemperature.h>
#include <OneWire.h>
#define ONE_WIRE_BUS 2  
#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

float TargetC;

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

float tempobject;
float temppeltier;
float output1;
int fuzzyx;

Fuzzy *fuzzy = new Fuzzy();

// FuzzyInput
FuzzySet *dingin = new FuzzySet(0, 0, 35, 36);
FuzzySet *normal = new FuzzySet(35, 36, 36, 37);
FuzzySet *panas = new FuzzySet(36, 37, 100, 100);

// FuzzyInput
FuzzySet *rendah = new FuzzySet(0, 0, 30, 40);
FuzzySet *sedang = new FuzzySet(30, 40, 40, 50);
FuzzySet *tinggi = new FuzzySet(40, 50, 100, 100);

// FuzzyOutput
FuzzySet *minimum = new FuzzySet(0, 0, 1, 2);
FuzzySet *average = new FuzzySet(2, 50, 50, 100);
FuzzySet *maximum = new FuzzySet(100, 200, 255, 255);

void setup()
{

  Serial.begin(9600);
  mlx.begin();
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  pinMode(9,OUTPUT);
  
  // FuzzyInput suhuobject
  FuzzyInput *suhuobject = new FuzzyInput(1);

  suhuobject->addFuzzySet(dingin);
  suhuobject->addFuzzySet(normal);
  suhuobject->addFuzzySet(panas);
  fuzzy->addFuzzyInput(suhuobject);

  // FuzzyInput suhupeltier
  FuzzyInput *suhupeltier = new FuzzyInput(2);

  suhupeltier->addFuzzySet(rendah);
  suhupeltier->addFuzzySet(sedang);
  suhupeltier->addFuzzySet(tinggi);
  fuzzy->addFuzzyInput(suhupeltier);

  // FuzzyOutput pwm
  FuzzyOutput *pwmout = new FuzzyOutput(1);

  pwmout->addFuzzySet(minimum);
  pwmout->addFuzzySet(average);
  pwmout->addFuzzySet(maximum);
  fuzzy->addFuzzyOutput(pwmout);

  // Building FuzzyRule 1
  FuzzyRuleAntecedent *ifsuhuobjectDinginAndsuhupeltierRendah = new FuzzyRuleAntecedent();
  ifsuhuobjectDinginAndsuhupeltierRendah->joinWithAND(dingin, rendah); 
  FuzzyRuleConsequent *thenPwmoutMaximum= new FuzzyRuleConsequent();
  thenPwmoutMaximum->addOutput(maximum);
  FuzzyRule *fuzzyRule1 = new FuzzyRule(1, ifsuhuobjectDinginAndsuhupeltierRendah, thenPwmoutMaximum);
  fuzzy->addFuzzyRule(fuzzyRule1);

  // Building FuzzyRule 2
  FuzzyRuleAntecedent *ifsuhuobjectDinginAndsuhupeltierSedang = new FuzzyRuleAntecedent();
  ifsuhuobjectDinginAndsuhupeltierSedang->joinWithAND(dingin, sedang); 
  //FuzzyRuleConsequent *thenPwmoutMaximum= new FuzzyRuleConsequent();
  thenPwmoutMaximum->addOutput(maximum);
  FuzzyRule *fuzzyRule2 = new FuzzyRule(2, ifsuhuobjectDinginAndsuhupeltierSedang, thenPwmoutMaximum);
  fuzzy->addFuzzyRule(fuzzyRule2);

  // Building FuzzyRule 3
  FuzzyRuleAntecedent *ifsuhuobjectDinginAndsuhupeltierTinggi = new FuzzyRuleAntecedent();
  ifsuhuobjectDinginAndsuhupeltierTinggi->joinWithAND(dingin, tinggi); 
  //FuzzyRuleConsequent *thenPwmoutMaximum= new FuzzyRuleConsequent();
  thenPwmoutMaximum->addOutput(maximum);
  FuzzyRule *fuzzyRule3 = new FuzzyRule(3, ifsuhuobjectDinginAndsuhupeltierTinggi, thenPwmoutMaximum);
  fuzzy->addFuzzyRule(fuzzyRule3);

  // Building FuzzyRule 4
  FuzzyRuleAntecedent *ifsuhuobjectNormalAndsuhupeltierRendah= new FuzzyRuleAntecedent();
  ifsuhuobjectNormalAndsuhupeltierRendah->joinWithAND(normal, rendah); 
  FuzzyRuleConsequent *thenPwmoutAverage= new FuzzyRuleConsequent();
  thenPwmoutAverage->addOutput(average);
  FuzzyRule *fuzzyRule4 = new FuzzyRule(4, ifsuhuobjectNormalAndsuhupeltierRendah, thenPwmoutAverage);
  fuzzy->addFuzzyRule(fuzzyRule4);

  // Building FuzzyRule 5
  FuzzyRuleAntecedent *ifsuhuobjectNormalAndsuhupeltierSedang= new FuzzyRuleAntecedent();
  ifsuhuobjectNormalAndsuhupeltierSedang->joinWithAND(normal, sedang); 
  //FuzzyRuleConsequent *thenPwmoutAverage= new FuzzyRuleConsequent();
  thenPwmoutAverage->addOutput(average);
  FuzzyRule *fuzzyRule5 = new FuzzyRule(5, ifsuhuobjectNormalAndsuhupeltierSedang, thenPwmoutAverage);
  fuzzy->addFuzzyRule(fuzzyRule5);

  // Building FuzzyRule 6
  FuzzyRuleAntecedent *ifsuhuobjectNormalAndsuhupeltierTinggi= new FuzzyRuleAntecedent();
  ifsuhuobjectNormalAndsuhupeltierTinggi->joinWithAND(normal, tinggi); 
  //FuzzyRuleConsequent *thenPwmoutAverage= new FuzzyRuleConsequent();
  thenPwmoutAverage->addOutput(average);
  FuzzyRule *fuzzyRule6 = new FuzzyRule(6, ifsuhuobjectNormalAndsuhupeltierTinggi, thenPwmoutAverage);
  fuzzy->addFuzzyRule(fuzzyRule6);

  // Building FuzzyRule 7
  FuzzyRuleAntecedent *ifsuhuobjectPanasAndsuhupeltierRendah= new FuzzyRuleAntecedent();
  ifsuhuobjectPanasAndsuhupeltierRendah->joinWithAND(panas, rendah); 
  FuzzyRuleConsequent *thenPwmoutMinimum= new FuzzyRuleConsequent();
  thenPwmoutMinimum->addOutput(minimum);
  FuzzyRule *fuzzyRule7 = new FuzzyRule(7, ifsuhuobjectPanasAndsuhupeltierRendah, thenPwmoutMinimum);
  fuzzy->addFuzzyRule(fuzzyRule7);

  // Building FuzzyRule 8
  FuzzyRuleAntecedent *ifsuhuobjectPanasAndsuhupeltierSedang= new FuzzyRuleAntecedent();
  ifsuhuobjectPanasAndsuhupeltierSedang->joinWithAND(panas, sedang); 
  //FuzzyRuleConsequent *thenPwmoutMinimum= new FuzzyRuleConsequent();
  thenPwmoutMinimum->addOutput(minimum);
  FuzzyRule *fuzzyRule8 = new FuzzyRule(8, ifsuhuobjectPanasAndsuhupeltierSedang, thenPwmoutMinimum);
  fuzzy->addFuzzyRule(fuzzyRule8);

  // Building FuzzyRule 9
  FuzzyRuleAntecedent *ifsuhuobjectPanasAndsuhupeltierTinggi= new FuzzyRuleAntecedent();
  ifsuhuobjectPanasAndsuhupeltierTinggi->joinWithAND(panas, tinggi); 
  //FuzzyRuleConsequent *thenPwmoutMinimum= new FuzzyRuleConsequent();
  thenPwmoutMinimum->addOutput(minimum);
  FuzzyRule *fuzzyRule9 = new FuzzyRule(9, ifsuhuobjectPanasAndsuhupeltierTinggi, thenPwmoutMinimum);
  fuzzy->addFuzzyRule(fuzzyRule9);
  
}

void loop()
{

  sensors.requestTemperatures();
  tempobject = mlx.readObjectTempC();
  temppeltier = sensors.getTempCByIndex(0);

  lcd.setCursor(0,0);
  lcd.print("To/b= ");
  lcd.print(tempobject,1);
  lcd.print("/");
  lcd.print(temppeltier,1);
  lcd.print("   ");
  lcd.setCursor(0,1);
  lcd.print("COG=");
  lcd.print(output1);
  lcd.print("/");
  lcd.print(fuzzyx);
  lcd.print("     ");
     
  Serial.print("Suhu Orang: ");
  Serial.print(tempobject);
  Serial.print("|| Suhu Object: ");
  Serial.println(temppeltier);

  fuzzy->setInput(1, tempobject);
  fuzzy->setInput(2, temppeltier);

  fuzzy->fuzzify();

  Serial.print("Suhu Object: Dingin-> ");
  Serial.print(dingin->getPertinence());
  Serial.print(", Normal-> ");
  Serial.print(normal->getPertinence());
  Serial.print(", Panas-> ");
  Serial.println(panas->getPertinence());

  Serial.print("Suhu Peltier: Rendah-> ");
  Serial.print(rendah->getPertinence());
  Serial.print(",  Sedang-> ");
  Serial.print(sedang->getPertinence());
  Serial.print(",  Tinggi-> ");
  Serial.print(tinggi->getPertinence());

  output1 = fuzzy->defuzzify(1);
  fuzzyx = map(output1,191,100,255,0);

  if(fuzzyx < 0){
    fuzzyx = 0;
  }
    
  Serial.println("Output: ");
  Serial.print("PWMOUT: Minimum-> ");
  Serial.print(minimum->getPertinence());
  Serial.print(", Average-> ");
  Serial.print(average->getPertinence());
  Serial.print(", Maximum-> ");
  Serial.println(maximum->getPertinence());

  Serial.print("HASIL: ");
  Serial.print("PWM: ");
  Serial.println(output1);
  analogWrite(9,fuzzyx);
  
  delay(1000);
}


3. VIDEO HASILNYA



Monitor Suhu dan Kelembaban DHT11 dan Kendali Lampu via Blynk 2.0

Monitor Suhu dan Kelembaban DHT11 dan Kendali Lampu via Blynk 2.0 


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor suhu dan kelembaban secara online via Blynk 2.0 dan juga bisa kendali lampu secara online juga, jadi alat ini menggunakan sensor suhu DHt11 dan relay modul sebagain on off lampunya. untuk lebih jelasnya berikut adalah koding dan skemaya.


1. Skema
sumber gambar: https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/
sumber gambar: https://www.waveshare.com/temperature-humidity-sensor.htm 



2. Program Arduino IDE

#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL64nitwxxx"
#define BLYNK_TEMPLATE_NAME "suhu humy"
#define BLYNK_AUTH_TOKEN "xUHsu0yUSztbOyf6p4vL9wkvg7BqRxxx"

#include <SPI.h>
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <LiquidCrystal_I2C.h> 
#include "DHT.h"

#define DHTPIN D7     // what digital pin we're connected to
#define DHTTYPE DHT11   // DHT 11

DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);

int relay1 = D3;
int relay2 = D6;

int t, h;
int pinValue1, pinValue2;

BlynkTimer timer;

char ssid[] = "hotspothpku";
char pass[] = "1234567890";


BLYNK_WRITE(V2)
{
  pinValue1 = param.asInt();   

  if(pinValue1 == 1){
    digitalWrite(relay1, LOW);
  }
  
  if(pinValue1 == 0) {
    digitalWrite(relay1, HIGH);
  }
  
}

BLYNK_WRITE(V3)
{
  pinValue2 = param.asInt();   

  if(pinValue2 == 1){
    digitalWrite(relay2, LOW);
  }
  
  if(pinValue2 == 0) {
    digitalWrite(relay2, HIGH);
  }
  
}

void kirimdata()
{
  Blynk.virtualWrite(V0,t);
  Blynk.virtualWrite(V1,h);
}


void setup()
{
 Serial.begin(9600);
 dht.begin();
 lcd.begin();
 lcd.clear();
 lcd.noCursor();
 pinMode(relay1,OUTPUT);
 pinMode(relay2,OUTPUT);
 digitalWrite(relay1,HIGH);
 digitalWrite(relay2,HIGH);

 Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
 timer.setInterval(1000L, kirimdata); 
}

void loop()
{
 
 h = dht.readHumidity();
 t = dht.readTemperature();
 
  lcd.setCursor(0,0);
  lcd.print("Suhu= ");
  lcd.print(t);
  lcd.print(" C      ");
 
  lcd.setCursor(0,1);
  lcd.print("Humy= ");
  lcd.print(h);
  lcd.print(" %      ");
  
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
   
delay(100);

}


3. VIDEO HASILNYA



Monitor Flow Meter dan Input via Blynk 2.0 + Fitur Notifikasi

Monitor Flow Meter dan Input via Blynk 2.0 + Fitur Notifikasi


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang menggunakan sensor flow dan aktuatornya berupa solenoid valve. jadi alat ini dimonitor dengan menggunakan aplikasi IOT Blynk 2.0 kemudian jika flow melebihi batas maka akan ada notifikasi pada handphone. untuk lebih jelasnya berikut adalah koding skemanya.


1. Skema



2. Program Arduino IDE

#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL6xxx--xxx"
#define BLYNK_TEMPLATE_NAME "monitor flow"
#define BLYNK_AUTH_TOKEN "VOK0cWiFN5ycHj3SV_snEDXTfTxxxxxx"

#include <ESP8266WiFi.h>
#include <SPI.h>
#include <Wire.h>
#include <BlynkSimpleEsp8266.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); 

BlynkTimer timer;

char ssid[] = "hotspothpku";
char pass[] = "123456789";

#define SENSOR  2
 
long currentMillis = 0;
long previousMillis = 0;
int interval = 1000;
boolean ledState = LOW;
float calibrationFactor = 4.5;
volatile byte pulseCount;
byte pulse1Sec = 0;
float flowRate;
unsigned long flowMilliLitres;
unsigned int totalMilliLitres;
float flowLitres;
float totalLitres;

int relay = 12;
int pinValue1, pinValue2;

int batas = 1;
 
void IRAM_ATTR pulseCounter()
{
  pulseCount++;
}
 
BLYNK_WRITE(V1)
{
  pinValue1 = param.asInt();   

  if(pinValue1 == 1){
   batas++;
  }
  
  if(pinValue1 == 0) {
 
  }
  
}

BLYNK_WRITE(V2)
{
  pinValue2 = param.asInt();   

  if(pinValue2 == 1){
   batas--;
  }
  
  if(pinValue2 == 0) {
 
  }
  
}

void kirimdata()
{
  Blynk.virtualWrite(V0,totalLitres);
}

void setup()
{
  Serial.begin(9600);
  lcd.begin();   
  lcd.noCursor();
  lcd.clear();
  delay(10);

  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(1000L, kirimdata);
  
  pinMode(relay,OUTPUT);
  digitalWrite(relay,HIGH);
  pinMode(SENSOR, INPUT_PULLUP);
 
  pulseCount = 0;
  flowRate = 0.0;
  flowMilliLitres = 0;
  totalMilliLitres = 0;
  previousMillis = 0;
 
  attachInterrupt(digitalPinToInterrupt(SENSOR), pulseCounter, FALLING);
}
 
void loop()
{

  
  currentMillis = millis();
  if (currentMillis - previousMillis > interval) 
  {
    
    pulse1Sec = pulseCount;
    pulseCount = 0;
 
    // Because this loop may not complete in exactly 1 second intervals we calculate
    // the number of milliseconds that have passed since the last execution and use
    // that to scale the output. We also apply the calibrationFactor to scale the output
    // based on the number of pulses per second per units of measure (litres/minute in
    // this case) coming from the sensor.
    flowRate = ((1000.0 / (millis() - previousMillis)) * pulse1Sec) / calibrationFactor;
    previousMillis = millis();
 
    // Divide the flow rate in litres/minute by 60 to determine how many litres have
    // passed through the sensor in this 1 second interval, then multiply by 1000 to
    // convert to millilitres.
    flowMilliLitres = (flowRate / 60) * 1000;
    flowLitres = (flowRate / 60);
 
    // Add the millilitres passed in this second to the cumulative total
    totalMilliLitres += flowMilliLitres;
    totalLitres += flowLitres;
    
    // Print the flow rate for this second in litres / minute
    Serial.print("Flow rate: ");
    Serial.print(flowRate);  // Print the integer part of the variable
    Serial.print("L/min");
    Serial.print("\t");       // Print tab space

   lcd.setCursor(0,0);
   //lcd.print("L/min: ");
   //lcd.print(flowRate);
   lcd.print("Batas: ");
   lcd.print(batas);
   lcd.print(" L  ");
   
   lcd.setCursor(0,1);    
   lcd.print("Total: ");
   lcd.print(totalLitres);
   lcd.print(" L  ");

  if(totalLitres > batas){

    Blynk.logEvent("air_maksimal");
    Serial.print("AIR MAKSIMAL");   
     
    digitalWrite(relay,LOW);
   
  }

  Blynk.run();
  timer.run(); // Initiates BlynkTimer

}
}


3. VIDEO HASILNYA 



Alat Akses Ruangan Menggunakan Sensor Suhu Tubuh dan PIR + Fitur Suara

Alat Akses Ruangan Menggunakan Sensor Suhu Tubuh dan PIR + Fitur Suara


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa memonitor suhu tubuh sebelum memasuki ruangan, jadi sebelum memasuki ruangan orang harus cek suhu tubuh kemudian jika suhunya normal maka akan ada suara silahkan masuk, jika suhu tinggi maka akan ada suara akses ditolak, jika suhu normal maka akan mengaktifkan solenoid sehingga pintu bisa dibuka, namun jika tidak maka solenoid akan tetap mengunci. untuk lebih jelasnya berikut koding skemanya.


1. Komponen



2. Program Arduino IDE

#include <Wire.h>
#include <DFPlayer_Mini_Mp3.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_MLX90614.h>
LiquidCrystal_I2C lcd(0x27, 16,2);
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

float TargetC;
int ledmerah = 4;
int dataadc;

void setup(){
 
  mlx.begin();
  lcd.clear();
  lcd.begin();
  Serial.begin(9600);
  mySerial.begin(9600);
  mp3_set_serial(mySerial);  //set softwareSerial for DFPlayer-mini mp3 module
  delay(1);  //wait 1ms for mp3 module to set volume
  mp3_set_volume(30);  //volume 0-30
  
  lcd.noCursor();
  pinMode(ledmerah,OUTPUT);
}

void loop(){
           
 TargetC = mlx.readObjectTempC();
 dataadc = analogRead(A0);

      lcd.setCursor(0,0);
      lcd.print("Suhu= ");
      lcd.print(TargetC);
      lcd.println(" 'C     ");
    
      //lcd.setCursor(0,1);
      //lcd.print("ADC: ");
      //lcd.print(dataadc);
      //lcd.print("  ");

      if(dataadc > 100){ 
      lcd.setCursor(0,1);
      lcd.print("ADA ORANG   ");
      }
      
      if(dataadc < 100) {
      lcd.setCursor(0,1);
      lcd.print("KOSONG      ");
      }    
   
      if((dataadc > 100)&&(TargetC <=  32.0)) { 
       mp3_play(1);  //play music file 0001.mp3
       digitalWrite(ledmerah,LOW);
       delay(5000);  
       digitalWrite(ledmerah,HIGH);
       mp3_stop(); 
      }
      
      if((dataadc > 100)&&(TargetC > 32.0 )) {
       mp3_play(2);
       delay(5000);
       mp3_stop(); 
       digitalWrite(ledmerah,HIGH);
      }
   
delay(200);
}
   

3. VIDEO HASILNYA



Membuat Alat Deteksi Golongan Darah Arduino

Membuat Alat Deteksi Golongan Darah Arduino


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa mendeteksi golongan darah secara invasive, jadi alat ini butuh sample darah lalu di cekkan ke alat tersebut sehingga akan menghasilkan nilai yang tertampil di LCD. dari nilai tersebut kemudian disimpulkan golongan darah yang sesuai. untuk lebih jelasnya berikut adalah koding dan skemanya.


1. Skema 




2. Program Arduino IDE

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

int dataadc1;
int dataadc2;
int dataadc3;
int dataadc4;

int tombol = 7;
int tombolx;

void setup() {
  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  pinMode(tombol,INPUT_PULLUP);
}

void loop() {

  dataadc1 = analogRead(A0);
  dataadc2 = analogRead(A1);
  dataadc3 = analogRead(A2);
  dataadc4 = analogRead(A3);

  lcd.setCursor(0,0);
  lcd.print(dataadc1);
  lcd.print("/");
  lcd.print(dataadc2);
  lcd.print("/");
  lcd.print(dataadc3);
  lcd.print("/");
  lcd.print(dataadc4);
  lcd.print("    ");

tombolx = digitalRead(tombol);

if(tombolx == 0){
  if((dataadc1 > 100)&&(dataadc2 < 100)&&(dataadc3 > 100)&&(dataadc4 > 100)){
  lcd.setCursor(0,1);
  lcd.print("GOL = A+ ");  
  }

  if((dataadc1 > 100)&&(dataadc2 < 100)&&(dataadc3 < 100)&&(dataadc4 > 100)){
  lcd.setCursor(0,1);
  lcd.print("GOL = A-"); 
  }

  if((dataadc1 < 100)&&(dataadc2 > 100)&&(dataadc3 > 100)&&(dataadc4 > 100)){
  lcd.setCursor(0,1);
  lcd.print("GOL = B+ ");
  }

  if((dataadc1 < 100)&&(dataadc2 > 100)&&(dataadc3 < 100)&&(dataadc4 > 100)){
  lcd.setCursor(0,1);
  lcd.print("GOL = B- ");
  }

  if((dataadc1 > 100)&&(dataadc2 > 100)&&(dataadc3 > 100)&&(dataadc4 > 100)){
  lcd.setCursor(0,1);
  lcd.print("GOL = AB+");
  }

  if((dataadc1 > 100)&&(dataadc2 > 100)&&(dataadc3 < 100)&&(dataadc4 > 100)){
  lcd.setCursor(0,1);
  lcd.print("GOL = AB-");
  }

  if((dataadc1 < 100)&&(dataadc2 < 100)&&(dataadc3 > 100)&&(dataadc4 < 100)){
  lcd.setCursor(0,1);
  lcd.print("GOL = O+ ");
  }

  if((dataadc1 < 100)&&(dataadc2 < 100)&&(dataadc3 < 100)&&(dataadc4 < 100)){
  lcd.setCursor(0,1);
  lcd.print("GOL = O- ");
  }
}

delay(200);
}


3. VIDEO ALATNYA




Deteksi Golongan Darah Non Invasive (Masih Tahap Experimental)

Deteksi Golongan Darah Non Invasive (Masih Tahap Experimental)


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mendeteksi golongan darah secara non invasive tapi masih dalam tahap experimental belum fix, alat ini masih butuh banyak uji coba agar didapat banyak data yang bisa diambil kesimpulannya. untuk lebih jelasnya berikut adalah koding dan skemanya.

 

1. Skema


2. Program Arduino IDE

#include <Wire.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial (2, 3);

int dataadc1;
int zero=0;
int heatTime = 80;
int heatInterval = 255;
char printDensity = 15;
char printBreakTime = 15;
char my_str1[] = "A+";
char my_str2[] = "A-";
char my_str3[] = "B+";
char my_str4[] = "B-";
char my_str5[] = "AB+";
char my_str6[] = "AB-";
char my_str7[] = "O+";
char my_str8[] = "O-";
int datahasil;
int urutan;
int mark;
int tanda = 0;
int button = 12;
int buttonx;

void setup() {
  mySerial.begin(9600);
  Serial.begin(9600); // to write to our new printer
  pinMode(button,INPUT_PULLUP);
  initPrinter();
}

void initPrinter()
{
 //Modify the print speed and heat
 Serial.write(27);
 Serial.write(55);
 Serial.write(7); //Default 64 dots = 8*('7'+1)
 Serial.write(heatTime); //Default 80 or 800us
 Serial.write(heatInterval); //Default 2 or 20us
 //Modify the print density and timeout
 Serial.write(18);
 Serial.write(35);
 int printSetting = (printDensity<<4) | printBreakTime;
 Serial.write(printSetting); //Combination of printDensity and printBreakTime
}

void loop() {

  dataadc1 = analogRead(A0);
 
  if((dataadc1 > 50)&&(dataadc1 < 100)){
  lcdCMD("hasil.txt=\"A+\"");  
  mark = 1;
  }

  if((dataadc1 > 100)&&(dataadc1 < 200)){
  lcdCMD("hasil.txt=\"A-\"");  
  mark = 2;
  }

  if((dataadc1 > 200)&&(dataadc1 < 300)){
  lcdCMD("hasil.txt=\"B+\"");  
  mark = 3;
  }

  if((dataadc1 > 300)&&(dataadc1 < 400)){
  lcdCMD("hasil.txt=\"B-\"");  
  mark = 4;
  }

  if((dataadc1 > 400)&&(dataadc1 < 500)){
  lcdCMD("hasil.txt=\"AB+\""); 
  mark = 5;
  }

  if((dataadc1 > 500)&&(dataadc1 < 600)){
  lcdCMD("hasil.txt=\"AB-\"");  
  mark = 6;
  }

  if((dataadc1 > 600)&&(dataadc1 < 700)){
  lcdCMD("hasil.txt=\"O+\"");  
  mark = 7;
  }

  if((dataadc1 > 700)&&(dataadc1 < 800)){
  lcdCMD("hasil.txt=\"O-\"");  
  mark = 8;
  }

  lcdCMD("sensor2.val=" + String(dataadc1));

   buttonx = digitalRead(button);
   if(buttonx == 0){
    printing();
   } 
    
}

void lcdCMD(String cmd) {
  mySerial.print(cmd);
  mySerial.write(0xff);
  mySerial.write(0xff);
  mySerial.write(0xff);
  tanda = 0;
}

void printing(){
   delay(1000);

if(mark == 1){
  Serial.print("GOL= ");
  Serial.println(my_str1);
  mark = 0;
  }

if(mark == 2){
  Serial.print("GOL= ");
  Serial.println(my_str2);
  mark = 0;
  }

if(mark == 3){
  Serial.print("GOL= ");
  Serial.println(my_str3);
  }

if(mark == 4){
  Serial.print("GOL= ");
  Serial.println(my_str4);
  mark = 0;
  }

if(mark == 5){
  Serial.print("GOL= ");
  Serial.println(my_str5);
  mark = 0;
  }  

if(mark == 6){
  Serial.print("GOL= ");
  Serial.println(my_str6);
  mark = 0;
  }      

if(mark == 7){
  Serial.print("GOL= ");
  Serial.println(my_str7);
  mark = 0;
  }      

if(mark == 8){
  Serial.print("GOL= ");
  Serial.println(my_str8);
  mark = 0;
  }                  
  
  Serial.write(10);
  Serial.write(10);  
}

3. VIDEO HASILNYA