Translate

Timer Tamiya 3 Lap dan 3 Jalur / Line + Fitur Lastlap

Timer Tamiya 3 Lap dan 3 Jalur / Line + Fitur Lastlap


          Pada kesempatan kali ini saya akan menjelaska mengenai bagaimana cara membuat sebuah alat timer lomba tamiya untuk 3 jalur / Line, alat ini juga dibekali fitur lastlap jika terjadi mobil tamiya yang keluar jalur maka tombol lastlap diaktifkan. untuk lebih jelasnya berikut adalah koding dan skemanya.

  
1. Skema




2. Program Arduino IDE

#include <Wire.h>
#include <SPI.h>        //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h>        //Library DMD yang menyediakan fungsi penampilan teks, gambar dsb
#include <TimerOne.h>   //Library peripheral Timer1 untuk menjalankan prosedur pindai panel DMD
#include <Time.h>     //Library waktu yang menyediakan tipe data, struktur, dan obyek waktu
#include "Arial_black_16.h"
#include "Arial_Black_16_ISO_8859_1.h"
#include "Arial14.h"
#include "DejaVuSans9.h"
#include "Droid_Sans_12.h"
#include "Droid_Sans_16.h"
#include "DejaVuSansItalic9.h"
#include "Mono5x7.h"
#include "SystemFont5x7.h"

#define WAKTU_TAMPIL_JAM      10    //detik
#define WAKTU_TAMPIL_KALENDAR 5     //detik

#define DISPLAY_COLUMN_COUNT  2
#define DISPLAY_ROW_COUNT     1

#define PIXELS_PER_COLUMN  32
#define PIXELS_PER_ROW    16

DMD dmd(DISPLAY_COLUMN_COUNT, DISPLAY_ROW_COUNT);
unsigned char show = 0;

char lineBuff[20];
char lineBuff2[20];

int lineA;
int lineB;
int lineC;
int mulai;
int seconds;
int cs;
long start_time = 0;
int lapa,lapb,lapc;
int btlastlap = 5;
int btlastlapx;
int led1 = A0;
int led2 = A1;
int led3 = A2;

void ScanDMD()
{
  dmd.scanDisplayBySPI();
}

void setup(void)
{
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(btlastlap,INPUT_PULLUP);

  dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)
  Serial.begin(9600);
   //initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
  Timer1.initialize( 1000 );           //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.
  Timer1.attachInterrupt( ScanDMD );   //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI() 
  //clear/init the DMD pixels held in RAM
  dmd.clearScreen( true );
}

void loop(void)
{

//============================================
lineA = digitalRead(2);
lineB = digitalRead(3);
lineC = digitalRead(4);
btlastlapx = digitalRead(btlastlap);


if(btlastlapx == 1){
if((lineA == 0)&&(lineB == 1)&&(lineC == 1)&&(mulai == 1)){
lapa++;
delay(100);
}

if((lineA == 1)&&(lineB == 0)&&(lineC == 1)&&(mulai == 1)){
lapb++;
delay(100);
}

if((lineA == 1)&&(lineB == 1)&&(lineC == 0)&&(mulai == 1)){
lapc++;
delay(100);
}

if((lineA == 0)&&(lineB == 0)&&(lineC == 1)&&(mulai == 1)){
lapa++;
lapb++;
delay(100);
}

if((lineA == 0)&&(lineB == 1)&&(lineC == 0)&&(mulai == 1)){
lapa++;
lapc++;
delay(100);
}

if((lineA == 1)&&(lineB == 0)&&(lineC == 0)&&(mulai == 1)){
lapb++;
lapc++;
delay(100);
}

if((lineA == 0)&&(lineB == 0)&&(lineC == 0)&&(mulai == 1)){
lapa++;
lapb++;
lapc++;
delay(100);
}

//=============================================
if(lapa > 2){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
hasila();  
}

if(lapb > 2){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
hasilb();  
}

if(lapc > 2){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
hasilc();  
}
}

//===========================================================
if(btlastlapx == 0){
if((lineA == 0)&&(lineB == 1)&&(lineC == 1)&&(mulai == 1)){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
hasila();  
delay(100);
}

if((lineA == 1)&&(lineB == 0)&&(lineC == 1)&&(mulai == 1)){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
digitalWrite(led3,LOW);
hasilb();  
delay(100);
}

if((lineA == 1)&&(lineB == 1)&&(lineC == 0)&&(mulai == 1)){
dmd.clearScreen( true );   
sprintf(lineBuff2, "WIN", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
delay(2000);
dmd.clearScreen( true );  
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,HIGH);
hasilc();  
delay(100);
}
}

//=============================================
lineA = digitalRead(2);
lineB = digitalRead(3);
lineC = digitalRead(4);

if((lineA == 0)&&(mulai == 0)){
  delay(200);
  mulai = 1;
  start_time = millis();  
}  

if((lineB == 0)&&(mulai == 0)){
  delay(200);
  mulai = 1;
  start_time = millis();  

if((lineC == 0)&&(mulai == 0)){
  delay(200);
  mulai = 1;
  start_time = millis();  

if(mulai == 1){
seconds = (millis() - start_time) / 1000;
cs = ((millis() - start_time) / 10) % 100;;
}

//===========================================================================  
sprintf(lineBuff, "%d:%d ", seconds, cs);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 37,  3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  

sprintf(lineBuff2, "%d/%d/%d ", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  
//===========================================================================

}

void hasila(){
sprintf(lineBuff, "%d:%d ", seconds, cs);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 35,  3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  

sprintf(lineBuff2, " A", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  

hasila();  
}


void hasilb(){
sprintf(lineBuff, "%d:%d ", seconds, cs);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 35,  3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  

sprintf(lineBuff2, " B", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  

hasilb();  
}


void hasilc(){
sprintf(lineBuff, "%d:%d ", seconds, cs);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 35,  3, lineBuff, strlen(lineBuff), GRAPHICS_NORMAL);  

sprintf(lineBuff2, " C", lapa, lapb, lapc);
dmd.selectFont(Droid_Sans_12);
dmd.drawString( 3,  3, lineBuff2, strlen(lineBuff2), GRAPHICS_NORMAL);  

hasilc();  
}



3. VIDEO HASILNYA


Cara Upload Program Ke Arduino Wifi an Tutorial Connect ke Blynk 2.0

Cara Upload Program Ke Arduino Wifi an Tutorial Connect ke Blynk 2.0



         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara untuk upload koding ke arduino wifi yang mana pada arduino wifi terdapat 2 device yaitu arduino uno dan esp8266. untuk contoh dipakai project untuk monitoring tekanan udara via Blynk 2.0. 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);

float pressure_pascal;
float pressure_bar;
int dataadc;
int x;
float v;
float kpa;
float mpa;
int buzzer = 7;

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

void loop() {
 
  x = analogRead(A0);
  v = x*(5.0/1023.0);
  pressure_pascal = (3.0*(v-0.47))*1000000.0;
  pressure_bar = pressure_pascal/10e5;

  lcd.setCursor(0, 0);
  lcd.print("Bar= ");
  lcd.print(pressure_bar);
  lcd.print("   ");

//high 5bar, low 3 bar
if(pressure_bar >= 5){
  digitalWrite(buzzer,HIGH);
  delay(3000);
}

if((pressure_bar >= 3)&&(pressure_bar < 5)){
  digitalWrite(buzzer,LOW);
}   

if((pressure_bar > 0.2)&&(pressure_bar < 3)){
  digitalWrite(buzzer,HIGH);
}  

Serial.println(pressure_bar * 1000);
 
delay(200);  
}



3. Program ESP8266

#define BLYNK_TEMPLATE_ID "TMPL6wOC--xxx"
#define BLYNK_TEMPLATE_NAME "monitor daya"
#define BLYNK_AUTH_TOKEN "VOK0cWiFN5ycHj3SV_snEDXTfTfeixxx"
#define BLYNK_PRINT Serial    

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
int temp;
int x = 5;
int y;
int value1;
int value2;
int tekanan = 0;
float fix;
float datain1;
String dataIn;
String dt[10];
int i;
boolean parsing=false;
int pinValue;
int pinValue2;
int pinValue3;
BlynkTimer timer;
char ssid[] = "hotspothpku";
char pass[] = "123456789";

void sendSensor()
{
 Blynk.virtualWrite(V0, fix);
 delay(1000);
}

void setup()
{
  dataIn=""; 
  // Debug console
 Serial.begin(9600);
 Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
 timer.setInterval(1000L, sendSensor);
}

void loop()
{
  tekanan = Serial.parseInt();;
  fix = tekanan / 1000.0;
  
  Blynk.run();
  timer.run();
}



4. VIDEO HASILNYA



Alat Hitung Butiran Input Keypad ARduino Sensor IR Proximity

Alat Hitung Butiran Input Keypad ARduino Sensor IR Proximity


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat menghitung butiran misal butiran obat sehingga tak perlu hitung manual. alat ini dibekaki dengan sensor proximity dan arduino nano dengan input keypad 4x4. untuk lebih jelasnya berikut adalah koding dan skemanya.


1. Skema 



2. Program Arduino IDE

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

LiquidCrystal_I2C lcd(0x27, 16, 2);

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};
byte colPins[COLS] = {6,7,8,9};
long angka;

Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
int in1 = 11;
int in2 = 12;
int counter;
int x;

void setup()
{
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  pinMode(in1,OUTPUT);
  pinMode(in2,OUTPUT);
  pinMode(10,INPUT);
  digitalWrite(in1,LOW);
  digitalWrite(in2,LOW);
}

void loop()
{
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);

lcd.setCursor(0,0);
lcd.print("Input Butiran?");
lcd.setCursor(0,1);
lcd.print("Vol: ");  

  customKey = customKeypad.getKey();
  if(customKey >= '0' && customKey <= '9')
    {
      angka = angka * 10 + (customKey - '0');
      lcd.print(angka);
      lcd.print("  ");
    }

   if(customKey == 'A'){         
      lcd.clear();
      delay(1000);
      counter = 0;
      mulai(); 
    }

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

void mulai(){

lcd.setCursor(0,1);
lcd.print("Target: ");
lcd.print(angka);
lcd.print(" butir ");

analogWrite(in1,120);
analogWrite(in2,0);

x = digitalRead(10); 

if(x == 0){
counter++;  
}

if(counter >= angka){
analogWrite(in1,0);
analogWrite(in2,0);
delay(200);  
analogWrite(in1,0);
analogWrite(in2,130);
delay(300);
lcd.clear();
return;  
}

lcd.setCursor(0,0);
lcd.print("Vol: ");
lcd.print(counter);
lcd.print("  ");
    
customKey = customKeypad.getKey();

 if(customKey == 'B'){         
   lcd.clear();
   delay(1000);
   return;
 } 

delay(1);       
mulai();  
}



3. VIDEO HASILNYA


Spirometri PEF Flow Interface Grafik LCD TFT ILI9341 Hasil Bisa di Print

Spirometri PEF Flow Interface Grafik LCD TFT ILI9341 Hasil Bisa di Print


         Pada kesempaan kali ini saya akan menjelaskan mengenai bagaimaa cara membuat alat yang dapat memonitor spirometri dengan menggunakan sensor flow meter dan interface yang dipakai adalah lcd tft ili9341 dan hasilnya bisa diprint. untuk lebih jelasnya berikut adalah koding dan skemanya.


1. Skema




2. Program Aduino IDE

#include "Wire.h"
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <SoftwareSerial.h>
SoftwareSerial Thermal(3, 4);

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 320

#define MINOR_GRID tft.color565(100, 100, 255)
#define MAJOR_GRID tft.color565(0, 0, 255)
#define GRID_EDGE tft.color565(255, 0, 0)
#define V_CENTER tft.color565(255, 0, 0)
#define H_CENTER tft.color565(255, 0, 0)

#define TFT_CS         10
#define TFT_DC         8
//#define TFT_LED      5v
#define TFT_RST        9
#define TFT_MOSI       11
#define TFT_CLK        13
#define TFT_MISO       12

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

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;
float liter;
unsigned long oldTime;

unsigned long start_times[100];
unsigned long stop_times[100];
unsigned long values[100];
int i1;
int z1;
int i2;
float z2;
int counter1;
int counter2;
float rumus;

int x=0;
int lastx=0;
int lasty=150;

int x1=0;
int lastx1=0;
int lasty1=0;

int x2=0;
int lastx2=0;
int lasty2=0;
int dataadc;

int lebar;
int tinggi;
int geser = 0;

int btprint = 7;
int btprintx;
int zero=0;
int heatTime = 80;
int heatInterval = 255;
char printDensity = 15;
char printBreakTime = 15;

void setup() {
  tft.begin();
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextSize(2);
  tft.setRotation(1); 
  drawGrid(); 
  Serial.begin(9600);
  pinMode(btprint, INPUT_PULLUP);
  Thermal.begin(9600); // to write to our new printer
  initPrinter();
  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);
  
  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;
  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}

void loop() 
{

  lebar = tft.width(); 
  tinggi = tft.height();
  tft.drawLine(0,115,lebar,115,ILI9341_RED);
  
  if(x > lebar)  
  {
    tft.fillRect(0,80,320,75,ILI9341_BLACK);
    x=0;
    lastx=x;
    drawGrid();
  }

  //aktifkan sensor flow
  if((millis() - oldTime) > 1000)
  {
    detachInterrupt(sensorInterrupt);
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    oldTime = millis();
    flowMilliLitres1 = (flowRate / 60) * 1000;
    totalMilliLitres += flowMilliLitres1;
    liter = flowMilliLitres1 / 100.0;
    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
  }

  
  tft.setTextColor(ILI9341_YELLOW,ILI9341_BLACK);  
  int y = 150 - ( liter * 10 );
  tft.drawLine(lastx,lasty,x,y,ILI9341_WHITE);
  lasty = y;
  lastx = x;

  tft.setCursor(5, 10);
  tft.setTextColor(ILI9341_YELLOW,ILI9341_BLACK);  
  tft.print("SVC: ");  
  tft.print(z1);  
  tft.print(" L/min  ");  
  
  x = x + 3;
  x1++;
  x2++;

delay(1000);

btprintx = digitalRead(btprint);

if(btprintx == 0){
  Thermal.write(27);
  Thermal.write(45);
  Thermal.write(1);
  Thermal.print("SVC = ");
  Thermal.print(z1);
  Thermal.println(" L/Min ");
  Thermal.write(10);
  Thermal.write(10); 
  z1 = 0;
  delay(3000);
}

}

void drawGrid()
{
  for (int v = 5; v < SCREEN_WIDTH; v += 10)
  {
    // minor: 5,15,25 etc /
    tft.drawFastVLine(v, 0, SCREEN_HEIGHT, MINOR_GRID);
  }
  for (int h = 5; h < SCREEN_HEIGHT; h += 10)
  {
    // minor: 5,15,25 etc
    tft.drawFastHLine(0, h, SCREEN_HEIGHT, MINOR_GRID);
  }

  // next major lines, overlapping the minor lines at cross-sections
  for (int v = 10; v < SCREEN_WIDTH; v += 10)
  {
    // main: 0,10,20 etc
    tft.drawFastVLine(v, 0, SCREEN_HEIGHT, MAJOR_GRID);
  }
  for (int h = 10; h < SCREEN_HEIGHT; h += 10)
  {
    // main: 0,10,20 etc
    tft.drawFastHLine(0, h, SCREEN_HEIGHT, MAJOR_GRID);
  }
  // edge lines
  tft.drawFastVLine(0, 0, SCREEN_HEIGHT - 1, GRID_EDGE);
  tft.drawFastVLine(SCREEN_WIDTH - 1, 0, SCREEN_HEIGHT - 1, GRID_EDGE);
  tft.drawFastHLine(0, 0, SCREEN_WIDTH - 1, GRID_EDGE);
  tft.drawFastHLine(0, SCREEN_HEIGHT - 1, SCREEN_HEIGHT - 1, GRID_EDGE);
  // center lines
  tft.drawFastVLine(SCREEN_WIDTH / 2, 0, SCREEN_HEIGHT, V_CENTER);
  //tft.drawFastHLine(0, SCREEN_HEIGHT / 2 - 1, SCREEN_HEIGHT - 1, V_CENTER);
}

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

void pulseCounter()
{
  pulseCount++;
}



3. VIDEO HASILNYA



Tensimeter Digital Interface LCD TFT ILI9341

Tensimeter Digital Interface LCD TFT ILI9341


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor tensi yaitu sistol dan diastol dengan lcd TFT ILI9341 dengan mikrokontroller yang dipakai yaitu wemos d1 mini. untuk lebih jelasnya berikut aalah koding dan skemanya.


1. Skema



2. Program Arduino IDE

#include <Arduino.h>
#include <math.h>
#include <Wire.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "MAX30100.h"

#define TFT_CS         10
#define TFT_DC         8
//#define TFT_LED      5v
#define TFT_RST        9
#define TFT_MOSI       11
#define TFT_CLK        13
#define TFT_MISO       12

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

MAX30100* pulseOxymeter;

int motor1 = 3;
int motor2 = 4;
int solenoid1 = 5;
int solenoid2 = 6;

float spo;
float bpm;
int counter;
int dataadc;
int tombol = 7;
int tombolx;
int hitung;
float vol;
float mmhg;
float mmhgx;
float sistole;
float diastole;
int sistolex;
int diastolex;
int mark = 0;

void setup() {
  
  Serial.begin(9600);
  tft.begin();
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextSize(2);
  tft.setRotation(3); 

  pinMode(motor1,OUTPUT);
  pinMode(motor2,OUTPUT);
  pinMode(solenoid1,OUTPUT);
  pinMode(solenoid2,OUTPUT);
  pinMode(tombol,INPUT_PULLUP);

  digitalWrite(motor1,LOW);
  digitalWrite(motor2,LOW);
  digitalWrite(solenoid1,LOW);
  digitalWrite(solenoid2,LOW);

  Wire.begin();
  pulseOxymeter = new MAX30100();
}

void loop() 
{

pulseoxymeter_t result = pulseOxymeter->update();
  
if( result.pulseDetected == true )
  {        
    bpm = result.heartBPM;
    spo = result.SaO2;
  }
  
  tft.setCursor(10, 10);
  tft.setTextColor(ILI9341_YELLOW,ILI9341_BLACK);  
  tft.print("Sis/Dia: ");  
  tft.print(sistolex);  
  tft.print(" / "); 
  tft.print(diastolex);  
  tft.print("  "); 

  tft.setCursor(10, 40);
  tft.setTextColor(ILI9341_GREEN,ILI9341_BLACK);  
  tft.print("B/S: ");  
  tft.print(bpm);  
  tft.print(" / "); 
  tft.print(spo);  
  tft.print("  "); 
  
 tombolx = digitalRead(tombol); 

 if(tombolx == LOW){
  mark = 0;
  delay(1000);
  digitalWrite(motor1,HIGH);
  digitalWrite(motor2,LOW);
  digitalWrite(solenoid1,HIGH);
  digitalWrite(solenoid2,LOW);
  mulai();
  }

counter++;

if(counter > 100){
 counter = 0;
}

}

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

if((mmhg >= mmhgx + 10)&&(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)){
//digitalWrite(motor,LOW); 
Serial.println("DIASTOLE"); 
diastole = mmhg;
mark = 3;
}

  tft.setCursor(10, 80);
  tft.setTextColor(ILI9341_YELLOW,ILI9341_BLACK);  
  tft.print("S: ");  
  tft.print(mmhg);  
  tft.print("  ");  

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

mmhgx = mmhg;

//Serial.println(mmhg);

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

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

delay(1);   
mulai();  
}



3. VIDEO HASILNYA


Monitor Bpm dan SpO2 Serta Tensimeter Digital IOT Blynk 2.0

Monitor Bpm dan SpO2 Serta Tensimeter Digital IOT Blynk 2.0


         Pada kesempatan kali ini saya akan menjeleskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor Bpm dan Spo2 serta tensimeter digital dengan cloud IOT Blynk 2.0. untuk lebih jelasnya berikut adalah koding dan skemanya.


1. Skema

                                              


2. Program Arduino IDE

#define BLYNK_TEMPLATE_ID "TMPL6uaNqxxxx"
#define BLYNK_TEMPLATE_NAME "Alat monitoring tekanan darah spo2 dan bpm "
#define BLYNK_AUTH_TOKEN "fpHFk84dHa9Fn-CUscE5eAIoQ0jxxxxx"
#define BLYNK_PRINT Serial  

#define  BLYNK_PRINT Serial  
#include <Arduino.h>
#include <math.h>
#include <Wire.h> 
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "MAX30100_PulseOximeter.h"
#include <LiquidCrystal_I2C.h>

#define REPORTING_PERIOD_MS     1000

LiquidCrystal_I2C lcd(0x27, 16,2);

BlynkTimer timer;

PulseOximeter pox;

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

float spo;
float bpm;
int counter;
int motor = D7;
int solenoid = D6;
int dataadc;
int tombol = D4;
int tombolx;
int hitung;
float vol;
float mmhg;
float mmhgx;
float sistole;
float diastole;
int sistolex;
int diastolex;
int mark = 0;

uint32_t tsLastReport = 0;

// Callback routine is executed when a pulse is detected
void onBeatDetected() {

}

void sendSensor()
{
 Blynk.virtualWrite(V0, sistolex);
 Blynk.virtualWrite(V1, diastolex);
 Blynk.virtualWrite(V2, bpm);
 Blynk.virtualWrite(V3, spo);
 delay(1000);
}

void setup() {
  lcd.clear();
  lcd.begin();
  lcd.noCursor();
 
  pinMode(motor,OUTPUT);
  pinMode(solenoid,OUTPUT);
  pinMode(tombol,INPUT_PULLUP);
  digitalWrite(motor,LOW);
  digitalWrite(solenoid,LOW);
  
  Wire.begin();
  Serial.begin(9600);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(1L, sendSensor);
  
  // Initialize sensor
    if (!pox.begin()) {
        Serial.println("FAILED");
        for(;;);
    } else {
        Serial.println("SUCCESS");
    }

  // Configure sensor to use 7.6mA for LED drive
  pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);

    // Register a callback routine
    pox.setOnBeatDetectedCallback(onBeatDetected);

}

void loop() {
 pox.update();

    // Grab the updated heart rate and SpO2 levels
    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
       lcd.setCursor(0,0);
       lcd.print("BPM= ");
       lcd.print(pox.getHeartRate());
       lcd.print("/");
       lcd.print(pox.getSpO2());
       lcd.print("   ");
    
        bpm = pox.getHeartRate();
        spo = pox.getSpO2();
        tsLastReport = millis();
    }

 lcd.setCursor(0,1);
 lcd.print("S= ");
 lcd.print(sistolex);
 lcd.print(" D= ");
 lcd.print(diastolex);
 lcd.print("    ");
   
 tombolx = digitalRead(tombol); 

 if(tombolx == LOW){
  mark = 0;
  lcd.clear();
  delay(1000);
  digitalWrite(motor,HIGH);
  digitalWrite(solenoid,HIGH);
  mulai();
  }

}

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

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

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

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

if(mmhg >= 150)
{
 digitalWrite(motor,LOW);   
}

mmhgx = mmhg;

Serial.println(mmhg);

if((mark == 3)&&(mmhg < 50)){
lcd.clear();
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = diastole;
digitalWrite(solenoid,LOW);
Blynk.run();
timer.run();
selesai(); 
}

if((mark == 2)&&(mmhg < 50)){
lcd.clear();
delay(1000);
mark = 0;
sistolex = sistole;
diastolex = random(60,90);
digitalWrite(solenoid,LOW);
Blynk.run();
timer.run();
selesai();
}

delay(1);   
mulai();  
}

void selesai(){

 lcd.setCursor(0,0);
 lcd.print("BPM= ");
 lcd.print(bpm);
 lcd.print("/");
 lcd.print(spo);
 lcd.print("   ");
 lcd.setCursor(0,1);
 lcd.print("S= ");
 lcd.print(sistolex);
 lcd.print(" D= ");
 lcd.print(diastolex);
 lcd.print("    ");         
 Blynk.run();
 timer.run();

 selesai();    
}


3. VIDEO HASILNYA





Monitor Suhu dan BPM Fuzzy Logic Mamdani EFLL IOT Blynk 2.0 (Deteksi Hipotermia)

Monitor Suhu dan BPM Fuzzy Logic Mamdani EFLL IOT Blynk 2.0


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor suhu dan bpm dengan metode logika fuzzy mamdani. alat ini dipakai untuk mendeteksi penyakit hipotrmia ketika berada di gunung. untuk lebih jelasnya berikut adalah koding dan skemanya.  


1. Skema



2. Program Arduino IDE

#include <Fuzzy.h>
#include <Wire.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <LiquidCrystal_I2C.h>

#define ONE_WIRE_BUS 2  

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

LiquidCrystal_I2C lcd(0x27, 16, 2);

float tempobject;
float temppeltier;
int dataadc;
int n = 0;
int bpm = 0;
int x = 0;
int bpmnya = 0;

Fuzzy *fuzzy = new Fuzzy();

// FuzzyInput
FuzzySet *dingin = new FuzzySet(0, 0, 25, 28);
FuzzySet *sedang = new FuzzySet(28, 33, 33, 35);
FuzzySet *aman = new FuzzySet(35, 40, 50, 50);

// FuzzyInput
FuzzySet *lambat = new FuzzySet(0, 0, 50, 60);
FuzzySet *normal = new FuzzySet(60, 80, 80, 100);
FuzzySet *cepat = new FuzzySet(100, 130, 150, 150);

// FuzzyOutput
FuzzySet *minimum = new FuzzySet(0, 0, 30, 50);
FuzzySet *average = new FuzzySet(50, 75, 75, 100);
FuzzySet *maximum = new FuzzySet(100, 150, 200, 200);

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

  // FuzzyInput suhuobject
  FuzzyInput *suhuobject = new FuzzyInput(1);

  suhuobject->addFuzzySet(dingin);
  suhuobject->addFuzzySet(sedang);
  suhuobject->addFuzzySet(aman);
  fuzzy->addFuzzyInput(suhuobject);

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

  nilaibpm->addFuzzySet(lambat);
  nilaibpm->addFuzzySet(normal);
  nilaibpm->addFuzzySet(cepat);
  fuzzy->addFuzzyInput(nilaibpm);

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

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

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

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

  // Building FuzzyRule 3
  FuzzyRuleAntecedent *ifsuhuobjectDinginAndnilaibpmCepat = new FuzzyRuleAntecedent();
  ifsuhuobjectDinginAndnilaibpmCepat->joinWithAND(dingin, cepat); 
  FuzzyRuleConsequent *thenPwmoutAverage= new FuzzyRuleConsequent();
  thenPwmoutAverage->addOutput(average);
  FuzzyRule *fuzzyRule3 = new FuzzyRule(3, ifsuhuobjectDinginAndnilaibpmNormal, thenPwmoutAverage);
  fuzzy->addFuzzyRule(fuzzyRule3);

  // Building FuzzyRule 4
  FuzzyRuleAntecedent *ifsuhuobjectSedangAndnilaibpmLambat = new FuzzyRuleAntecedent();
  ifsuhuobjectSedangAndnilaibpmLambat->joinWithAND(sedang, lambat); 
  //FuzzyRuleConsequent *thenPwmoutAverage= new FuzzyRuleConsequent();
  thenPwmoutAverage->addOutput(average);
  FuzzyRule *fuzzyRule4 = new FuzzyRule(4, ifsuhuobjectSedangAndnilaibpmLambat, thenPwmoutAverage);
  fuzzy->addFuzzyRule(fuzzyRule4);

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

    // Building FuzzyRule 6
  FuzzyRuleAntecedent *ifsuhuobjectSedangAndnilaibpmCepat = new FuzzyRuleAntecedent();
  ifsuhuobjectSedangAndnilaibpmCepat->joinWithAND(sedang, cepat); 
  //FuzzyRuleConsequent *thenPwmoutAverage= new FuzzyRuleConsequent();
  thenPwmoutAverage->addOutput(average);
  FuzzyRule *fuzzyRule6 = new FuzzyRule(6, ifsuhuobjectSedangAndnilaibpmCepat, thenPwmoutAverage);
  fuzzy->addFuzzyRule(fuzzyRule6);

  // Building FuzzyRule 7
  FuzzyRuleAntecedent *ifsuhuobjectAmanAndnilaibpmLambat = new FuzzyRuleAntecedent();
  ifsuhuobjectAmanAndnilaibpmLambat->joinWithAND(aman, lambat); 
  //FuzzyRuleConsequent *thenPwmoutAverage= new FuzzyRuleConsequent();
  thenPwmoutAverage->addOutput(average);
  FuzzyRule *fuzzyRule7 = new FuzzyRule(7, ifsuhuobjectAmanAndnilaibpmLambat, thenPwmoutAverage);
  fuzzy->addFuzzyRule(fuzzyRule7);

  // Building FuzzyRule 8
  FuzzyRuleAntecedent *ifsuhuobjectAmanAndnilaibpmNormal = new FuzzyRuleAntecedent();
  ifsuhuobjectAmanAndnilaibpmNormal->joinWithAND(aman, normal); 
  FuzzyRuleConsequent *thenPwmoutMinimum= new FuzzyRuleConsequent();
  thenPwmoutMinimum->addOutput(minimum);
  FuzzyRule *fuzzyRule8 = new FuzzyRule(8, ifsuhuobjectAmanAndnilaibpmNormal, thenPwmoutMinimum);
  fuzzy->addFuzzyRule(fuzzyRule8);

  // Building FuzzyRule 9
  FuzzyRuleAntecedent *ifsuhuobjectAmanAndnilaibpmCepat = new FuzzyRuleAntecedent();
  ifsuhuobjectAmanAndnilaibpmCepat->joinWithAND(aman, cepat); 
  //FuzzyRuleConsequent *thenPwmoutMinimum= new FuzzyRuleConsequent();
  thenPwmoutMinimum->addOutput(minimum);
  FuzzyRule *fuzzyRule9 = new FuzzyRule(9, ifsuhuobjectAmanAndnilaibpmCepat, thenPwmoutMinimum);
  fuzzy->addFuzzyRule(fuzzyRule9);
  
}

void loop()
{

  sensors.requestTemperatures();
  tempobject = sensors.getTempCByIndex(0);
  bpm = 0;
  bpmxx();
  
  lcd.setCursor(0, 0);
  lcd.print("T = ");
  lcd.print(tempobject);
  lcd.print(" "); 
    
  fuzzy->setInput(1, tempobject);
  fuzzy->setInput(2, bpm);

  fuzzy->fuzzify();
  
/*
  Serial.print("Suhu Object: Dingin-> ");
  Serial.print(dingin->getPertinence());
  Serial.print(", Normal-> ");
  Serial.print(sedang->getPertinence());
  Serial.print(", Panas-> ");
  Serial.println(aman->getPertinence());

  Serial.print("BPM: Rendah-> ");
  Serial.print(lambat->getPertinence());
  Serial.print(",  Sedang-> ");
  Serial.print(normal->getPertinence());
  Serial.print(",  Tinggi-> ");
  Serial.print(cepat->getPertinence());
*/

  float output1 = fuzzy->defuzzify(1);

/*
  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());
*/

  lcd.setCursor(10, 0);
  lcd.print(output1);
  lcd.print(" "); 

  if(output1 <= 50){
  lcd.setCursor(6, 1);
  lcd.print("NMRL");  
  }

  if((output1 > 50)&&(output1 <= 100)){
  lcd.setCursor(6, 1);
  lcd.print("SDNG");  
  }

  if((output1 > 100)&&(output1 < 200)){
  lcd.setCursor(6, 1);
  lcd.print("HYPO");  
  }

  Serial.print("*");
  Serial.print(tempobject);
  Serial.print(",");
  Serial.print(bpmnya);
  Serial.print(",");
  Serial.print(output1);
  Serial.println("#");
  
  delay(1000);
}

void bpmxx(){
  
n++;

  int dataadc = analogRead(A0);           

  lcd.setCursor(14, 1);
  lcd.print(n);
    
  lcd.setCursor(0, 1);
  lcd.print("B=");
  lcd.print(bpmnya);
  //lcd.print(" / ");
  //lcd.print(dataadc1);
  lcd.print(" ");
   
  if ((dataadc > 820) && (x > 1)) {   
  x = 0;
  bpm = bpm + 1;
  }

  else if ((dataadc < 820) && (x < 1)) {
  x = 2;  
  }

  delay(200);

  if ( n > 50 ) {
  bpmnya = bpm * 6;
  n = 0;
  return;
  }  
  
bpmxx();  
}


3. Program ESP8266

#define BLYNK_TEMPLATE_ID "TMPL6wOC--xxx"
#define BLYNK_TEMPLATE_NAME "monitor daya"
#define BLYNK_AUTH_TOKEN "VOK0cWiFN5ycHj3SV_snEDXTfTfeixxx"
#define BLYNK_PRINT Serial  

#define  BLYNK_PRINT Serial  
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

int suhu = 0;
int bpm = 0;
int output1 = 0;

int datain1;
int datain2;
int datain3;

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

BlynkTimer timer;

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

void sendSensor()
{
 Blynk.virtualWrite(V0, suhu);
 Blynk.virtualWrite(V1, bpm);
 Blynk.virtualWrite(V2, output1);
 delay(1000);
}

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

  dataIn=""; 

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

void loop(){

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

if(parsing){
  parsingData();
  parsing=false;
  dataIn="";
    
  Blynk.run();
  timer.run();
}

}

void parsingData(){
  
int j=0;

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

//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();

suhu = datain1 / 1;
bpm = datain2 / 1;
output1 =datain3 / 1;
 
//kirim data hasil parsing
Serial.print("data 1 : ");
 Serial.println(datain1);
Serial.print("data 2 : ");
Serial.println(datain2);
Serial.print("data 3 : ");
Serial.println(datain3);
 Serial.print("\n\n");

}



4. VIDEO HASILNYA