Translate

Monitor Suhu & Kelembaban (Temperature & Humidity) Sensor DHT22 dan NodeMCU ESP8266 Interface 7Segment Modul

Monitor Suhu & Kelembaban (Temperature & Humidity) Sensor DHT22 dan NodeMCU ESP8266 Interface 7Segment Modul


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor suhu dan kelembaban atau temperature dan humidity dengan menggunakan sensor DHT22. alat ini menggunakan interface 7Segment modul yang mana untuk menampilkan nilai suhu dan nilai kelembaban. untuk lebih jelasnya berikut adalah koding dan skemanya.



a. Skema dan Komponen






b. Program Arduino IDE

#include <TM1637Display.h>
#include "DHT.h"

#define DHTPIN D7

#define CLK D2
#define DIO D1
#define CLK2 D5
#define DIO2 D6

#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

float t,h;
int dataadc;
TM1637Display display1(CLK, DIO);
TM1637Display display2(CLK2, DIO2);
void setup()
{
  display1.setBrightness(0x0f); //seting brightness maksimal  
  display2.setBrightness(0x0f); //seting brightness maksimal   
  dht.begin();
}

void loop()
{  
  
 h = dht.readHumidity();
 t = dht.readTemperature();
  
display1.showNumberDec(t); 
display2.showNumberDec(h); 

delay(200);  
}



c. VIDEO HASILNYA




Tensimeter Digital Fuzzy logic Mamdani Library EFLL

Tensimeter Digital Fuzzy logic Mamdani Library EFLL


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang menggunakan Fuzzy Logic untuk tensimeter digital. alat ini seperti halnya tensimeter digital namun ada metode yang dipakai yaitu Fuzzy Logic Mamdani. alat ini terdapat fitur input kolesterol dan berat badan serta tinggi badan. untuk lebih jelasnya berikut adalah koding skemanya.  


a. Skema 



b. Program Arduino IDE 

#include <Fuzzy.h>
#include <Arduino.h>
#include <math.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//#include <SPI.h>
#include <Keypad.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

int counter;
int motor1 = 12;
int motor2 = 13;
int solenoid1 = 10;
int solenoid2 = 11;
int dataadc;
int tombolx;
int hitung;
float vol;
float mmhg;
float mmhgx;
int sistole;
int diastole;
int sistolex;
int diastolex;
int mark = 0;
long kolesterolnya, massanya;
long tinggi;
int hasilresiko;
int indekmassatubuh, kolesterolz;
float output1;

char customKey;
const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
  {'1', '2', '3','A'},
  {'4', '5', '6','B'},
  {'7', '8', '9','C'},
  {'*', '0', '#','D'}
};
byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8,9}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);


Fuzzy *fuzzy = new Fuzzy();

// FuzzyInput tekanan darah
FuzzySet *td1 = new FuzzySet(0, 90, 129, 134);
FuzzySet *td2 = new FuzzySet(125, 130, 139, 144);
FuzzySet *td3 = new FuzzySet(135, 140, 159, 164);
FuzzySet *td4 = new FuzzySet(155, 160, 179, 184);
FuzzySet *td5 = new FuzzySet(175, 180, 190, 190);

// FuzzyInput kolesterol
FuzzySet *k1 = new FuzzySet(0, 100, 199, 240);
FuzzySet *k2 = new FuzzySet(200, 240, 300, 300);

// FuzzyInput index massa tubuh
FuzzySet *imt1 = new FuzzySet(0, 15, 25, 26);
FuzzySet *imt2 = new FuzzySet(25, 27, 30, 30);

// FuzzyOutput
FuzzySet *N = new FuzzySet(0, 0, 2, 3);
FuzzySet *LR = new FuzzySet(1, 2, 4, 5);
FuzzySet *MRR = new FuzzySet(3, 4, 6, 7);
FuzzySet *MTHR = new FuzzySet(5, 6, 8, 9);
FuzzySet *HR = new FuzzySet(7, 8, 10, 10);


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

  Serial.begin(9600);
      
  pinMode(motor1,OUTPUT);
  pinMode(motor2,OUTPUT);
  pinMode(solenoid1,OUTPUT);
  pinMode(solenoid2,OUTPUT);
  digitalWrite(motor1,LOW);
  digitalWrite(motor2,LOW);
  digitalWrite(solenoid1,HIGH);
  digitalWrite(solenoid2,LOW);


  // FuzzyInput tekanan darah
  FuzzyInput *tekanandarah = new FuzzyInput(1);
  tekanandarah->addFuzzySet(td1);
  tekanandarah->addFuzzySet(td2);
  tekanandarah->addFuzzySet(td3);
  tekanandarah->addFuzzySet(td4);
  tekanandarah->addFuzzySet(td5);
  fuzzy->addFuzzyInput(tekanandarah);

  // FuzzyInput kolesterol
  FuzzyInput *kolesterol = new FuzzyInput(2);
  kolesterol->addFuzzySet(k1);
  kolesterol->addFuzzySet(k2);
  fuzzy->addFuzzyInput(kolesterol);

  // FuzzyInput index massa tubuh
  FuzzyInput *massatubuh = new FuzzyInput(3);
  massatubuh->addFuzzySet(imt1);
  massatubuh->addFuzzySet(imt2);
  fuzzy->addFuzzyInput(massatubuh);

  // FuzzyOutput resiko
  FuzzyOutput *resiko = new FuzzyOutput(1);
  resiko->addFuzzySet(N);
  resiko->addFuzzySet(LR);
  resiko->addFuzzySet(MRR);
  resiko->addFuzzySet(MTHR);
  resiko->addFuzzySet(HR);
  fuzzy->addFuzzyOutput(resiko);

  // Building FuzzyRule 1
  FuzzyRuleAntecedent *iftekanandarahTd1AndmassatubuhImt1 = new FuzzyRuleAntecedent();
  iftekanandarahTd1AndmassatubuhImt1->joinWithAND(td1, imt1); 
  
  FuzzyRuleAntecedent *kolesterolK1 = new FuzzyRuleAntecedent();
  kolesterolK1->joinSingle(k1);
  FuzzyRuleAntecedent *iftekanandarahTd1AndmassatubuhImt1AndkolesterolK1 = new FuzzyRuleAntecedent();
  iftekanandarahTd1AndmassatubuhImt1AndkolesterolK1->joinWithAND(iftekanandarahTd1AndmassatubuhImt1, kolesterolK1);
  FuzzyRuleConsequent *thenResikoN = new FuzzyRuleConsequent();
  thenResikoN->addOutput(N);
  FuzzyRule *fuzzyRule1 = new FuzzyRule(1, iftekanandarahTd1AndmassatubuhImt1AndkolesterolK1, thenResikoN);
  fuzzy->addFuzzyRule(fuzzyRule1);

  // Building FuzzyRule 2
  //FuzzyRuleAntecedent *iftekanandarahTd1AndmassatubuhImt1 = new FuzzyRuleAntecedent();
  iftekanandarahTd1AndmassatubuhImt1->joinWithAND(td1, imt1); 
  
  FuzzyRuleAntecedent *kolesterolK2 = new FuzzyRuleAntecedent();
  kolesterolK2->joinSingle(k2);
  FuzzyRuleAntecedent *iftekanandarahTd1AndmassatubuhImt1AndkolesterolK2 = new FuzzyRuleAntecedent();
  iftekanandarahTd1AndmassatubuhImt1AndkolesterolK2->joinWithAND(iftekanandarahTd1AndmassatubuhImt1, kolesterolK2);
  //FuzzyRuleConsequent *thenResikoN = new FuzzyRuleConsequent();
  thenResikoN->addOutput(N);
  FuzzyRule *fuzzyRule2 = new FuzzyRule(2, iftekanandarahTd1AndmassatubuhImt1AndkolesterolK2, thenResikoN);
  fuzzy->addFuzzyRule(fuzzyRule2);

  // Building FuzzyRule 3
  FuzzyRuleAntecedent *iftekanandarahTd1AndmassatubuhImt2 = new FuzzyRuleAntecedent();
  iftekanandarahTd1AndmassatubuhImt2->joinWithAND(td1, imt2); 
  
  //FuzzyRuleAntecedent *kolesterolK1 = new FuzzyRuleAntecedent();
  kolesterolK1->joinSingle(k1);
  FuzzyRuleAntecedent *iftekanandarahTd1AndmassatubuhImt2AndkolesterolK1 = new FuzzyRuleAntecedent();
  iftekanandarahTd1AndmassatubuhImt2AndkolesterolK1->joinWithAND(iftekanandarahTd1AndmassatubuhImt2, kolesterolK1);
  //FuzzyRuleConsequent *thenResikoN = new FuzzyRuleConsequent();
  thenResikoN->addOutput(N);
  FuzzyRule *fuzzyRule3 = new FuzzyRule(3, iftekanandarahTd1AndmassatubuhImt2AndkolesterolK1, thenResikoN);
  fuzzy->addFuzzyRule(fuzzyRule3);

  // Building FuzzyRule 4
  //FuzzyRuleAntecedent *iftekanandarahTd1AndmassatubuhImt2 = new FuzzyRuleAntecedent();
  iftekanandarahTd1AndmassatubuhImt2->joinWithAND(td1, imt2); 
  
  //FuzzyRuleAntecedent *kolesterolK2 = new FuzzyRuleAntecedent();
  kolesterolK2->joinSingle(k2);
  FuzzyRuleAntecedent *iftekanandarahTd1AndmassatubuhImt2AndkolesterolK2 = new FuzzyRuleAntecedent();
  iftekanandarahTd1AndmassatubuhImt2AndkolesterolK2->joinWithAND(iftekanandarahTd1AndmassatubuhImt2, kolesterolK2);
  //FuzzyRuleConsequent *thenResikoN = new FuzzyRuleConsequent();
  thenResikoN->addOutput(N);
  FuzzyRule *fuzzyRule4 = new FuzzyRule(4, iftekanandarahTd1AndmassatubuhImt2AndkolesterolK2, thenResikoN);
  fuzzy->addFuzzyRule(fuzzyRule4);

  // Building FuzzyRule 5
  FuzzyRuleAntecedent *iftekanandarahTd2AndmassatubuhImt1 = new FuzzyRuleAntecedent();
  iftekanandarahTd2AndmassatubuhImt1->joinWithAND(td2, imt1); 
  
  //FuzzyRuleAntecedent *kolesterolK1 = new FuzzyRuleAntecedent();
  kolesterolK1->joinSingle(k1);
  FuzzyRuleAntecedent *iftekanandarahTd2AndmassatubuhImt1AndkolesterolK1 = new FuzzyRuleAntecedent();
  iftekanandarahTd2AndmassatubuhImt1AndkolesterolK1->joinWithAND(iftekanandarahTd2AndmassatubuhImt1, kolesterolK1);
  FuzzyRuleConsequent *thenResikoLr = new FuzzyRuleConsequent();
  thenResikoLr->addOutput(LR);
  FuzzyRule *fuzzyRule5 = new FuzzyRule(5, iftekanandarahTd2AndmassatubuhImt1AndkolesterolK1, thenResikoLr);
  fuzzy->addFuzzyRule(fuzzyRule5);

  // Building FuzzyRule 6
  //FuzzyRuleAntecedent *iftekanandarahTd2AndmassatubuhImt1 = new FuzzyRuleAntecedent();
  iftekanandarahTd2AndmassatubuhImt1->joinWithAND(td2, imt1); 
  
  //FuzzyRuleAntecedent *kolesterolK2 = new FuzzyRuleAntecedent();
  kolesterolK2->joinSingle(k2);
  FuzzyRuleAntecedent *iftekanandarahTd2AndmassatubuhImt1AndkolesterolK2 = new FuzzyRuleAntecedent();
  iftekanandarahTd2AndmassatubuhImt1AndkolesterolK2->joinWithAND(iftekanandarahTd2AndmassatubuhImt1, kolesterolK2);
  //FuzzyRuleConsequent *thenResikoLr = new FuzzyRuleConsequent();
  thenResikoLr->addOutput(LR);
  FuzzyRule *fuzzyRule6 = new FuzzyRule(6, iftekanandarahTd2AndmassatubuhImt1AndkolesterolK2, thenResikoLr);
  fuzzy->addFuzzyRule(fuzzyRule6);

  // Building FuzzyRule 7
  FuzzyRuleAntecedent *iftekanandarahTd2AndmassatubuhImt2 = new FuzzyRuleAntecedent();
  iftekanandarahTd2AndmassatubuhImt2->joinWithAND(td2, imt2); 
  
  //FuzzyRuleAntecedent *kolesterolK1 = new FuzzyRuleAntecedent();
  kolesterolK1->joinSingle(k1);
  FuzzyRuleAntecedent *iftekanandarahTd2AndmassatubuhImt2AndkolesterolK1 = new FuzzyRuleAntecedent();
  iftekanandarahTd2AndmassatubuhImt2AndkolesterolK1->joinWithAND(iftekanandarahTd2AndmassatubuhImt2, kolesterolK1);
  //FuzzyRuleConsequent *thenResikoLr = new FuzzyRuleConsequent();
  thenResikoLr->addOutput(LR);
  FuzzyRule *fuzzyRule7 = new FuzzyRule(7, iftekanandarahTd2AndmassatubuhImt2AndkolesterolK1, thenResikoLr);
  fuzzy->addFuzzyRule(fuzzyRule7);

   // Building FuzzyRule 8
  //FuzzyRuleAntecedent *iftekanandarahTd2AndmassatubuhImt2 = new FuzzyRuleAntecedent();
  iftekanandarahTd2AndmassatubuhImt2->joinWithAND(td2, imt2); 
  
  //FuzzyRuleAntecedent *kolesterolK2 = new FuzzyRuleAntecedent();
  kolesterolK2->joinSingle(k2);
  FuzzyRuleAntecedent *iftekanandarahTd2AndmassatubuhImt2AndkolesterolK2 = new FuzzyRuleAntecedent();
  iftekanandarahTd2AndmassatubuhImt2AndkolesterolK2->joinWithAND(iftekanandarahTd2AndmassatubuhImt2, kolesterolK2);
  //FuzzyRuleConsequent *thenResikoLr = new FuzzyRuleConsequent();
  thenResikoLr->addOutput(LR);
  FuzzyRule *fuzzyRule8 = new FuzzyRule(8, iftekanandarahTd2AndmassatubuhImt2AndkolesterolK2, thenResikoLr);
  fuzzy->addFuzzyRule(fuzzyRule8);
 
   // Building FuzzyRule 9
  FuzzyRuleAntecedent *iftekanandarahTd3AndmassatubuhImt1 = new FuzzyRuleAntecedent();
  iftekanandarahTd3AndmassatubuhImt1->joinWithAND(td3, imt1); 
  
  //FuzzyRuleAntecedent *kolesterolK1 = new FuzzyRuleAntecedent();
  kolesterolK1->joinSingle(k1);
  FuzzyRuleAntecedent *iftekanandarahTd3AndmassatubuhImt1AndkolesterolK1 = new FuzzyRuleAntecedent();
  iftekanandarahTd3AndmassatubuhImt1AndkolesterolK1->joinWithAND(iftekanandarahTd3AndmassatubuhImt1, kolesterolK1);
  //FuzzyRuleConsequent *thenResikoLr = new FuzzyRuleConsequent();
  thenResikoLr->addOutput(LR);
  FuzzyRule *fuzzyRule9 = new FuzzyRule(9, iftekanandarahTd3AndmassatubuhImt1AndkolesterolK1, thenResikoLr);
  fuzzy->addFuzzyRule(fuzzyRule9);

  // Building FuzzyRule 10
  //FuzzyRuleAntecedent *iftekanandarahTd3AndmassatubuhImt1 = new FuzzyRuleAntecedent();
  iftekanandarahTd3AndmassatubuhImt1->joinWithAND(td3, imt1); 
  
  //FuzzyRuleAntecedent *kolesterolK2 = new FuzzyRuleAntecedent();
  kolesterolK2->joinSingle(k2);
  FuzzyRuleAntecedent *iftekanandarahTd3AndmassatubuhImt1AndkolesterolK2 = new FuzzyRuleAntecedent();
  iftekanandarahTd3AndmassatubuhImt1AndkolesterolK2->joinWithAND(iftekanandarahTd3AndmassatubuhImt1, kolesterolK2);
  FuzzyRuleConsequent *thenResikoMrr = new FuzzyRuleConsequent();
  thenResikoMrr->addOutput(MRR);
  FuzzyRule *fuzzyRule10 = new FuzzyRule(10, iftekanandarahTd3AndmassatubuhImt1AndkolesterolK2, thenResikoMrr);
  fuzzy->addFuzzyRule(fuzzyRule10);

    // Building FuzzyRule 11
  FuzzyRuleAntecedent *iftekanandarahTd3AndmassatubuhImt2 = new FuzzyRuleAntecedent();
  iftekanandarahTd3AndmassatubuhImt2->joinWithAND(td3, imt2); 
  
  //FuzzyRuleAntecedent *kolesterolK1 = new FuzzyRuleAntecedent();
  kolesterolK1->joinSingle(k1);
  FuzzyRuleAntecedent *iftekanandarahTd3AndmassatubuhImt2AndkolesterolK1 = new FuzzyRuleAntecedent();
  iftekanandarahTd3AndmassatubuhImt2AndkolesterolK1->joinWithAND(iftekanandarahTd3AndmassatubuhImt2, kolesterolK1);
  //FuzzyRuleConsequent *thenResikoMrr = new FuzzyRuleConsequent();
  thenResikoMrr->addOutput(MRR);
  FuzzyRule *fuzzyRule11 = new FuzzyRule(11, iftekanandarahTd3AndmassatubuhImt2AndkolesterolK1, thenResikoMrr);
  fuzzy->addFuzzyRule(fuzzyRule11);

    // Building FuzzyRule 12
  //FuzzyRuleAntecedent *iftekanandarahTd3AndmassatubuhImt2 = new FuzzyRuleAntecedent();
  iftekanandarahTd3AndmassatubuhImt2->joinWithAND(td3, imt2); 
  
  //FuzzyRuleAntecedent *kolesterolK2 = new FuzzyRuleAntecedent();
  kolesterolK2->joinSingle(k2);
  FuzzyRuleAntecedent *iftekanandarahTd3AndmassatubuhImt2AndkolesterolK2 = new FuzzyRuleAntecedent();
  iftekanandarahTd3AndmassatubuhImt2AndkolesterolK2->joinWithAND(iftekanandarahTd3AndmassatubuhImt2, kolesterolK2);
  //FuzzyRuleConsequent *thenResikoMrr = new FuzzyRuleConsequent();
  thenResikoMrr->addOutput(MRR);
  FuzzyRule *fuzzyRule12 = new FuzzyRule(12, iftekanandarahTd3AndmassatubuhImt2AndkolesterolK2, thenResikoMrr);
  fuzzy->addFuzzyRule(fuzzyRule12);

  // Building FuzzyRule 13
  FuzzyRuleAntecedent *iftekanandarahTd4AndmassatubuhImt1 = new FuzzyRuleAntecedent();
  iftekanandarahTd4AndmassatubuhImt1->joinWithAND(td4, imt1); 
  
  //FuzzyRuleAntecedent *kolesterolK1 = new FuzzyRuleAntecedent();
  kolesterolK1->joinSingle(k1);
  FuzzyRuleAntecedent *iftekanandarahTd4AndmassatubuhImt1AndkolesterolK1 = new FuzzyRuleAntecedent();
  iftekanandarahTd4AndmassatubuhImt1AndkolesterolK1->joinWithAND(iftekanandarahTd4AndmassatubuhImt1, kolesterolK1);
  //FuzzyRuleConsequent *thenResikoMrr = new FuzzyRuleConsequent();
  thenResikoMrr->addOutput(MRR);
  FuzzyRule *fuzzyRule13 = new FuzzyRule(13, iftekanandarahTd4AndmassatubuhImt1AndkolesterolK1, thenResikoMrr);
  fuzzy->addFuzzyRule(fuzzyRule13);

    // Building FuzzyRule 14
  //FuzzyRuleAntecedent *iftekanandarahTd4AndmassatubuhImt1 = new FuzzyRuleAntecedent();
  iftekanandarahTd4AndmassatubuhImt1->joinWithAND(td4, imt1); 
  
  //FuzzyRuleAntecedent *kolesterolK2 = new FuzzyRuleAntecedent();
  kolesterolK2->joinSingle(k2);
  FuzzyRuleAntecedent *iftekanandarahTd4AndmassatubuhImt1AndkolesterolK2 = new FuzzyRuleAntecedent();
  iftekanandarahTd4AndmassatubuhImt1AndkolesterolK2->joinWithAND(iftekanandarahTd4AndmassatubuhImt1, kolesterolK2);
  FuzzyRuleConsequent *thenResikoMthr = new FuzzyRuleConsequent();
  thenResikoMthr->addOutput(MTHR);
  FuzzyRule *fuzzyRule14 = new FuzzyRule(14, iftekanandarahTd4AndmassatubuhImt1AndkolesterolK2, thenResikoMthr);
  fuzzy->addFuzzyRule(fuzzyRule14);

  // Building FuzzyRule 15
  FuzzyRuleAntecedent *iftekanandarahTd4AndmassatubuhImt2 = new FuzzyRuleAntecedent();
  iftekanandarahTd4AndmassatubuhImt2->joinWithAND(td4, imt2); 
  
  //FuzzyRuleAntecedent *kolesterolK1 = new FuzzyRuleAntecedent();
  kolesterolK1->joinSingle(k1);
  FuzzyRuleAntecedent *iftekanandarahTd4AndmassatubuhImt2AndkolesterolK1 = new FuzzyRuleAntecedent();
  iftekanandarahTd4AndmassatubuhImt2AndkolesterolK1->joinWithAND(iftekanandarahTd4AndmassatubuhImt2, kolesterolK1);
  //FuzzyRuleConsequent *thenResikoMthr = new FuzzyRuleConsequent();
  thenResikoMthr->addOutput(MTHR);
  FuzzyRule *fuzzyRule15 = new FuzzyRule(15, iftekanandarahTd4AndmassatubuhImt2AndkolesterolK1, thenResikoMthr);
  fuzzy->addFuzzyRule(fuzzyRule15);

  // Building FuzzyRule 16
  //FuzzyRuleAntecedent *iftekanandarahTd4AndmassatubuhImt2 = new FuzzyRuleAntecedent();
  iftekanandarahTd4AndmassatubuhImt2->joinWithAND(td4, imt2); 
  
  //FuzzyRuleAntecedent *kolesterolK2 = new FuzzyRuleAntecedent();
  kolesterolK2->joinSingle(k2);
  FuzzyRuleAntecedent *iftekanandarahTd4AndmassatubuhImt2AndkolesterolK2 = new FuzzyRuleAntecedent();
  iftekanandarahTd4AndmassatubuhImt2AndkolesterolK2->joinWithAND(iftekanandarahTd4AndmassatubuhImt2, kolesterolK2);
  //FuzzyRuleConsequent *thenResikoMthr = new FuzzyRuleConsequent();
  thenResikoMthr->addOutput(MTHR);
  FuzzyRule *fuzzyRule16 = new FuzzyRule(16, iftekanandarahTd4AndmassatubuhImt2AndkolesterolK2, thenResikoMthr);
  fuzzy->addFuzzyRule(fuzzyRule16);   

  // Building FuzzyRule 17
  FuzzyRuleAntecedent *iftekanandarahTd5AndmassatubuhImt1 = new FuzzyRuleAntecedent();
  iftekanandarahTd5AndmassatubuhImt1->joinWithAND(td5, imt1); 
  
  //FuzzyRuleAntecedent *kolesterolK1 = new FuzzyRuleAntecedent();
  kolesterolK1->joinSingle(k1);
  FuzzyRuleAntecedent *iftekanandarahTd5AndmassatubuhImt1AndkolesterolK1 = new FuzzyRuleAntecedent();
  iftekanandarahTd5AndmassatubuhImt1AndkolesterolK1->joinWithAND(iftekanandarahTd5AndmassatubuhImt1, kolesterolK1);
  FuzzyRuleConsequent *thenResikoHr = new FuzzyRuleConsequent();
  thenResikoHr->addOutput(HR);
  FuzzyRule *fuzzyRule17 = new FuzzyRule(17, iftekanandarahTd5AndmassatubuhImt1AndkolesterolK1, thenResikoHr);
  fuzzy->addFuzzyRule(fuzzyRule17);  

  // Building FuzzyRule 18
  //FuzzyRuleAntecedent *iftekanandarahTd5AndmassatubuhImt1 = new FuzzyRuleAntecedent();
  iftekanandarahTd5AndmassatubuhImt1->joinWithAND(td5, imt1); 
  
  //FuzzyRuleAntecedent *kolesterolK2 = new FuzzyRuleAntecedent();
  kolesterolK2->joinSingle(k2);
  FuzzyRuleAntecedent *iftekanandarahTd5AndmassatubuhImt1AndkolesterolK2 = new FuzzyRuleAntecedent();
  iftekanandarahTd5AndmassatubuhImt1AndkolesterolK2->joinWithAND(iftekanandarahTd5AndmassatubuhImt1, kolesterolK2);
  //FuzzyRuleConsequent *thenResikoHr = new FuzzyRuleConsequent();
  thenResikoHr->addOutput(HR);
  FuzzyRule *fuzzyRule18 = new FuzzyRule(18, iftekanandarahTd5AndmassatubuhImt1AndkolesterolK2, thenResikoHr);
  fuzzy->addFuzzyRule(fuzzyRule18);  

  // Building FuzzyRule 19
  FuzzyRuleAntecedent *iftekanandarahTd5AndmassatubuhImt2 = new FuzzyRuleAntecedent();
  iftekanandarahTd5AndmassatubuhImt2->joinWithAND(td5, imt2); 
  
  //FuzzyRuleAntecedent *kolesterolK1 = new FuzzyRuleAntecedent();
  kolesterolK1->joinSingle(k1);
  FuzzyRuleAntecedent *iftekanandarahTd5AndmassatubuhImt2AndkolesterolK1 = new FuzzyRuleAntecedent();
  iftekanandarahTd5AndmassatubuhImt2AndkolesterolK1->joinWithAND(iftekanandarahTd5AndmassatubuhImt2, kolesterolK1);
  //FuzzyRuleConsequent *thenResikoHr = new FuzzyRuleConsequent();
  thenResikoHr->addOutput(HR);
  FuzzyRule *fuzzyRule19 = new FuzzyRule(19, iftekanandarahTd5AndmassatubuhImt2AndkolesterolK1, thenResikoHr);
  fuzzy->addFuzzyRule(fuzzyRule19);  

  // Building FuzzyRule 20
  //FuzzyRuleAntecedent *iftekanandarahTd5AndmassatubuhImt2 = new FuzzyRuleAntecedent();
  iftekanandarahTd5AndmassatubuhImt2->joinWithAND(td5, imt2); 
  
  //FuzzyRuleAntecedent *kolesterolK2 = new FuzzyRuleAntecedent();
  kolesterolK2->joinSingle(k2);
  FuzzyRuleAntecedent *iftekanandarahTd5AndmassatubuhImt2AndkolesterolK2 = new FuzzyRuleAntecedent();
  iftekanandarahTd5AndmassatubuhImt2AndkolesterolK2->joinWithAND(iftekanandarahTd5AndmassatubuhImt2, kolesterolK2);
  //FuzzyRuleConsequent *thenResikoHr = new FuzzyRuleConsequent();
  thenResikoHr->addOutput(HR);
  FuzzyRule *fuzzyRule20 = new FuzzyRule(20, iftekanandarahTd5AndmassatubuhImt2AndkolesterolK2, thenResikoHr);
  fuzzy->addFuzzyRule(fuzzyRule20);  

  lcd.clear();
  inputkolesterol();
  inputmassatubuh();
  inputtinggi();     
}


void loop() {
  
 indekmassatubuh = (massanya / pow(tinggi , 2));      
 customKey = customKeypad.getKey();
 
 if(customKey == 'A'){
  mark = 0;
  customKey = ' ';
  lcd.clear();
  delay(1000);
  digitalWrite(motor1,HIGH);
  digitalWrite(motor2,LOW);
  digitalWrite(solenoid1,LOW);
  digitalWrite(solenoid2,HIGH);
  mulai();
  }
    
  fuzzy->setInput(1, sistolex);
  fuzzy->setInput(2, kolesterolz);
  fuzzy->setInput(3, indekmassatubuh);
  fuzzy->fuzzify();

  /*
  Serial.print("sistol: td1-> ");
  Serial.print(td1->getPertinence());
  Serial.print(", td2-> ");
  Serial.print(td2->getPertinence());
  Serial.print(", td3-> ");
  Serial.print(td3->getPertinence());
  Serial.print(", td4-> ");
  Serial.print(td4->getPertinence());
  Serial.print(", td5-> ");
  Serial.println(td5->getPertinence());

  Serial.print("kolesterol: k1-> ");
  Serial.print(k1->getPertinence());
  Serial.print(", k2-> ");
  Serial.println(k2->getPertinence());

  Serial.print("Berat: imt1-> ");
  Serial.print(imt1->getPertinence());
  Serial.print(", imt2-> ");
  Serial.println(imt2->getPertinence());
  */
  
  output1 = fuzzy->defuzzify(1);

   /*
  Serial.print("output: N-> ");
  Serial.print(N->getPertinence());
  Serial.print(", LR-> ");
  Serial.print(LR->getPertinence());
  Serial.print(", MRR-> ");
  Serial.print(MRR->getPertinence());
  Serial.print(", MTHR-> ");
  Serial.print(MTHR->getPertinence());
  Serial.print(", HR-> ");
  Serial.println(HR->getPertinence());
 
  Serial.print("HASIL: ");
  Serial.println(output1);
  */
  
  if((output1 > 0)&&(output1 <= 4 )){
   lcd.setCursor(0,1);
   lcd.print("Resiko Rendah     ");
  }

 if((output1 > 4)&&(output1 <= 7 )){
   lcd.setCursor(0,1);
   lcd.print("Resiko Sedang     ");
  }  

 if((output1 > 7)&&(output1 <= 10 )){
   lcd.setCursor(0,1);
   lcd.print("Rsk Agak Tinggi   ");
  } 

 lcd.setCursor(0,0);
 lcd.print(kolesterolz);
 lcd.print("/");
 lcd.print(indekmassatubuh);
 lcd.print("/");
 lcd.print(output1);
 lcd.print("    ");
 lcd.setCursor(0,1);
 lcd.print(sistolex);
 lcd.print("/");
 lcd.print(diastolex);
 lcd.print("  ");

Serial.print("*");
Serial.print(kolesterolz);
Serial.print(",");
Serial.print(indekmassatubuh);
Serial.print(",");
Serial.print(sistolex);
Serial.print(",");
Serial.print(diastolex);
Serial.print(",");
Serial.print(output1 * 100.0);
Serial.println("#");

delay(10); 
}

void mulai(){
  
 dataadc = analogRead(A0);
 mmhg = (dataadc - 46.222) / 3.2;

if((mmhg >= mmhgx + 5)&&(mmhg > 100)&&(mark == 0)){
//digitalWrite(motor,LOW); 
//Serial.println("SISTOLE"); 
sistole = mmhg;
mark = 2; 
digitalWrite(motor1,LOW);
digitalWrite(motor2,LOW);
}

if((mmhg >= mmhgx + 5)&&(mmhg > 50)&&(mmhg < 90)&&(mark == 2)){
//Serial.println("DIASTOLE"); 
diastole = mmhg;
mark = 3;
}

 lcd.setCursor(0,1);
 lcd.print("S= ");
 lcd.print(mmhg);
 lcd.print("     ");

if(mmhg >= 120)
{
 digitalWrite(motor1,LOW);   
 digitalWrite(motor2,LOW);   
}

mmhgx = mmhg;

//Serial.println(mmhg);

if((mark == 3)&&(mmhg < 50)){
lcd.clear();
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = diastole;
digitalWrite(solenoid1,LOW);
digitalWrite(solenoid2,LOW);
return;  
}

if((mark == 2)&&(mmhg < 50)){
lcd.clear();
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = random(60,80);
digitalWrite(solenoid1,LOW);
digitalWrite(solenoid2,LOW);
return;  
}

delay(1);   
mulai();  
}



void inputkolesterol(){
  
 lcd.setCursor(0,0);
 lcd.print("Kolesterol");

customKey = customKeypad.getKey();
 
switch(customKey)
{
  case '0' ... '9': // This keeps collecting the first value until a operator is pressed "+-*/"
    lcd.setCursor(0,1);
    kolesterolnya = kolesterolnya * 10 + (customKey - '0');
    lcd.print(kolesterolnya);
    break;    
}

if(customKey == 'C'){
lcd.clear();
delay(200);
kolesterolnya = 0;
}

if(customKey == '#'){
lcd.clear();
delay(200);
kolesterolz = kolesterolnya;
return;
}

inputkolesterol();  
}


void inputmassatubuh(){
  
 lcd.setCursor(0,0);
 lcd.print("Berat Badan");

customKey = customKeypad.getKey();
 
switch(customKey)
{
  case '0' ... '9': // This keeps collecting the first value until a operator is pressed "+-*/"
    lcd.setCursor(0,1);
    massanya = massanya * 10 + (customKey - '0');
    lcd.print(massanya);
    break;    
}

if(customKey == 'C'){
lcd.clear();
delay(200);
massanya = 0;
}

if(customKey == '#'){
lcd.clear();
delay(200);
return;
}

inputmassatubuh();  
}



void inputtinggi(){
  
 lcd.setCursor(0,0);
 lcd.print("Tinggi");

customKey = customKeypad.getKey();
 
switch(customKey)
{
  case '0' ... '9': // This keeps collecting the first value until a operator is pressed "+-*/"
    lcd.setCursor(0,1);
    tinggi = tinggi * 10 + (customKey - '0');
    lcd.print(tinggi);
    break;    
}

if(customKey == 'C'){
lcd.clear();
delay(200);
tinggi = 0;
}

if(customKey == '#'){
lcd.clear();
delay(200);
tinggi = tinggi / 100;
return;
}

inputtinggi();  
}



c. Program ESP-32

#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>

int temp;
int x = 5;
int y;

int value1;
int value2;
int value3;
int value4;
int value5;

int kolesterolz;
int indekmassatubuh;
int sistolex;
int diastolex;
float output1;

int datain1;
int datain2;
int datain3;
int datain4;
int datain5;

String dataIn;
String dt[10];
int i;
boolean parsing = false;

String apiKey = "57GHFD48HJKGG78H";     //  Enter your Write API key from ThingSpeak
const char* resource = "/update?api_key=";

const char *ssid =  "hotspothpku";     // replace with your wifi ssid and wpa2 key
const char *pass =  "123456789";
const char* server = "api.thingspeak.com";

WiFiClient client;

void setup()
{
 
  dataIn="";
  Serial.begin(9600);
  delay(10);

  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

      while (WiFi.status() != WL_CONNECTED)
     {
            delay(500);
            Serial.print(".");
     }
      Serial.println("");
      Serial.println("WiFi connected");

}

void loop()
{

while(Serial.available()>0) {
  
//   dataIn="";
    char inChar = (char)Serial.read();
    dataIn += inChar;
    if (inChar == '\n') {
    parsing = true;
  }
}

if(parsing){
    parsingData();
       
  if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
                      {
                           
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(kolesterolz);
                             postStr += "\r\n\r\n";

                             client.print(String("GET ") + resource + apiKey + "&field1=" + kolesterolz + "&field2=" + indekmassatubuh + "&field3=" + sistolex + "&field4=" + diastolex + "&field5=" + output1 + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");
                                       
                             client.print("Host: api.thingspeak.com\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             client.print(postStr.length());
                             client.print("\n\n");
                             client.print(postStr);
                               
                             Serial.println(". Send to Thingspeak.");
                        }
                       
          client.stop();

          //Serial.println("Waiting...");

  delay(10000);
 
 }
}

void parsingData(){
int j=0;

//kirim data yang telah diterima sebelumnya
//Serial.print("data masuk : ");
//Serial.print(dataIn);
//Serial.print("\n");

//inisialisasi variabel, (reset isi variabel)
dt[j]="";
//proses parsing data
for(i=1;i<dataIn.length();i++){
//pengecekan tiap karakter dengan karakter (#) dan (,)
if ((dataIn[i] == '#') || (dataIn[i] == ','))
{
//increment variabel j, digunakan untuk merubah index array penampung
j++;
dt[j]="";       //inisialisasi variabel array dt[j]
}
else
{
//proses tampung data saat pengecekan karakter selesai.
dt[j] = dt[j] + dataIn[i];
}
}

 datain1 = dt[0].toInt();
 datain2 = dt[1].toInt();
 datain3 = dt[2].toInt();
 datain4 = dt[3].toInt();
 datain5 = dt[4].toInt();
 
//kirim data hasil parsing
Serial.print("data 1 : ");
Serial.print(datain1);
Serial.print("\n");
Serial.print("data 2 : ");
Serial.print(datain2);
Serial.print("\n");
Serial.print("data 3 : ");
Serial.print(datain3);
Serial.print("data 4 : ");
Serial.print(datain4);
Serial.print("data 5 : ");
Serial.print(datain5);

 kolesterolz = datain1 / 1;
 indekmassatubuh = datain2 / 1;
 sistolex = datain3 / 1;
 diastolex = datain4 / 1;
 output1 = datain5 /100.0;

}



d. VIDEO HASILNYA




Monitor PH dan Flow Air via Blynk 2.0 WEMOS D1

Monitor PH dan Flow Air via Blynk 2.0 WEMOS D1


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara untuk membuat sebuah alat yang dapat memonitor PH dan Flow air dengan menggunakan aplikasi Blynk 2.0. untuk mikrokontroller yang dipakai yaitu Wemos D1 sehingga bisa digunakan untuk IOT. untuk lebih jelasnya berikut adalah komponen dan kodingnya.


a. Komponen dan Skema





b. Program Arduino IDE

#define BLYNK_PRINT Serial

#define BLYNK_TEMPLATE_ID "YTRE6wKQ--abc"
#define BLYNK_TEMPLATE_NAME "monitor phflow"
#define BLYNK_AUTH_TOKEN "k8HmPp9dHXPjalYVO9cymS30_imbh6ty"

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

#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 cacah;
int dataadc;
float ph;

BlynkTimer timer;

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

void kirimdata()
{
  Blynk.virtualWrite(V0,ph);
  Blynk.virtualWrite(V1,flowRate);
}
 
void IRAM_ATTR pulseCounter()
{
  pulseCount++;
}

void setup() 
{
  Serial.begin(115200);
  lcd.begin(); //setting lcd
  lcd.clear(); //clear screen
  lcd.noCursor(); //tidak ada kursor
  
  pinMode(SENSOR, INPUT_PULLUP);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(1000L, kirimdata);
  
  pulseCount = 0;
  flowRate = 0.0;
  flowMilliLitres = 0;
  totalMilliLitres = 0;
  previousMillis = 0;
 
  attachInterrupt(digitalPinToInterrupt(SENSOR), pulseCounter, FALLING);
}

void loop() 
{

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

 currentMillis = millis();
  if (currentMillis - previousMillis > interval) 
  {
    
    pulse1Sec = pulseCount;
    pulseCount = 0;
 
    flowRate = ((1000.0 / (millis() - previousMillis)) * pulse1Sec) / calibrationFactor;
    previousMillis = millis();
 
    flowMilliLitres = (flowRate / 60) * 1000;
    flowLitres = (flowRate / 60);
 
    totalMilliLitres += flowMilliLitres;
    totalLitres += flowLitres;
     
}

lcd.setCursor(0,0);
lcd.print("P/F:");  
lcd.print(ph,1);  
lcd.print("/");
lcd.print(flowRate,1);  
lcd.print("  ");

if(flowRate > 30.0){  
lcd.setCursor(0,1);
lcd.print("BOCOR     ");  
}

if(flowRate <= 30.0){  
lcd.setCursor(0,1);
lcd.print("TDK BOCOR");  
}

if(ph > 7 ){
lcd.setCursor(10,1);
lcd.print("BASA  ");    
}

if(ph < 5 ){
lcd.setCursor(10,1);
lcd.print("ASAM  ");    
}

if((ph > 5 )&&(ph <= 8)){
lcd.setCursor(10,1);
lcd.print("NORMAL");    
}

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



c. VIDEO HASILNYA



Cara Upload Koding ke Arduino Nano (Terbaru)

Cara Upload Koding ke Arduino Nano (Terbaru)


         Seringnya error terjadi saat upload koding ke Arduino nano disebabkan firmware yang dipakai oleh arduino nano berbeda sehingga cara uploadnya juga ada sedikit perubahan yang harus dilakukan yaitu menyamakan versi arduinonya sesuai firmware yang dipakai arduino nano. berikut adalah tutorial cara upload koding ke arduino nano step by step.

File PDF bisa di download di link berikut. LINK DOWNLOAD









Kendali Motor Stepper Driver TB6600 Fitur Kendali Arah Putaran Menggunakan Potensio

Kendali Motor Stepper Driver TB6600 Fitur Kendali Arah Putaran Menggunakan Potensio


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat diatur arah putaran dan sudutnya dengan menggunakan potensio, jadi jika potensio ini berputar ke kanan maka motor stepper juga berputar ke kanan, jika potensio berputar ke arah kiri maka motor stepper juga akan bergerak ke arah kiri. jika potensio diam/stop maka motor stepper juga berhenti. untuk lebih jelasnya berikut adalah koding dan skemanya.
 


a. Skema Alat



b. Program Arduino IDE

#include <Wire.h>

#define dirPin 12
#define stepPin 11

int dataadc1,dataadc2,dataadcold;
int i;
int batasatas;
int batasbawah;

void setup() {
  Serial.begin(9600);
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
}

void loop() {

  dataadc1 = analogRead(A0);
  delay(100);

  Serial.print(dataadc1);
  Serial.print(" : ");
  Serial.println(dataadc2);
  batasatas = dataadc2 + 15;
  batasbawah = dataadc2 - 15;


if(dataadc1 > batasatas){ 
  Serial.println("KIRI");  
  for(i=0;i<30;i++){       
  digitalWrite(dirPin, LOW); // putar CW jarum jam
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(700); // ganti delay untuk mempercepat motor
  digitalWrite(stepPin, LOW);
  delayMicroseconds(700); // ganti delay untuk mempercepat motor
  }
  }

  if(dataadc1 < batasbawah){  
  Serial.println("KANAN");   
  for(i=0;i<30;i++){    
  digitalWrite(dirPin, HIGH); // putar CCW jarum jam
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(700); // ganti delay untuk mempercepat motor
  digitalWrite(stepPin, LOW);
  delayMicroseconds(700); // ganti delay untuk mempercepat motor
  }
  }

  if(dataadc1 == dataadc2){  
  Serial.println("STOP"); 
  }
  
dataadc2 = analogRead(A0);
delay(100);  
}


c. VIDEO HASILNYA


Kendali Motor Stepper Menggunakan Driver TB6600 dan Fitur Kendali Arah Putar dan Sudut Serta Kembali ke Posisi Awal

Kendali Motor Stepper Menggunakan Driver TB6600 dan Fitur Kendali Arah Putar dan Sudut Serta Kembali ke Posisi Awal


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat dikendalikan menggunakan pushbutton untuk arahnya dan potensio untuk mengatur sudut dari putaran motor stepper. alat ini juga tersedia fitur kembali ke posisi awal. untuk lebih jelasnya berikut adalah koding skemanya.


a. Skema Alat



b. Program Arduino IDE

#include <Wire.h>
#define dirPin 13
#define stepPin 12

int btkiri = 11;
int btkanan = 10;
int btreset = 9;
int dataadc;
int btkirix;
int btkananx;
int btresetx;
int kiri;
int kanan;
int pusat;
int langkah1,langkah2;
int derajat;
int i;

void setup() {
  Serial.begin(9600);
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  pinMode(btkiri,INPUT_PULLUP);
  pinMode(btkanan,INPUT_PULLUP);
  pinMode(btreset,INPUT_PULLUP);  
}

void loop() {
dataadc = analogRead(A0);
btkirix = digitalRead(btkiri);
btkananx = digitalRead(btkanan);
btresetx = digitalRead(btreset);

derajat = map(dataadc,0,1023,0,180);
Serial.print(pusat);
Serial.print(" : ");
Serial.print(langkah1);
Serial.print(" : ");
Serial.print(langkah2);
Serial.print(" : ");
Serial.println(derajat);

if(btkirix == 0){
  delay(500);
  for(i=0;i<derajat;i++){       
  digitalWrite(dirPin, LOW); // putar CW jarum jam
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(700); // ganti delay untuk mempercepat motor
  digitalWrite(stepPin, LOW);
  delayMicroseconds(700); // ganti delay untuk mempercepat motor
  }
  kanan++;    
}

if(btkananx == 0){
  delay(500);
  for(i=0;i<derajat;i++){       
  digitalWrite(dirPin, HIGH); // putar CCW jarum jam
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(700); // ganti delay untuk mempercepat motor
  digitalWrite(stepPin, LOW);
  delayMicroseconds(700); // ganti delay untuk mempercepat motor
  }
  kiri++;    
}


  pusat = kanan - kiri;
  langkah1 = kiri * derajat;
  langkah2 = kanan * derajat;
 
if(btresetx == 0){
  delay(500); 
  if(pusat > 0){ //ke kanan
  for(i=0;i<langkah2;i++){ //balik ke kiri       
  digitalWrite(dirPin, HIGH); // putar CCW jarum jam
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(700); // ganti delay untuk mempercepat motor
  digitalWrite(stepPin, LOW);
  delayMicroseconds(700); // ganti delay untuk mempercepat motor
  }
  pusat = 0;
  kiri = 0;
  kanan = 0;
  }

  if(pusat < 0){ // ke kiri
  for(i=0;i<langkah1;i++){ //nalik ke kanan      
  digitalWrite(dirPin, LOW); // putar CCW jarum jam
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(700); // ganti delay untuk mempercepat motor
  digitalWrite(stepPin, LOW);
  delayMicroseconds(700); // ganti delay untuk mempercepat motor
  }
  pusat = 0;
  kiri = 0;
  kanan = 0;
  }
}

delay(200);
}


c. VIDEO HASILNYA



Monitor BPM Wireless NRF24L01 Multiple Transmitter Receiver MAX30100 Server Thingspeak

Monitor BPM Wireless NRF24L01 Multiple Transmitter Receiver MAX30100 Server Thingspeak


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat alat yang dapat berfungsi sebagai penghitung Bpm pada 2 alat yang berbeda, alat ini menggunakan sistem wireless dengan 2 transmitter dan 1 receiver. untuk komunikasi wireless ini dengan menggunakan modul NRF24L01 pada 3 buah device tersebut. untuk sensor Bpmnya menggunakan MAX30100. untuk lebih jelasnya berikut adalah koding skemanya.



a. Skema Transmitter - Receiver



2. Program Arduino TRANSMITTER 1

#include <Wire.h>
#include <MAX30100_PulseOximeter.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"

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

MAX30100* pulseOxymeter;   //library

float sensorValue;
float tegangan;
int bpmku;
int counter;
float spo;
float bpm;
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
int cacah;
 
PulseOximeter pox;

uint32_t tsLastReport = 0;
String hrData = "";

void onBeatDetected()
{
//    Serial.println("Beat!");
}

RF24 radio(9, 10); // CE, CSN

const uint64_t pipe = 0xE8E8F0F0E1LL;
float dataku[4];
float b;

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

Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);

pulseOxymeter = new MAX30100();
 
if (!pox.begin()) {
 //Serial.println("FAILED");
  for(;;);
 } else {
 //Serial.println("SUCCESS");
}
 
  pox.setIRLedCurrent(MAX30100_LED_CURR_11MA);
  pox.setOnBeatDetectedCallback(onBeatDetected);

}

void loop(void){

pox.update();    
b = pox.getHeartRate();
//s = pox.getSpO2();

lcd.setCursor(0,0);
lcd.print("BPM1:");
lcd.print(b,1);
lcd.print("   ");

dataku[0] = 231;  // code to identify the transmitter. 
dataku[1] = b; 
radio.write( dataku, sizeof(dataku) );
 
}



3. Program Arduino TRANSMITTER 2

#include <Wire.h>
#include <MAX30100_PulseOximeter.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"

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

MAX30100* pulseOxymeter;   //library

float sensorValue;
float tegangan;
int bpmku;
int counter;
float spo;
float bpm;
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
int cacah;
float b,s,t;
float dataku[4];
 
PulseOximeter pox;

uint32_t tsLastReport = 0;
String hrData = "";

void onBeatDetected()
{
//    Serial.println("Beat!");
}

RF24 radio(9, 10); // CE, CSN

const uint64_t pipe = 0xE8E8F0F0E1LL;

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

Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);

pulseOxymeter = new MAX30100();
 
if (!pox.begin()) {
 //Serial.println("FAILED");
  for(;;);
 } else {
 //Serial.println("SUCCESS");
}
 
  pox.setIRLedCurrent(MAX30100_LED_CURR_11MA);
  pox.setOnBeatDetectedCallback(onBeatDetected);

}

void loop(void){

pox.update();    
s = pox.getHeartRate();

lcd.setCursor(0,0);
lcd.print("BPM2:");
lcd.print(s,1);
lcd.print("   ");

dataku[0] = 434;  // code to identify the transmitter. 
dataku[1] = s; 
radio.write( dataku, sizeof(dataku) );
 
}



4. Program Arduino Receiver

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <LiquidCrystal_I2C.h>

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

//Replace your wifi credentials here
const char* ssid     = "HOTSPOTHPKU";
const char* password = "123456789";

String apiKey = "UYT689JHVVNMI9UV";     //  Enter your Write API key from ThingSpeak
const char* resource = "/update?api_key=";
const char* server = "api.thingspeak.com";

int msg[1];
float b,s,t;
float data1; 
float data2; 
float dataku[4];
int cacah;

unsigned long lastReceiveTime = 0;
unsigned long currentTime = 0;
 
RF24 radio(D4,D3);

const uint64_t pipe = 0xE8E8F0F0E1LL;

WiFiClient  client;

void setup(){
 
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();

// Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

lcd.begin();
lcd.clear();
lcd.noCursor();
lcd.setCursor(0,0);
lcd.print("BPM1:");

}

void loop(){

if (radio.available()) { 
  
radio.read(dataku, sizeof(dataku));  
Serial.print(dataku[0]);
Serial.print(" : ");
Serial.println(dataku[1]);

if(dataku[0] == 231.0) // header
{
  data1 = dataku[1]; 
  lcd.setCursor(0,0);
  lcd.print("BPM1:");
  lcd.print(data1,1);
  lcd.print("   ");
}

if(dataku[0] == 434.0) // header
{
  data2 = dataku[1]; 
  lcd.setCursor(0,1);
  lcd.print("BPM2:");
  lcd.print(data2,1);
  lcd.print("   ");
}
 
}

if(cacah > 500){
cacah = 0;  
kirim();  
}

cacah++;
delay(10);      
}

void kirim(){
  
if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
{
                            
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(data1);
                             postStr += "\r\n\r\n";

                             client.print(String("GET ") + resource + apiKey + "&field1=" + data1 + "&field2=" + data2 + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");
                                       
                             client.print("Host: api.thingspeak.com\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             client.print(postStr.length());
                             client.print("\n\n");
                             client.print(postStr);
                             
                             Serial.println(". Send to Thingspeak.");
                        }
                        
          client.stop();

          Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
  delay(5000);
  
}



5. VIDEO HASILNYA