Translate

Arduino RPM Meter Speedometer (TACHOMETER)

Arduino RPM Meter (TACHOMETER) 


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat menghitung kecepatan putaran motor atau gerakan dengan satuan menit. alat ini menggunakan arduino uno dan sensor photodioda dan led inframerah. untuk lebih jelasnya berikut adalah koding dan skemanya.


1. Skema



2. Program Arduino IDE

#include <Wire.h>

#define sensor 2

int rpm = 0;
unsigned long millisBefore;
volatile int objects;
int servorange;

void setup()
{
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(2), count, FALLING);
  delay(1000);
  pinMode(2, INPUT);
}

void loop(){
 
    if (millis() - millisBefore > 1000) {
    rpm = (objects / 3.0)*60;
    objects = 0;
    millisBefore = millis();
    }

    Serial.println(rpm);
    
delay(100);
}
    
void count() {
  objects++;
}



Kendali Motor Stepper Driver DM542 ARDUINO

Kendali Motor Stepper Driver DM542 ARDUINO


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengendalikan arah putaran motor stepper dengan menggunakan driver DM542. untuk mikrokontroler yang dipakai yaitu Arduino Nano. untuk lebih jelasnya berikut adalah koding dan skemanya. 



1. Skema









2. Program Arduino IDE

int stepPin1 = 2;
int dirPin1 = 3;
int enblPin1 = 4;

int stepPin2 = 5;
int dirPin2 = 6;
int enblPin2 = 7;

int switch1;
int switch2;
int switch3;
int switch4;
int x;

void setup() {

Serial.begin(9600);

pinMode (A0, INPUT_PULLUP);
pinMode (8, INPUT_PULLUP);
pinMode (9, INPUT_PULLUP);
pinMode (10, INPUT_PULLUP);
  
pinMode (stepPin1, OUTPUT);
pinMode (dirPin1, OUTPUT);
pinMode (enblPin1, OUTPUT);
digitalWrite(enblPin1, HIGH);

pinMode (stepPin2, OUTPUT);
pinMode (dirPin2, OUTPUT);
pinMode (enblPin2, OUTPUT);
digitalWrite(enblPin2, HIGH);
}

void loop() {

switch1 = digitalRead(A0);
switch2 = digitalRead(8);
switch3 = digitalRead(9);
switch4 = digitalRead(10);

Serial.print(switch1);
Serial.print("/");
Serial.print(switch2);
Serial.print("/");
Serial.print(switch3);
Serial.print("/");
Serial.println(switch4);

if((switch1 == 1)&&(switch2 == 1)&&(switch3 == 1)&&(switch4 == 1)){
//stop  
digitalWrite(enblPin1, LOW);
digitalWrite(enblPin2, LOW);

digitalWrite(stepPin1, LOW);
delayMicroseconds(700);
digitalWrite(stepPin1, LOW);
delayMicroseconds(700);

digitalWrite(stepPin2, LOW);
delayMicroseconds(700);
digitalWrite(stepPin2, LOW);
delayMicroseconds(700);
}

if((switch1 == 0)&&(switch2 == 1)&&(switch3 == 1)&&(switch4 == 1)){
//motor1 CW  
digitalWrite(enblPin1, HIGH);
digitalWrite(dirPin1, HIGH);
for(x = 0; x < 400; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(700);
digitalWrite(stepPin1, LOW);
delayMicroseconds(700);
}
}

if((switch1 == 1)&&(switch2 == 0)&&(switch3 == 1)&&(switch4 == 1)){
//motor1 CCW  
digitalWrite(enblPin1, HIGH);
digitalWrite(dirPin1, LOW);
for(x = 0; x < 400; x++)
{
digitalWrite(stepPin1, HIGH);
delayMicroseconds(700);
digitalWrite(stepPin1, LOW);
delayMicroseconds(700);
}
}

if((switch1 == 1)&&(switch2 == 1)&&(switch3 == 0)&&(switch4 == 1)){
//motor2 CW  
digitalWrite(enblPin2, HIGH);
digitalWrite(dirPin2, LOW);
for(x = 0; x < 400; x++)
{
digitalWrite(stepPin2, HIGH);
delayMicroseconds(700);
digitalWrite(stepPin2, LOW);
delayMicroseconds(700);
}

}

if((switch1 == 1)&&(switch2 == 1)&&(switch3 == 1)&&(switch4 == 0)){
//motor2 CCW  
digitalWrite(enblPin2, HIGH);
digitalWrite(dirPin2, HIGH);
for(x = 0; x < 400; x++)
{
digitalWrite(stepPin2, HIGH);
delayMicroseconds(700);
digitalWrite(stepPin2, LOW);
delayMicroseconds(700);
}
}

}


3. VIDEO HASILNYA



Membuat Alat Pijat Otomatis Berbasis Tensimeter Mpx5050DP Interface Android MIT Inventor via Bluetooth

Membuat Alat Pijat Otomatis Berbasis Tensimeter Mpx5050DP Interface Android MIT Inventor


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memijat secara otomatis dengan berbasis tensimeter digital. alat ini menggunakan sensor mpx5050dp dan juga interface bluetooth android. untuk lebih jelasnya berikut adalah koding dan skemanya.   


1. Skema 




2. Program Arduino IDE

#include <Arduino.h>
#include <math.h>
#include <Wire.h> 
#include <SPI.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16,2);

int counter;
int motor1 = 4;
int solenoid1 = 5;
int motor2 = 7;
int solenoid2 = 6;
int dataadc;
int dataadc2;
int tombol = 8;
int tombolx;
int hitung;
float vol;
float mmhg,mmhg2;
float mmhgx,mmhgx2;
float sistole,sistole2;
float diastole,diastole2;
int sistolex,sistolex2;
int diastolex,diastolex2;
int mark = 0;
int mark2 = 0;
float ABIsis;
float ABIdia;

void setup() {
  Serial.begin(9600);
  lcd.clear();
  lcd.begin();
  lcd.noCursor();
      
  pinMode(motor1,OUTPUT);
  pinMode(solenoid1,OUTPUT);
  pinMode(motor2,OUTPUT);
  pinMode(solenoid2,OUTPUT);
  pinMode(tombol,INPUT_PULLUP);
  digitalWrite(motor1,LOW);
  digitalWrite(solenoid1,LOW);
  digitalWrite(motor2,LOW);
  digitalWrite(solenoid2,LOW);
  
}

void loop() {

 lcd.setCursor(0,0);
 lcd.print("ABI= ");
 lcd.print(ABIsis);
 lcd.print("   "); 

 lcd.setCursor(0,1);
 lcd.print("D= ");
 lcd.print(diastolex);
 lcd.print("   ");

ABIsis = sistolex / sistolex2;
     
 tombolx = digitalRead(tombol); 

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

    Serial.print(ABIsis);
    Serial.print("|");       
    Serial.print(sistolex);
    Serial.print("|");       
    Serial.print(sistolex2);
    Serial.print("|");
    
}

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(motor1,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(mmhg);
 lcd.print("     ");

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

mmhgx = mmhg;

//Serial.println(mmhg);

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

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

 dataadc2 = analogRead(A1);
 mmhg2 = (dataadc2 - 46.222) / 3.2;

if((mmhg2 >= mmhgx2 + 2)&&(mmhg2 > 100)&&(mark2 == 0)){
//digitalWrite(motor,LOW); 
Serial.println("SISTOLE"); 
sistole2 = mmhg2;
mark2 = 2; 
digitalWrite(motor2,LOW);
}

if((mmhg2 >= mmhgx2 + 1)&&(mmhg2 > 50)&&(mmhg2 < 90)&&(mark2 == 2)){
//digitalWrite(motor,LOW); 
Serial.println("DIASTOLE"); 
diastole2 = mmhg2;
mark2 = 3;
}

 lcd.setCursor(10,1);
 lcd.print(mmhg2);
 lcd.print("     ");

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

mmhgx2 = mmhg2;
//Serial.println(mmhg2);

if((mark2 == 3)&&(mmhg < 50)&&(mmhg2 < 50)){
lcd.clear();
delay(1000);
mark2 = 0;
sistolex2 = sistole2;
diastolex2 = diastole2;
digitalWrite(solenoid2,LOW);
return;
}

if((mark2 == 2)&&(mmhg < 50)&&(mmhg2 < 50)){
lcd.clear();
delay(1000);
mark2 = 0;
sistolex2 = sistole2;
diastolex2 = random(60,90);
digitalWrite(solenoid2,LOW);
return;
}

    Serial.print(ABIsis);
    Serial.print("|");       
    Serial.print(sistolex);
    Serial.print("|");       
    Serial.print(sistolex2);
    Serial.print("|");

delay(1);   
mulai(); 
}


3. Interface Android






4. VIDEO HASILNYA



MONITOR PH - TDS - SUHU - JARAK BLYNK ESP8266

MONITOR PH - TDS - SUHU - JARAK BLYNK ESP8266 


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapa memonitor PH, TDS, Suhu, Jarak menggunakan Blynk secara realtime. alat ini menggunakan relay sebagi kedali dari pompanya dan juga menggunakan Nodemcu ESP8266 sebagai microcontrollernya. untuk lebih jelasnya berikut adalah koding dan skemanya.



1. Skema 



2. Program Arduino IDE

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

#define  BLYNK_PRINT Serial  
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_ADS1015.h>

#define trigPin D6
#define echoPin D7

#define ONE_WIRE_BUS 2  
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

LiquidCrystal_I2C lcd(0x27,16,2);

Adafruit_ADS1115 ads1115;

long duration, distance;
float TempC;
float pHValue;
long ntu;
int ntunew;
int adcntu;
int adcPH;
int h;
int rawValue;
int TempCx;
int pHValuex;
int ntux;
float ntufix;
int relay1 = D8;
int relay2 = D5;

BlynkTimer timer;

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

void sendSensor()
{
 Blynk.virtualWrite(V0, pHValue);
 Blynk.virtualWrite(V1, ntux);
 Blynk.virtualWrite(V2, distance);
 Blynk.virtualWrite(V3, TempC);
 delay(1000);
}

void setup(){ 
sensors.begin();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
      
ads1115.begin();
ads1115.setGain(GAIN_ONE); 
    
Wire.begin();  

Serial.begin(9600);
lcd.begin();

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

void loop(){

  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
 
adcPH = ads1115.readADC_SingleEnded(0);
pHValue = (adcPH - 2196.84) / 440.283;

adcntu = ads1115.readADC_SingleEnded(1);                   
ntu = (adcntu - 22000.0) / 1;

sensors.requestTemperatures();
TempC = sensors.getTempCByIndex(0); // Celcius

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

ntux = map(adcntu, 3000, 0, 0, 100);

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

  lcd.setCursor(0,0);
  lcd.print("Ph: ");
  lcd.print(pHValue);
  lcd.print(" ");
  lcd.print(distance);
  lcd.print("    ");
   
  lcd.setCursor(0,1);
  lcd.print("NTU: ");
  lcd.print(ntux);
  lcd.print(" ");
  lcd.print(TempC);
  lcd.print("   ");
  
if(distance <= 10){
 digitalWrite(relay1, HIGH);
}
if(distance > 10){
 digitalWrite(relay1, LOW);
}

if(ntux <= 10){
 digitalWrite(relay2, HIGH);
}
if(ntux > 10){
 digitalWrite(relay2, LOW);
}

  Blynk.run();
  timer.run();
  delay(200);
}


3. VIDEO HASILNYA



Monitoring PH dan Turbidity via Wireless HC-12 LCD TFT ILI9341 Arduino

Monitoring PH dan Turbidity via Wireless HC-12 LCD TFT ILI9341 Arduino


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa memonitoring ph dan turbidity secara realtime dengan sistem wireless. alat ini menggunakan indikator berupa lampu ac 220 volt yang berwarna. interface yang dipakai juga menggunakan lcd tft ili9341. untuk lebih jelasnya berikut adalah koding dan komponennya.


1. Komponen 




2. Program Transmitter

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

SoftwareSerial mySerial (2, 3);

float pHValue;
int tds;
int adctds;
int adcPH;

void setup() {
 mySerial.begin(9600); 
 Serial.begin(9600); 
 pinMode(2, INPUT);
 pinMode(3, OUTPUT);
}

void loop() {

 adcPH = analogRead(A0); //menggunakan pin A0 untuk membaca output sensor pH
 pHValue = (adcPH - 1093.4) / -30.897;

 adctds = analogRead(A1);             
 tds = map(adctds, 900, 1, 0, 100);

mySerial.print("*");
mySerial.print(pHValue * 100);
mySerial.print(",");
mySerial.print(tds);
mySerial.println("#");

//Serial.print(pHValue);
//Serial.print(" ");
//Serial.println(tds);

delay(100);
}


3. Program Receiver

#include <Arduino.h>
#include <math.h>
#include <Wire.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <SoftwareSerial.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);

SoftwareSerial mySerial (2, 3);

int value1;
int value2;
float ph = 0;
int tds = 0;
int datain1;
int datain2;

int ssrmerahph = 4;
int ssrhijauph = A1;
int ssrkuningph = A2;
int ssrtdsmerah = 7;
int ssrtdshijau = A0;

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

void setup(){

pinMode(ssrmerahph,OUTPUT);
pinMode(ssrhijauph,OUTPUT);
pinMode(ssrkuningph,OUTPUT);
pinMode(ssrtdsmerah,OUTPUT);
pinMode(ssrtdshijau,OUTPUT);

  digitalWrite(ssrmerahph,HIGH);
  digitalWrite(ssrhijauph,HIGH);
  digitalWrite(ssrkuningph,HIGH);
  digitalWrite(ssrtdsmerah,HIGH);
  digitalWrite(ssrtdshijau,HIGH);
  
  tft.begin();
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextSize(5);
  tft.setRotation(3); 
  
 dataIn=""; 
// Serial.begin(9600);
 mySerial.begin(9600); 
 pinMode(2, INPUT);
 pinMode(3, OUTPUT);
}

void loop(){

delay(200);

  tft.setCursor(10, 10);
  tft.setTextColor(ILI9341_YELLOW,ILI9341_BLACK);  
  tft.print("PH: ");  
  tft.print(ph);    
  tft.print("  "); 

  tft.setCursor(10, 70);
  tft.setTextColor(ILI9341_GREEN,ILI9341_BLACK);  
  tft.print("TDS: ");  
  tft.print(tds);  
  tft.print("  "); 

if(ph > 8){
  digitalWrite(ssrmerahph,LOW);
  digitalWrite(ssrhijauph,HIGH);
  digitalWrite(ssrkuningph,HIGH);
}

if(ph < 6){
  digitalWrite(ssrmerahph,HIGH);
  digitalWrite(ssrhijauph,HIGH);
  digitalWrite(ssrkuningph,LOW);
}
  
if((ph >= 6)&&(ph <= 8)){
  digitalWrite(ssrmerahph,HIGH);
  digitalWrite(ssrhijauph,LOW);
  digitalWrite(ssrkuningph,HIGH);
}

if(tds < 5){
  digitalWrite(ssrtdsmerah,HIGH);
  digitalWrite(ssrtdshijau,LOW);
}

if(tds >= 5){
  digitalWrite(ssrtdsmerah,LOW);
  digitalWrite(ssrtdshijau,HIGH);
}


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

if(parsing){
    parsingData();
   
    ph = datain1/100.0;
    tds = datain2;
     
    parsing=false;
    dataIn="";
  } 

}

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

}


4. VIDEO HASILNYA



Monitoring Kecepatan Kendaraan Sensor Piezoelectic via Bluetooth Android MIT Inventor

Monitoring Kecepatan Kendaraan Sensor Piezoelectic via Bluetooth Android MIT Inventor 


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengukur kecepatan kendaraan menggunakan piezoelectric yang dipasang pada pembatas jalan. alat ini dimonitoring dengan menggunakan handphone via bluetooth dengan software MIT Inventor. untuk lebih jelasnya berikut adalah koding dan skemanya.


a. Skema




b. Koding Android





c. Program Arduino IDE

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

SoftwareSerial mySerial (2, 3);

float kecepatan; 
float t;
int tanda,counter;

void setup() {
 mySerial.begin(9600); 
 Serial.begin(9600); 
 lcd.begin();
 lcd.clear();
 lcd.noCursor();
 pinMode(2, INPUT);
 pinMode(3, OUTPUT);
}

void loop() {

  int v1 = analogRead(A0);
  int v2 = analogRead(A1);

  lcd.setCursor(0, 0);
  lcd.print("1/2= ");
  lcd.print(v1);
  lcd.print("/");
  lcd.print(v2);
  lcd.print("  ");
     
  lcd.setCursor(0, 1);
  lcd.print("V= ");
  lcd.print(kecepatan);
  lcd.print(" m/s ");

if((v1 > 10)&&(tanda == 0)){
  tanda = 1;
  lcd.setCursor(15, 0);
  lcd.print("c");
  }

if((v2 > 15)&&(tanda == 1)){
  tanda = 0;
  t = counter / 1000.0;
  counter = 0;
  kecepatan = 5.0/t;
  lcd.setCursor(15, 0);
  lcd.print(" ");
  }

if(tanda == 1){
counter++;  

mySerial.print(kecepatan);
delay(100);
}



d. VIDEO HASILNYA



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