Translate

Monitor suhu non contact MlX90614 LCD TFT Graphic ILI9341 ESP32

Monitor Suhu Non Contact MLX90614 LCD TFT Graphic ILI9341 ESP32


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mendeteksi suhu kemudian data suhu tersebut ditampilkan ke lcd TFT ILI9341 dengan grafiknya. jadi alat ini hanya monitor suhu saja secara non contact atau tidak menyentuh, sehingga sangat bagus untuk kebutuhan industri yang ingin memonitor suhu tanpa harus menyentuh objectnya. untuk koding dan skemanya seperti berikut ini.



a. Skema Rangkaian Alat

R1 - R6 = 2k2 ohm
R7 - R12 = 3k3 ohm






b. Program Arduino IDE

#include <Wire.h>
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <Adafruit_MLX90614.h>
#include <WiFi.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 350

#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         13
#define TFT_DC         14
//#define TFT_LED      5v
#define TFT_RST        12
#define TFT_MOSI       27
#define TFT_CLK        26
#define TFT_MISO       25

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

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 LastTime=0;
bool BPMTiming=false;
bool BeatComplete=false;
int BPM=0;

#define UpperThreshold 550
#define LowerThreshold 500

int lebar;
int tinggi;
int geser = 0;
float suhubenda;

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

void loop() 
{
  
  suhubenda = mlx.readObjectTempC();

  lebar = tft.width(); 
  tinggi = tft.height();
  tft.drawLine(0,115,lebar,115,ILI9341_RED);
  
  if(x > lebar)  
  {
    tft.fillScreen(ILI9341_BLACK);
    //tft.fillRect(0,100,320,75,ILI9341_BLACK);
    x=0;
    lastx=x;
    drawGrid();
  }
   
  tft.setTextColor(ILI9341_YELLOW,ILI9341_BLACK);  
  int y = 150 - ( suhubenda / 1 );
  tft.drawLine(lastx,lasty,x,y,ILI9341_WHITE);
  lasty = y;
  lastx = x;

  tft.setCursor(5, 10);
  tft.setTextColor(ILI9341_YELLOW,ILI9341_BLACK);  
  tft.print("Suhu: ");  
  tft.print(suhubenda);  
  tft.print("   ");  
  
  x = x + 3;
  x1++;
  x2++;

}

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



c. VIDEO HASILNYA





Monitor Jumlah Orang di Ruangan ESP32 Sensor HB100 Server Thingspeak

Monitor Jumlah Orang di Ruangan ESP32 Sensor HB100 Server Thingspeak


            Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor jumlah orang yang berada didalam ruangan, jadi sistem kerja alat ini yaitu terdapat 2 buah sensor HB100 lalu dipasangkan di pintu masuk dan pintu keluar sehingga tiap kali orang masuk akan dihitung dan jika oang ersebut keluar juga dihitung sehingga bisa diketahui jumlah orang yang berada didalam ruangan. alat ini juga mengirimkan data ke Thingspeak untuk merecord data yang dimonitor oleh alat. untuk lebih jelasnya berikut adalah koding dan skemanya.



a. Skema 



b. Program Arduino IDE

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

String apiKey = "ZQGE8G2JTWQRTAB3";     //  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;

int dataadc1;
int dataadc2;
int masuk;
int keluar;
int orang;
int waktu;


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

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

// Connect to WiFi network
  Serial.println();
  Serial.println();
  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()
{

  dataadc1 = analogRead(34);
  dataadc2 = analogRead(35);
  
  lcd.setCursor(0,0);
  lcd.print("ADC1=");
  lcd.print(dataadc1);
  lcd.print("/");
  lcd.print(dataadc2);
  lcd.print("   ");
   
  lcd.setCursor(0,1);
  lcd.print("Data: ");
  lcd.print(orang);
  lcd.print("    ");

if(dataadc1 < 1000){
delay(1000);
orang++;    
}

if(dataadc2 < 1000){
delay(1000);
orang--;
}

if(waktu > 500){ //kirim data setiap 10 detik
waktu = 0;  
kirim();      
}

waktu++;
delay(10);
}


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

                             client.print(String("GET ") + resource + apiKey + "&field1=" + orang + " 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(10000);
  
}



c. VIDEO HASILNYA





ECG Graphic Arduino LCD TFT ILI9341 / ILI9488 Sensor Modul AD8232

ECG Graphic Arduino LCD TFT ILI9341 / ILI9488 Sensor Modul AD8232 


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat menampilkan grafik ECG menggunakan LCD TFT dengan driver ILI9341 / ILI9488, alat ini menggunakan Arduino sebagai pengolah datanya dan sensor ECGnya menggunakan modul AD8232. untuk lebih jelasnya berikut adalah koding dan skemanya.


a. Rangkaian Skema





b. Program Arduino IDE ILI9341

#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 350

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

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 LastTime=0;
bool BPMTiming=false;
bool BeatComplete=false;
int BPM=0;

#define UpperThreshold 550
#define LowerThreshold 500

int lebar;
int tinggi;
int geser = 0;

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

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

  int dataecg = analogRead(A0);
  //Serial.println(dataecg);  
    
  tft.setTextColor(ILI9341_YELLOW,ILI9341_BLACK);  
  int y = 150 - ( dataecg / 10 );
  tft.drawLine(lastx,lasty,x,y,ILI9341_WHITE);
  lasty = y;
  lastx = x;

  if( dataecg > UpperThreshold )
  {
    if(BeatComplete)
    {
      BPM=millis()-LastTime;
      BPM=int(60/(float(BPM)/1000));
      BPMTiming=false;
      BeatComplete=false;
    }
    if(BPMTiming==false)
    {
      LastTime=millis();
      BPMTiming=true;
    }
  }
  if((dataecg < LowerThreshold)&(BPMTiming))
    BeatComplete=true;
  // display bpm
  
  tft.setCursor(5, 10);
  tft.setTextColor(ILI9341_YELLOW,ILI9341_BLACK);  
  tft.print("BPM: ");  
  tft.print(BPM);  
  tft.print("   ");  
  
  x = x + 3;
  x1++;
  x2++;

}

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



c. Program Arduino IDE ILI9488

#include "SPI.h"
#include <Adafruit_GFX.h>
#include <ILI9488.h>
   
#define SCREEN_WIDTH 500
#define SCREEN_HEIGHT 500

#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

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

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 LastTime=0;
bool BPMTiming=false;
bool BeatComplete=false;
int BPM=0;

#define UpperThreshold 550
#define LowerThreshold 500

int lebar;
int tinggi;
int geser = 0;

void setup() {
  tft.begin();
  tft.fillScreen(ILI9488_BLACK);
  tft.setTextSize(2);
  tft.setRotation(1); 
  drawGrid(); 
  Serial.begin(9600);
}


void loop() 
{

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


  int dataecg = analogRead(A0);
  //Serial.println(dataecg);  
    
  tft.setTextColor(ILI9488_YELLOW,ILI9488_BLACK);  
  int y = 150 - ( dataecg / 10 );
  tft.drawLine(lastx,lasty,x,y,ILI9488_WHITE);
  lasty = y;
  lastx = x;


  if( dataecg > UpperThreshold )
  {
    if(BeatComplete)
    {
      BPM=millis()-LastTime;
      BPM=int(60/(float(BPM)/1000));
      BPMTiming=false;
      BeatComplete=false;
    }
    if(BPMTiming==false)
    {
      LastTime=millis();
      BPMTiming=true;
    }
  }
  if((dataecg < LowerThreshold)&(BPMTiming))
    BeatComplete=true;
  // display bpm
  
  tft.setCursor(5, 10);
  tft.setTextColor(ILI9488_YELLOW,ILI9488_BLACK);  
  tft.print("BPM: ");  
  tft.print(BPM);  
  tft.print("   ");  
  
  x = x + 3;
  x1++;
  x2++;

}

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

 
d. VIDEO HASILNYA




Tutorial Monitor Suhu & Kelembaban (DHT11) Interface LCD TFT ILI9488

Tutorial Monitor Suhu & Kelembaban (DHT11) Interface LCD TFT ILI9488


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor suhu dan kelembaban dengan menggunakan sensor DHT11 dengan interface yaitu LCD TFT ILI9488, alat ini menggunakan arduino sebagai kontrollernya untuk lebih jelasnya berikut adalah koding dan skemanya.


a. Skema (PIN DHT11 ada di PIN 2 Arduino)






b. Program Arduino IDE

#include "SPI.h"
#include <Adafruit_GFX.h>
#include <ILI9488.h>
#include "DHT.h"
#define DHTPIN 2     

#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

ILI9488 tft = ILI9488(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
#define DHTTYPE DHT11

int x1 = 0;
int y1 = 150;
int x2 = 500;
int y2 = 150;
int dataadc;
int t,h;
unsigned long start;
DHT dht(DHTPIN, DHTTYPE);
  
void setup() {
  Serial.begin(9600);
  tft.begin();
  tft.fillScreen(ILI9488_BLACK);
  tft.setTextSize(3);
  dht.begin();
}


void loop(void) {
 
  h = dht.readHumidity();
  t = dht.readTemperature();
  
  tft.setRotation(1);
  tft.setCursor(10, 10);
  tft.setTextColor(ILI9488_WHITE,ILI9488_BLACK);  
  tft.print("MONITOR SUHU & HUMIDITY");
  
  tft.setCursor(5, 40);
  tft.setTextColor(ILI9488_YELLOW,ILI9488_BLACK);  
  tft.print("Suhu: ");  
  tft.print(t);  
  tft.print(" C ");  

  tft.setCursor(5, 80);
  tft.setTextColor(ILI9488_GREEN,ILI9488_BLACK);  
  tft.print("Humy: ");
  tft.print(h);    
  tft.print(" % ");  

delay(10);
 
}



c. VIDEO HASILNYA



Mengakses Voice Record Module ISD1760 Menggunakan Arduino

Mengakses Voice Record Module ISD1760 Menggunakan Arduino


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara memebuat sebuah alat yang dapat me-record suara lalu memutar kembali (play) suara yang direkam tadi, alat ini bisa merekam beberapa suara berbeda karena menggunakan modul ISD1760 yang mana memiliki kemampuan record suara yang bagus. untuk lebih jelasnya berikut adalah skema dan kodingnya.



a. Skema 





b. Program Arduino IDE

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

LiquidCrystal_I2C lcd(0x27, 16, 2);

int btplay = 7;
int btrec = 6; 
int bterase = 5;
int btfwd = 4;
int btplayx;
int btrecx; 
int bterasex;
int btfwdx;
int reg;

void setup() {
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  Serial.begin(9600);
  pinMode(btplay,INPUT_PULLUP);
  pinMode(btrec,INPUT_PULLUP);
  pinMode(bterase,INPUT_PULLUP);
  pinMode(btfwd,INPUT_PULLUP);
}

void loop() {

btplayx = digitalRead(btplay);
btrecx = digitalRead(btrec);
bterasex = digitalRead(bterase);
btfwdx = digitalRead(btfwd);


if(btfwdx == 0){
delay(1000);
lcd.setCursor(0,0);
lcd.print("NEXT..");
delay(1000);
lcd.clear();
}
 
if(btrecx == 0){
lcd.setCursor(0,1);
lcd.print("RECORD....  ");
delay(3000);
lcd.clear();  
}

if(btplayx == 0){
lcd.setCursor(0,1);
lcd.print("PLAY.....  ");
delay(3000);
lcd.clear();  
}

if(bterasex == 0){
lcd.setCursor(0,1);
lcd.print("ERASE.... ");
delay(3000);  
lcd.clear();
}

}



c. VIDEO HASILNYA



 

Membuat Robot Line Follower / Robot Line Tracer

Membuat Robot Line Follower / Robot Line Tracer
 

           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah robot line follower dengan menggunakan arduino nano sebagai kendalinya. jadi robot ini hanya bergerak sesuai dengan jalur yang sudah diberikan dengan jalur bewarna hitam putih. untuk sensor yang dipakai yaitu 8 buah photodioda dengan 8 buah led putih super bright. untuk lebih jelasnya berikut adalah koding dan skemanya.


  
a. Komponen dan skemanya






b. Program Arduino IDE

#include <Wire.h>
#include <EEPROM.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

int mtrkanan1 = 8;
int mtrkanan2 = 11;

int mtrkiri1 = 12;
int mtrkiri2 = 13;

int kecmtr1 = 9;
int kecmtr2 = 10;

int kecepatan = 255;

float batas1;
float batas2;
float batas3;
float batas4;
float batas5;
float batas6;
float batas7;
float batas8;

int addr1 = 0;
int addr2 = 1;
int addr3 = 2;
int addr4 = 3;
int addr5 = 4;
int addr6 = 5;
int addr7 = 6;
int addr8 = 7;

float simpan1;
float simpan2;
float simpan3;
float simpan4;
float simpan5;
float simpan6;
float simpan7;
float simpan8;

int sensor1;
int sensor2;
int sensor3;
int sensor4;
int sensor5;
int sensor6;
int sensor7;
int sensor8;
int a,b,c,d,e,f,g,h;
int btset = 0;
int btsetx;
int btok = 1;
int btokx;
float batas1a, batas1b;
float batas2a, batas2b;
float batas3a, batas3b;
float batas4a, batas4b;
float batas5a, batas5b;
float batas6a, batas6b;
float batas7a, batas7b;
float batas8a, batas8b;


void setup() {
batas1 = EEPROM.read(addr1);
batas2 = EEPROM.read(addr2);
batas3 = EEPROM.read(addr3);
batas4 = EEPROM.read(addr4);
batas5 = EEPROM.read(addr5);
batas6 = EEPROM.read(addr6);
batas7 = EEPROM.read(addr7);
batas8 = EEPROM.read(addr8);

lcd.begin(16, 2);
lcd.clear();
lcd.noCursor();
pinMode(mtrkanan1,OUTPUT);
pinMode(mtrkanan2,OUTPUT);
pinMode(mtrkiri1,OUTPUT);
pinMode(mtrkiri2,OUTPUT);
pinMode(kecmtr1,OUTPUT);
pinMode(kecmtr2,OUTPUT);
pinMode(btset,INPUT);
pinMode(btok,INPUT);
}

void loop() {

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

if(btokx == 0){
lcd.clear();
delay(1000);
mulai();  
}

sensor1 = analogRead(A0);
sensor2 = analogRead(A1);
sensor3 = analogRead(A2);
sensor4 = analogRead(A3);
sensor5 = analogRead(A4);
sensor6 = analogRead(A5);
sensor7 = analogRead(A6);
sensor8 = analogRead(A7);

if(btsetx == 0){
delay(2000);
lcd.clear();
  
kalsenput1();
kalsenhit1();

kalsenput2();
kalsenhit2();

kalsenput3();
kalsenhit3();

kalsenput4();
kalsenhit4();

kalsenput5();
kalsenhit5();

kalsenput6();
kalsenhit6();

kalsenput7();
kalsenhit7();

kalsenput8();
kalsenhit8();
}

if(sensor1 > batas1){
a = 1;  
}
if(sensor1 < batas1){
a = 0;  
}

if(sensor2 > batas2){
b = 1;  
}
if(sensor2 < batas2){
b = 0;  
}

if(sensor3 > batas3){
c = 1;  
}
if(sensor3 < batas3){
c = 0;  
}

if(sensor4 > batas4){
d = 1;  
}
if(sensor4 < batas4){
d = 0;  
}

if(sensor5 > batas5){
e = 1;  
}
if(sensor5 < batas5){
e = 0;  
}

if(sensor6 > batas6){
f = 1;  
}
if(sensor6 < batas6){
f = 0;  
}

if(sensor7 > batas7){
g = 1;  
}
if(sensor7 < batas7){
g = 0;  
}

if(sensor8 > batas8){
h = 1;  
}
if(sensor8 < batas8){
h = 0;  
}



lcd.setCursor(3, 0);
lcd.print(a);lcd.print(b);lcd.print(c);lcd.print(d);lcd.print(e);lcd.print(f);lcd.print(g);lcd.print(h);
lcd.setCursor(0, 1);
lcd.print("KAL");
lcd.setCursor(12, 1);
lcd.print("START");

delay(10);
}



void mulai(){
  
sensor1 = analogRead(A0);
sensor2 = analogRead(A1);
sensor3 = analogRead(A2);
sensor4 = analogRead(A3);
sensor5 = analogRead(A4);
sensor6 = analogRead(A5);
sensor7 = analogRead(A6);
sensor8 = analogRead(A7);

if(sensor1 > batas1){
a = 1;  
}
if(sensor1 < batas1){
a = 0;  
}

if(sensor2 > batas2){
b = 1;  
}
if(sensor2 < batas2){
b = 0;  
}

if(sensor3 > batas3){
c = 1;  
}
if(sensor3 < batas3){
c = 0;  
}

if(sensor4 > batas4){
d = 1;  
}
if(sensor4 < batas4){
d = 0;  
}

if(sensor5 > batas5){
e = 1;  
}
if(sensor5 < batas5){
e = 0;  
}

if(sensor6 > batas6){
f = 1;  
}
if(sensor6 < batas6){
f = 0;  
}

if(sensor7 > batas7){
g = 1;  

}
if(sensor7 < batas7){
g = 0;  
}

if(sensor8 > batas8){
h = 1;  
}
if(sensor8 < batas8){
h = 0;  
}


//maju 
if((a == 1)&&(b == 1)&&(c == 0)&&(d == 1)&&(e == 1)&&(f == 1)&&(g == 1)&&(h == 1)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,HIGH);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,HIGH);
  digitalWrite(mtrkiri2,LOW);
}

//maju 
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 0)&&(e == 1)&&(f == 1)&&(g == 1)&&(h == 1)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,HIGH);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,HIGH);
  digitalWrite(mtrkiri2,LOW);
}

//maju 
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 1)&&(e == 0)&&(f == 1)&&(g == 1)&&(h == 1)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,HIGH);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,HIGH);
  digitalWrite(mtrkiri2,LOW);
}

//maju 
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 1)&&(e == 1)&&(f == 0)&&(g == 1)&&(h == 1)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,HIGH);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,HIGH);
  digitalWrite(mtrkiri2,LOW);
}

//maju 
if((a == 1)&&(b == 1)&&(c == 0)&&(d == 0)&&(e == 1)&&(f == 1)&&(g == 1)&&(h == 1)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,HIGH);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,HIGH);
  digitalWrite(mtrkiri2,LOW);
}

//maju 
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 0)&&(e == 0)&&(f == 1)&&(g == 1)&&(h == 1)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,HIGH);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,HIGH);
  digitalWrite(mtrkiri2,LOW);
}

//maju 
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 1)&&(e == 0)&&(f == 0)&&(g == 1)&&(h == 1)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,HIGH);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,HIGH);
  digitalWrite(mtrkiri2,LOW);
}
//maju 
if((a == 1)&&(b == 1)&&(c == 0)&&(d == 0)&&(e == 0)&&(f == 1)&&(g == 1)&&(h == 1)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,HIGH);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,HIGH);
  digitalWrite(mtrkiri2,LOW);
}

//maju 
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 0)&&(e == 0)&&(f == 0)&&(g == 1)&&(h == 1)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,HIGH);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,HIGH);
  digitalWrite(mtrkiri2,LOW);
}

//==============================================================================
//=======================================================================================
//kanan 
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 1)&&(e == 1)&&(f == 1)&&(g == 1)&&(h == 0)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,HIGH);
  digitalWrite(mtrkiri2,LOW);
}

//kanan 
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 1)&&(e == 1)&&(f == 1)&&(g == 0)&&(h == 0)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,HIGH);
  digitalWrite(mtrkiri2,LOW);
}

//kanan 
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 1)&&(e == 1)&&(f == 0)&&(g == 0)&&(h == 1)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,HIGH);
  digitalWrite(mtrkiri2,LOW);
}

//kanan 
if((a == 1)&&(b == 1)&&(c == 1)&&(d == 1)&&(e == 1)&&(f == 0)&&(g == 0)&&(h == 0)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,LOW);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,HIGH);
  digitalWrite(mtrkiri2,LOW);
}


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

//kiri 
if((a == 0)&&(b == 1)&&(c == 1)&&(d == 1)&&(e == 1)&&(f == 1)&&(g == 1)&&(h == 1)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,HIGH);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,LOW);
}

//kiri 
if((a == 0)&&(b == 0)&&(c == 1)&&(d == 1)&&(e == 1)&&(f == 1)&&(g == 1)&&(h == 1)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,HIGH);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,LOW);
}

//kiri 
if((a == 1)&&(b == 0)&&(c == 0)&&(d == 1)&&(e == 1)&&(f == 1)&&(g == 1)&&(h == 1)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,HIGH);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,LOW);
}

//kiri 
if((a == 0)&&(b == 0)&&(c == 0)&&(d == 1)&&(e == 1)&&(f == 1)&&(g == 1)&&(h == 1)){
  digitalWrite(kecmtr1,HIGH);
  digitalWrite(mtrkanan1,HIGH);
  digitalWrite(mtrkanan2,LOW);
  digitalWrite(kecmtr2,HIGH);
  digitalWrite(mtrkiri1,LOW);
  digitalWrite(mtrkiri2,LOW);
}

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



lcd.setCursor(3, 0);
lcd.print(a);lcd.print(b);lcd.print(c);lcd.print(d);lcd.print(e);lcd.print(f);lcd.print(g);lcd.print(h);

mulai();
}


void kalsenput1(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

sensor1 = analogRead(A0);
  
lcd.setCursor(0, 0);
lcd.print("SENSOR1 PUTIH");
lcd.setCursor(0, 1);
lcd.print("NILAI:");
lcd.print(sensor1);
lcd.print("   ");

if(btokx == 0){
delay(2000);
lcd.clear();  
batas1a = sensor1;   
return;
}
delay(200);
kalsenput1();  
}


void kalsenhit1(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

sensor1 = analogRead(A0);
  
lcd.setCursor(0, 0);
lcd.print("SENSOR1 HITAM");
lcd.setCursor(0, 1);
lcd.print("NILAI:");
lcd.print(sensor1);
lcd.print("   ");

if(btokx == 0){
delay(2000);
lcd.clear();  
batas1b = sensor1;
batas1 = (batas1a + batas1b) / 2.0;   
EEPROM.write(addr1, batas1);
return;
}

delay(200);
kalsenhit1();  
}



void kalsenput2(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

sensor2 = analogRead(A1);
  
lcd.setCursor(0, 0);
lcd.print("SENSOR2 PUTIH");
lcd.setCursor(0, 1);
lcd.print("NILAI:");
lcd.print(sensor2);
lcd.print("   ");

if(btokx == 0){
delay(2000);
lcd.clear();  
batas2a = sensor2;   
return;
}
delay(200);
kalsenput2();  
}


void kalsenhit2(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

sensor2 = analogRead(A1);
  
lcd.setCursor(0, 0);
lcd.print("SENSOR2 HITAM");
lcd.setCursor(0, 1);
lcd.print("NILAI:");
lcd.print(sensor2);
lcd.print("   ");

if(btokx == 0){
delay(2000);
lcd.clear();  
batas2b = sensor2;
batas2 = (batas2a + batas2b) / 2.0;
EEPROM.write(addr2, batas2);   
return;
}

delay(200);
kalsenhit2();  
}




void kalsenput3(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

sensor3 = analogRead(A2);
  
lcd.setCursor(0, 0);
lcd.print("SENSOR3 PUTIH");
lcd.setCursor(0, 1);
lcd.print("NILAI:");
lcd.print(sensor3);
lcd.print("   ");

if(btokx == 0){
delay(2000);
lcd.clear();  
batas3a = sensor3;   
return;
}
delay(200);
kalsenput3();  
}


void kalsenhit3(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

sensor3 = analogRead(A2);
  
lcd.setCursor(0, 0);
lcd.print("SENSOR3 HITAM");
lcd.setCursor(0, 1);
lcd.print("NILAI:");
lcd.print(sensor3);
lcd.print("   ");

if(btokx == 0){
delay(2000);
lcd.clear();  
batas3b = sensor3;
batas3 = (batas3a + batas3b) / 2.0;
EEPROM.write(addr3, batas3);   
return;
}

delay(200);
kalsenhit3();  
}


void kalsenput4(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

sensor4 = analogRead(A3);
  
lcd.setCursor(0, 0);
lcd.print("SENSOR4 PUTIH");
lcd.setCursor(0, 1);
lcd.print("NILAI:");
lcd.print(sensor4);
lcd.print("   ");

if(btokx == 0){
delay(2000);
lcd.clear();  
batas4a = sensor4;   
return;
}
delay(200);
kalsenput4();  
}


void kalsenhit4(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

sensor4 = analogRead(A3);
  
lcd.setCursor(0, 0);
lcd.print("SENSOR4 HITAM");
lcd.setCursor(0, 1);
lcd.print("NILAI:");
lcd.print(sensor4);
lcd.print("   ");

if(btokx == 0){
delay(2000);
lcd.clear();  
batas4b = sensor4;
batas4 = (batas4a + batas4b) / 2.0;
EEPROM.write(addr4, batas4);   
return;
}

delay(200);
kalsenhit4();  
}




void kalsenput5(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

sensor5 = analogRead(A4);
  
lcd.setCursor(0, 0);
lcd.print("SENSOR5 PUTIH");
lcd.setCursor(0, 1);
lcd.print("NILAI:");
lcd.print(sensor5);
lcd.print("   ");

if(btokx == 0){
delay(2000);
lcd.clear();  
batas5a = sensor5;   
return;
}
delay(200);
kalsenput5();  
}


void kalsenhit5(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

sensor5 = analogRead(A4);
  
lcd.setCursor(0, 0);
lcd.print("SENSOR5 HITAM");
lcd.setCursor(0, 1);
lcd.print("NILAI:");
lcd.print(sensor5);
lcd.print("   ");

if(btokx == 0){
delay(2000);
lcd.clear();  
batas5b = sensor5;
batas5 = (batas5a + batas5b) / 2.0;
EEPROM.write(addr5, batas5);   
return;
}

delay(200);
kalsenhit5();  
}


void kalsenput6(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

sensor6 = analogRead(A5);
  
lcd.setCursor(0, 0);
lcd.print("SENSOR6 PUTIH");
lcd.setCursor(0, 1);
lcd.print("NILAI:");
lcd.print(sensor6);
lcd.print("   ");

if(btokx == 0){
delay(2000);
lcd.clear();  
batas6a = sensor6;   
return;
}
delay(200);
kalsenput6();  
}


void kalsenhit6(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

sensor6 = analogRead(A5);
  
lcd.setCursor(0, 0);
lcd.print("SENSOR6 HITAM");
lcd.setCursor(0, 1);
lcd.print("NILAI:");
lcd.print(sensor6);
lcd.print("   ");

if(btokx == 0){
delay(2000);
lcd.clear();  
batas6b = sensor6;
batas6 = (batas6a + batas6b) / 2.0;
EEPROM.write(addr6, batas6);   
return;
}

delay(200);
kalsenhit6();  
}



void kalsenput7(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

sensor7 = analogRead(A6);
  
lcd.setCursor(0, 0);
lcd.print("SENSOR7 PUTIH");
lcd.setCursor(0, 1);
lcd.print("NILAI:");
lcd.print(sensor7);
lcd.print("   ");

if(btokx == 0){
delay(2000);
lcd.clear();  
batas7a = sensor7;   
return;
}
delay(200);
kalsenput7();  
}


void kalsenhit7(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

sensor7 = analogRead(A6);
  
lcd.setCursor(0, 0);
lcd.print("SENSOR7 HITAM");
lcd.setCursor(0, 1);
lcd.print("NILAI:");
lcd.print(sensor7);
lcd.print("   ");

if(btokx == 0){
delay(2000);
lcd.clear();  
batas7b = sensor7;
batas7 = (batas7a + batas7b) / 2.0;
EEPROM.write(addr7, batas7);   
return;
}

delay(200);
kalsenhit7();  
}


void kalsenput8(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

sensor8 = analogRead(A7);
  
lcd.setCursor(0, 0);
lcd.print("SENSOR8 PUTIH");
lcd.setCursor(0, 1);
lcd.print("NILAI:");
lcd.print(sensor8);
lcd.print("   ");

if(btokx == 0){
delay(2000);
lcd.clear();  
batas8a = sensor8;   
return;
}
delay(200);
kalsenput8();  
}


void kalsenhit8(){

btsetx = digitalRead(btset);
btokx = digitalRead(btok);

sensor8 = analogRead(A7);
  
lcd.setCursor(0, 0);
lcd.print("SENSOR8 HITAM");
lcd.setCursor(0, 1);
lcd.print("NILAI:");
lcd.print(sensor8);
lcd.print("   ");

if(btokx == 0){
delay(2000);
lcd.clear();  
batas8b = sensor8;
batas8 = (batas8a + batas8b) / 2.0;
EEPROM.write(addr8, batas8);   
return;
}

delay(200);
kalsenhit8();  
}



c. VIDEO HASILNYA





Monitor PH dan Turbidity (kekeruhan air) Server Thingspeak Arduino UNO WIFI ESP8266

Monitor PH dan Turbidity (kekeruhan air) Server Thingspeak 
 

       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa mengukur PH dan kekeruhan air (Turbidity). alat ini mengirimkan data sensor ke server Thingspeak menggunakan Arduino Uno WIFI. untuk lebih jelasnya berikut adalah koding dan komponennya.

Konfigurasi Switch UNO WIFI
sumber link: LINK



a. Skema Alat



b. Program Arduino Uno

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

float pHValue;
int adc;
int adcPH;
int pHValuex;
float ntu;
float ntunew;
int adcntu;
float volt;

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

void loop(){

adcPH = analogRead(A0); //menggunakan pin A0 untuk membaca output sensor pH
pHValue = (adcPH + 3.026) / 98.009;
pHValuex = pHValue * 100.0;

volt = 0;
    for(int i=0; i<800; i++)
    {
        volt += ((float)analogRead(A1)/1023)*5;
    }
    volt = volt/800;
    volt = round_to_dp(volt,2);
    if(volt < 2.5){
      ntu = 3000;
    }else{
      ntu = -1120.4*square(volt)+5742.3*volt-4353.8; 
    }

  ntunew = ntu / 1;
     
  lcd.setCursor(0,0);
  lcd.print("PH:");
  lcd.print(pHValue,2);
  lcd.print("     ");

  lcd.setCursor(0,1);
  lcd.print("NTU= ");
  lcd.print(ntunew);
  lcd.print("     ");

  Serial.print("*");
  Serial.print(pHValuex);
  Serial.print(",");
  Serial.print(ntunew * 100.0);
  Serial.println("#");
  
  delay(1000);
}
   
float round_to_dp( float in_value, int decimal_place )
{
  float multiplier = powf( 10.0f, decimal_place );
  in_value = roundf( in_value * multiplier ) / multiplier;
  return in_value;
}



c. Program ESP8266

#include <SPI.h>
#include <ESP8266WiFi.h>

int temp;
int x = 5;
int y;

int value1;
int value2;

float ph;
float ntu;

int datain1;
int datain2;

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

String apiKey = "7YGF2HJ3KHG678JH3";     //  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(ph);
                             postStr += "\r\n\r\n";

                             client.print(String("GET ") + resource + apiKey + "&field1=" + ph + "&field2=" + ntu + " 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();

 ph = datain1 / 100.0;
 ntu = datain2 / 100.0;
 
}
 


d. Interface Thingspeak





e. VIDEO HASILNYA



Monitor Bpm Spo2 Server Thingspeak Aplikasi Android APP MIT INVENTOR

Monitor Bpm Spo2 Server Thingspeak Aplikasi Android APP MIT INVENTOR


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa mengukur nilai Bpm dan Spo2 secara realtime dan menggunakan IOT server Thingspeak, dari server data diambil ke aplikasi APP MIT Inventor. untuk lebih jelasnya berikut adalah program dan skemanya.


a. Skema





b. Program Arduino UNO

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

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

MAX30100* pulseOxymeter;   //library

int cacah; //membuat variabel
int spo;
int bpm;

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

PulseOximeter pox;

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


void setup() {
Serial.begin(9600);
lcd.begin();
lcd.clear();
pinMode(2,OUTPUT);

 //Serial.print("Initializing pulse oximeter..");
    if (!pox.begin()) {
        //Serial.println("FAILED");
        for(;;);
    } else {
        //Serial.println("SUCCESS");
    }
    
pox.setIRLedCurrent(MAX30100_LED_CURR_11MA);
pox.setOnBeatDetectedCallback(onBeatDetected);
}

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

    bpm = pox.getHeartRate();
    spo = pox.getSpO2();
    bpmku = bpm;
       
    lcd.setCursor(0,0);
    lcd.print("Bpm: ");
    lcd.print(pox.getHeartRate());
    lcd.print("  ");
    lcd.setCursor(0,1);
    lcd.print("Spo: ");
    lcd.print(pox.getSpO2());
    lcd.print(" % ");
       
    tsLastReport = millis();
}

Serial.print("*");
Serial.print(bpm);
Serial.print(",");
Serial.print(spo);
Serial.println("#");
  
}



c. Program ESP8266

#include <SPI.h>
#include <ESP8266WiFi.h>

int temp;
int x = 5;
int y;

int value1;
int value2;

int bpm;
int spo;

int datain1;
int datain2;

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

String apiKey = "HUAGGJ96F2RNAX30";     //  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(bpm);
                             postStr += "\r\n\r\n";

                             client.print(String("GET ") + resource + apiKey + "&field1=" + bpm + "&field2=" + spo + " 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();

 bpm = datain1 / 1;
 spo = datain2 / 1;
 
}
 



d. Thingspeak Interface




e. APP Inventor






f. VIDEO HASILNYA