Translate

Monitoring Arus dan Tegangan 3 Fasa RST ARDUINO

Monitoring Arus dan Tegangan 3 Fasa RST ARDUINO


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitoring arus dan tegangan 3 fasa RST dengan menggunakan sensor tegangan ZMPT101B dan arus SCT-013. alat ini menggunakan Arduino Mega dan interface LCD 16x2.untuk lebih jelasnya berikut adalah koding dan komponennya.



a. Komponen



b. Program Arduino IDE

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

// Arrays to save our results in
unsigned long start_times[300];
unsigned long stop_times[300];
unsigned long values[300];

// Define various ADC prescaler
const unsigned char PS_16 = (1 << ADPS2);
const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0);
const unsigned char PS_64 = (1 << ADPS2) | (1 << ADPS1);
const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);

float tegangan,tegangan2,tegangan3;
float arus,arus2,arus3;
unsigned int i,i2,i3,i4,i5,i6;
unsigned int z,z2,z3,z4,z5,z6;

int vin,vin2,vin3,vin4,vin5,vin6;

    
void setup() {

lcd.begin();
lcd.clear();
lcd.noCursor();

  // set up the ADC
  ADCSRA &= ~PS_128;  // remove bits set by Arduino library

  // you can choose a prescaler from above.
  // PS_16, PS_32, PS_64 or PS_128
  ADCSRA |= PS_128;    // set our own prescaler to 64
 
  Serial.begin(9600);
}


void loop()
{

// zmpt101b tegangan
//==================================
  z = 0;
  
  // capture the values to memory
  for(i=0;i<300;i++) {
    start_times[i] = micros();
    values[i] = analogRead(A0);            

  if (values[i] >= z) {
  z = values[i];
  }
    stop_times[i] = micros();
  }

   vin = z ;

  z = 0;

  tegangan = (vin - 559.9) / 0.413 ;
  tegangan = tegangan + 80.0;
  
  if (tegangan < 0){
  tegangan = 0;
  }

//================================
//==================================
  z2 = 0;
  
  // capture the values to memory
  for(i2=0;i2<300;i2++) {
    start_times[i2] = micros();
    values[i2] = analogRead(A1);            

  if (values[i2] >= z2) {
  z2 = values[i2];
  }
    stop_times[i2] = micros();
  }

   vin2 = z2 ;

  z2 = 0;

  tegangan2 = (vin2 - 559.9) / 0.413 ;
  tegangan2 = tegangan2 + 80.0;
    
  if (tegangan2 < 0){
  tegangan2 = 0;
  }
  
//================================
//==================================
  z3 = 0;
  
  // capture the values to memory
  for(i3=0;i3<300;i3++) {
    start_times[i3] = micros();
    values[i3] = analogRead(A2);            

  if (values[i3] >= z3) {
  z3 = values[i3];
  }
    stop_times[i3] = micros();
  }

   vin3 = z3 ;

  z3 = 0;

  tegangan3 = (vin3 - 559.9) / 0.413 ;
  tegangan3 = tegangan3 + 80.0;
  
  if (tegangan3 < 0){
  tegangan3 = 0;
  }
  
  //================================
  // sct-013 arus
  //=================================
  // capture the values to memory
  for(i4=0;i4<300;i4++) {
    start_times[i4] = micros();
    values[i4] = analogRead(A3);            

  if (values[i4] >= z4) {
  z4 = values[i4];
  }
    stop_times[i4] = micros();
  }

  arus = (z4 - 500.0) / 100.0;

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

 z4 = 0;
//==============================
//=================================
// capture the values to memory
  for(i5=0;i5<300;i5++) {
    start_times[i5] = micros();
    values[i5] = analogRead(A4);            

  if (values[i5] >= z5) {
  z5 = values[i5];
  }
    stop_times[i5] = micros();
  }

  arus2 = (z5 - 500.0) / 100.0;

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

 z5 = 0;
//==============================
//=================================
// capture the values to memory
  for(i6=0;i6<300;i6++) {
    start_times[i6] = micros();
    values[i6] = analogRead(A5);            

  if (values[i6] >= z6) {
  z6 = values[i6];
  }
    stop_times[i6] = micros();
  }

  arus3 = (z6 - 500.0) / 100.0;

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

 z6 = 0;
//==============================

  lcd.setCursor(0, 0);
  lcd.print(tegangan,0);
  lcd.print("/");
  lcd.print(tegangan2,0);
  lcd.print("/");
  lcd.print(tegangan3,0);
  lcd.print("      ");
  
  lcd.setCursor(0, 1); 
  lcd.print(arus,1);
  lcd.print("/");
  lcd.print(arus2,1);
  lcd.print("/");
  lcd.print(arus3,1);
  lcd.print("   ");
  
delay(200);
}



c. VIDEO HASILNYA




Monitoring PH dan Suhu via ESP32 WEBSERVER

Monitoring PH dan Suhu via ESP32 WEBSERVER


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yangdapat memonitor kadar ph dan suhu dengan menggunakan webserver, maksud webserver disini yaitu menggunakan IP lokal sehingga tidak membutuhkan koneksi internet hanya butuh koneksi wifi saja. untuk lebih jelasnya berikut adalah koding dan komponennya.



a. Komponen




b. Program Arduino IDE

#include <Wire.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_ADS1015.h>

LiquidCrystal_I2C lcd(0x27,16,2);

Adafruit_ADS1115 ads1115;
#define ONE_WIRE_BUS 32  

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

float TempC;
float pHValue;
int adcPH;
int h;
int TempCx;
int pHValuex;

const char* ssid = "hotspothpku";
const char* password = "123456789";

WiFiServer server(80);
AsyncWebServer server(80);

void setup(){ 
ads1115.begin();
ads1115.setGain(GAIN_ONE); 
    
Wire.begin();   
sensors.begin();
Serial.begin(9600);
lcd.begin();
lcd.clear();

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

  WiFi.begin(ssid, password);

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

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");

}

void loop(){

WiFiClient client = server.available();

adcPH = ads1115.readADC_SingleEnded(0);
pHValue = (adcPH - 1136.84) / 330.283;

sensors.requestTemperatures();
TempC = sensors.getTempCByIndex(0); // Celcius
  
  lcd.setCursor(0,0);
  lcd.print("Ph: ");
  lcd.print(pHValue);
  lcd.print("  ");
   
  lcd.setCursor(0,1);
  lcd.print("Suhu: ");
  lcd.print(TempC);
  lcd.print(" c  ");


  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println("Refresh: 1");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
   
  client.println("<center>");
  client.println("<h1>");
  client.println("Monitoring PH dan SUHU");
  client.println("</h1>");
   
  client.println("<h3>");
  client.println("PH = ");
  client.println(pHValue);
  client.println("<br>");
  
  client.println("Suhu = ");
  client.println(TempC);
  client.println(" C");
  client.println("<br>");
 
  client.println("</h3>");  
  client.println("</center>");
  client.println("</html>");

  delay(1);
  //Serial.println("Client disonnected");
  //Serial.println("");

delay(200);
}



c. VIDEO HASILNYA




Monitor Tegangan AC 220 volt PLN Nyala atau Padam Notif SMS GATEWAY

Monitor Tegangan AC 220 volt PLN Nyala atau Padam Notif SMS GATEWAY


       Pada ksempatan kali ini saya akan menjelaskan mengenai bagaimana cara untuk membuat sebuah alat yang dapat memonitor tegangan pln 220 saat dia padam atau nyala dengan notifikasi sms, jadi jika pemilik rumah sedang berada di luar kota dapat dengan mudah memantaunya dengan adanya sms tersebut. untuk lebih jelasnya berikut adalah koding dan skemanya.


a. skema



b. Program Arduino IDE

#include "Wire.h"
#include "SIM900.h"
#include <SoftwareSerial.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "sms.h"
SMSGSM sms;

LiquidCrystal_I2C lcd(0x27,16,2);

int vin = 0;
int iin = 0;
int vout;
float kal;

int a = 0;
int zero = 1;
int kondisi = 0;
int dataadc;

char string[160];
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
unsigned long values[100];
int vin1;
int vin2;
int vin3;
int vin4;
unsigned int i1;
unsigned int z1;
unsigned int i2;
unsigned int z2;
unsigned int i3;
unsigned int z3;
unsigned int i4;
unsigned int z4;

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

  Serial.println("GSM Shield testing.");
     if (gsm.begin(2400)) {
          Serial.println("\nstatus=READY");
          started=true;
     } else Serial.println("\nstatus=IDLE");

     if(started) {
          if (sms.SendSMS("085726123456", "Alat Ready"))
          Serial.println("\nSMS sent OK");
     }
     
}

void loop() {
 
z1 = 0;
z2 = 0;
z3 = 0;
z4 = 0;

for(i1=0;i1<100;i1++) {
  values[i1] = analogRead(A0);            
  if (values[i1] >= z1) {
  z1 = values[i1];
  }
}

for(i2=0;i2<100;i2++) {
  values[i2] = analogRead(A0);            
  if (values[i2] >= z2) {
  z2 = values[i2];
  }
}
 
for(i3=0;i3<100;i3++) {
  values[i3] = analogRead(A0);            
  if (values[i3] >= z3) {
  z3 = values[i3];
  }
}
 
 for(i4=0;i4<100;i4++) {
  values[i4] = analogRead(A0);            
  if (values[i4] >= z4) {
  z4 = values[i4];
  }
}
 
vin1 = z1 ;
vin2 = z2 ;
vin3 = z3 ;
vin4 = z4 ;

z1 = 0;
z2 = 0;
z3 = 0;
z4 = 0;

if((vin1 > vin2)&&(vin1 > vin3)&&(vin1 > vin4)){
  vout = vin1;
  kal = (vout - 515.9) / 0.413 ;
}
else if((vin2 > vin1)&&(vin2 > vin3)&&(vin2 > vin4)){
  vout = vin2;
  kal = (vout - 515.9) / 0.413 ;
}
else if((vin3 > vin1)&&(vin3 > vin2)&&(vin3 > vin4)){
  vout = vin3;
  kal = (vout - 515.9) / 0.413 ;
}
else if((vin4 > vin1)&&(vin4 > vin2)&&(vin4 > vin3)){
  vout = vin4;
  kal = (vout - 515.9) / 0.413 ;
}

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

  lcd.setCursor(0,0);
  lcd.print("V: ");
  lcd.print(kal);
  lcd.print("    ");
  
//Serial.println(kal);

 if((kal > 200)&&(kondisi == 1)){
  if (sms.SendSMS("085726123456", "Listrik Nyala"))
      Serial.println("\nSMS sent OK");
      kondisi = 0;
      delay(3000);
   }
 
 if((kal < 200)&&(kondisi == 0)){
   if (sms.SendSMS("085726123456", "Listrik Padam"))
      Serial.println("\nSMS sent OK");
      kondisi = 1;
      delay(3000);
   }
      
delay(200);
}



c. VIDEO HASILNYA






Monitor PH dan Turbidity TDS Serta Water Level JSN-SR04 IOT BLYNK 2.0 ADS1115 Nodemcu ESP8266

Monitor PH dan Turbidity TDS Serta Water Level JSN-SR04 IOT BLYNK 2.0 ADS1115 Nodemcu ESP8266


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor PH dan turbidity serta water level atau ketinggia air secara realtime online dengan server IOT Blynk 2.0 sehingga bisa dimonitor secara jarak jauh. untuk lebih jelasnya berkut adalah koding dan skemanya.


a. Skema dan Komponen



b. Program Nodemcu ESP8266

#define BLYNK_TEMPLATE_ID "TMPL6wOCxxxxx"
#define BLYNK_TEMPLATE_NAME "monitor ph tds"
#define BLYNK_AUTH_TOKEN "VOK0cWiFN5ycHj3SV_snEDXTfTfeixxxx"
#define BLYNK_PRINT Serial  

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

#define trigPin D6
#define echoPin D7

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;
WidgetLED led1(V3);
WidgetLED led2(V4);

BlynkTimer timer;

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

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

void setup(){ 

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 - 2136.84) / 440.283;

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

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

ntux = map(ntu, 0, 100, 190, 0);

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

if(distance <= 4){
 digitalWrite(relay1, LOW);
}
if(distance > 4){
 digitalWrite(relay1, HIGH);
}

if((pHValue > 6)&&(pHValue < 9)&&(ntu < 5)){
  led1.on();
  led2.off(); 
}else{
  led1.off();
  led2.on();
}

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



c. VIDEO HASILNYA




Monitor PH dan Turbidity IOT Blynk 2.0 Nodemcu ESP8266 dan Modul ADS1115

Monitor PH dan Turbidity IOT Blynk 2.0 Nodemcu ESP8266 dan Modul ADS1115


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor PH dan turbidity secara realtime secara online IOT server Blynk 2.0 dengan mikrokontrollernya yaitu Nodemcu ESP8266 dengan ADC external ADS1115.untuk lebih jelasnya berikut adalah koding dan skemanya.


a. Skema dan Komponen




b. Program Nodemcu ESP8266

#define BLYNK_TEMPLATE_ID "TMPL67JSxxxxx"
#define BLYNK_TEMPLATE_NAME "MONITORING KUALITAS AIR"
#define BLYNK_AUTH_TOKEN "t7jsxB6EIiM0r85puv7FHvDTvZN8xxxx"
#define BLYNK_PRINT Serial  

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

LiquidCrystal_I2C lcd(0x27,16,2);

Adafruit_ADS1115 ads1115;

float TempC;
float pHValue;
float ntu;
int ntunew;
int adcntu;
int adcPH;
int h;
int dryValue = 957;
int wetValue = 56;
int friendlyDryValue = 0;
int friendlyWetValue = 100;
int rawValue;
int TempCx;
int pHValuex;
int ntux;
float ntufix;

BlynkTimer timer;

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

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

void setup(){ 
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(){

adcPH = ads1115.readADC_SingleEnded(0);
pHValue = (adcPH - 1136.84) / 330.283;

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

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

ntux = map(ntu, 0, 100, 190, 0);

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

  lcd.setCursor(0,0);
  lcd.print("Ph: ");
  lcd.print(pHValue);
  lcd.print("  ");
   
  lcd.setCursor(0,1);
  lcd.print("NTU: ");
  lcd.print(ntux);
  lcd.print(" %     ");

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



c. VIDEO HASILNYA




Monitor Kecepatan Angin (Wind Speed) Anemometer Interface P10 RGB HUB75 Wireless Hc-12 IOT BLYNK 2.0

Monitor Kecepatan Angin (Wind Speed) Anemometer Interface P10 RGB HUB75 Wireless Hc-12 IOT BLYNK 2.0


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor kecepatan angin dengan interface P10 RGB hub75. mikrokontroller yang dipakai yaitu Arduino Uno pada bagian transmitter dan receiver menggunakan Arduino Wifi. untuk bisa mmonitor jarak jauh maka dipakai server Blynk 2.0. untuk lebih jelasnya berikut adalah koding dan skemanya.


a. Skema Alat




b. Program Transmitter

#include <Wire.h>  // i2C Conection Library
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
#include <SoftwareSerial.h>

SoftwareSerial HC12(10, 11);
LiquidCrystal_I2C lcd(0x27, 16, 2);

// anemometer parameters
volatile byte rpmcount; // count signals
volatile unsigned long last_micros;
unsigned long timeold;
unsigned long timemeasure = 2.00; // seconds
int timetoSleep = 1;               // minutes
unsigned long sleepTime = 15;      // minutes
unsigned long timeNow;
int countThing = 0;
int GPIO_pulse = 2; // Arduino = D2
float rpm, rps;     // frequencies
float radius = 0.1; // meters - measure of the lenght of each the anemometer wing
float velocity_kmh; // km/h
float velocity_ms;  //m/s
float omega = 0;    // rad/s
float calibration_value = 2.0;

void setup() {

  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  HC12.begin(9600);  
   
  pinMode(GPIO_pulse, INPUT_PULLUP);
  digitalWrite(GPIO_pulse, LOW);

  detachInterrupt(digitalPinToInterrupt(GPIO_pulse));                         // force to initiate Interrupt on zero
  attachInterrupt(digitalPinToInterrupt(GPIO_pulse), rpm_anemometer, RISING); //Initialize the intterrupt pin
  rpmcount = 0;
  rpm = 0;
  timeold = 0;
  timeNow = 0;
 
}

void loop()
{
  //Measure RPM
  if ((millis() - timeold) >= timemeasure * 1000)
  {
    //countThing++;
    detachInterrupt(digitalPinToInterrupt(GPIO_pulse)); // Disable interrupt when calculating
    rps = float(rpmcount) / float(timemeasure);         // rotations per second
    rpm = 60 * rps;                                     // rotations per minute
    omega = 2 * PI * rps;                               // rad/s
    velocity_ms = omega * radius * calibration_value;   // m/s
    velocity_kmh = velocity_ms * 3.6;                   // km/h
        
    timeold = millis();
    rpmcount = 0;
    attachInterrupt(digitalPinToInterrupt(GPIO_pulse), rpm_anemometer, RISING); // enable interrupt
  }

  lcd.setCursor(0, 0);
  lcd.print("Kec=");
  lcd.print(velocity_ms);
  lcd.print(" m/s ");

  HC12.write(velocity_ms * 100);  
 delay(1000); 
}

void rpm_anemometer()
{
  if (long(micros() - last_micros) >= 5000)
  { // time to debounce measures
    rpmcount++;
    last_micros = micros();
  }
}


c. Program Receiver Arduino Uno

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

#define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr

#define CLK 8  // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A3
#define OE  9
#define A   A0
#define B   A1
#define C   A2

RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);

int val;
float nilaims;
float nilaikmh;
int nilaimsx;
int nilaikmhx;

int bta = 13;
int btb = 12;
int btax;
int btbx;
int nilaimaxkmh, nilaimaxms;
int mode;

SoftwareSerial HC12(10, 11);  

void setup()
{
  Serial.begin(9600);
  pinMode(bta,INPUT_PULLUP);
  pinMode(btb,INPUT_PULLUP);
  HC12.begin(9600); 
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  matrix.begin();
  matrix.setTextWrap(true); // Allow text to run off right edge
  matrix.setTextSize(1);
}

void loop()
{

btax = digitalRead(bta);
btbx = digitalRead(btb);

if((btax == 0)&&(btbx == 0)){
  lcd.clear();
  delay(1000);
  setting1();
  setting2();
}
    
  while (HC12.available()) {        // If HC-12 has data
    val = HC12.read();
    nilaims = val / 100.0;
    //Serial.println(HC12.read());      // Send the data to Serial monitor
  } 

  nilaikmh = nilaims * 3.6;
  nilaims = nilaikmh / 3.6;

if(btax == 0){
mode++;
}

if(mode > 1){
  mode = 0;
}

if(mode == 0){
  lcd.setCursor(0, 0);
  lcd.print("Kec= ");
  lcd.print(nilaims);
  lcd.print(" m/s   ");

if(nilaims < nilaimaxms){
  matrix.fillScreen(0);
  matrix.setTextColor(matrix.Color444(0, 1, 0));
  matrix.setCursor(3, 3); //x,y
  matrix.print(nilaims);
}


if(nilaims >= nilaimaxms){
  matrix.fillScreen(0);
  matrix.setTextColor(matrix.Color444(1, 0, 0));
  matrix.setCursor(3, 3); //x,y
  matrix.print(nilaims);
}

}

if(mode == 1){
  lcd.setCursor(0, 0);
  lcd.print("Kec= ");
  lcd.print(nilaikmh);
  lcd.print(" km/h  ");

if(nilaikmh >= nilaimaxkmh){
  matrix.fillScreen(0);
  matrix.setTextColor(matrix.Color444(1, 0, 0));
  matrix.setCursor(3, 3); //x,y
  matrix.print(nilaikmh);
}

if(nilaikmh < nilaimaxkmh){
  matrix.fillScreen(0);
  matrix.setTextColor(matrix.Color444(0, 1, 0));
  matrix.setCursor(3, 3); //x,y
  matrix.print(nilaikmh);
}
 
}

nilaikmhx = nilaikmh * 100;
nilaimsx = nilaims * 100;

  lcd.setCursor(0, 1);
  lcd.print(nilaimaxms);
  lcd.print(" / ");
  lcd.print(nilaimaxkmh);
  lcd.print(" / ");

  Serial.print("*");
  Serial.print(nilaimsx);
  Serial.print(",");
  Serial.print(nilaikmhx);
  Serial.println("#");  

delay(1000);
}


void setting1(){
  
btax = digitalRead(bta);
btbx = digitalRead(btb);  

if(btax == 0){
 delay(200); 
 nilaimaxms++; 
}

if(btbx == 0){
 delay(200); 
 nilaimaxms--; 
}

if((btax == 0)&&(btbx == 0)){
 delay(200); 
 lcd.clear();
 return;
}

  lcd.setCursor(0, 0);
  lcd.print("Kec1=");
  lcd.print(nilaimaxms);
  lcd.print(" m/s ");  
  
setting1();  
}


void setting2(){
  
btax = digitalRead(bta);
btbx = digitalRead(btb);  

if(btax == 0){
 delay(200); 
 nilaimaxkmh++; 
}

if(btbx == 0){
 delay(200); 
 nilaimaxkmh--; 
}

if((btax == 0)&&(btbx == 0)){
 delay(200); 
 lcd.clear();
 return;
}

  lcd.setCursor(0, 0);
  lcd.print("Kec2=");
  lcd.print(nilaimaxkmh);
  lcd.print(" km/h ");  
  
setting2();  
}


d. Program Receiver ESP8266

#define BLYNK_TEMPLATE_ID "TMPL6Xd6mRxxx"
#define BLYNK_TEMPLATE_NAME "anemometer"
#define BLYNK_AUTH_TOKEN "tSFV2OuvES_o9gLE77FjEERbD3L0xxxx"

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

int temp;
int x = 5;
int y;

int value1;
int value2;

float ms;
float kmh;

float datain1;
float datain2;

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, ms);
 Blynk.virtualWrite(V1, kmh);
 delay(1000);
}

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

void loop()
{

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

if(parsing){
  parsingData();
    
  Blynk.run();
  timer.run();
}

}

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

 ms = datain1 / 100.0;
 kmh = datain2 / 100.0;

}


 
e. VIDEO HASILNYA





Kendali Motor DC da LED via IOT BLYNK 2.0

Kendali Motor DC da LED via IOT BLYNK 2.0


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengendalikan motor dc dan led dengan menggunakan IOT Blynk 2.0. pada interface Blynk terdapat beberapa tombol switch yang dapat digunakan untuk mengendalikan arah putaran motor dan ON OFF led. untuk lebih jelasnya berikut adalah skema dan kodingnya.


a. Skema

link sumber: https://projectiot123.com/2023/11/22/motor-speed-control-using-ibt-2-and-arduino/




b. Program ESP8266

#define BLYNK_TEMPLATE_ID "TMPL6mWi-xxxx"
#define BLYNK_TEMPLATE_NAME "telur"
#define BLYNK_AUTH_TOKEN "APJjyV28gzQqQTjYaeEj-KUAJF8TAxxx"
#define BLYNK_PRINT Serial  

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

int led = D1;
int tanda;
int pinValue, pinValue2, pinValue3, pinValue4, pinValue5;
int pwm1 = D6;
int pwm2 = D7;
int pwm3 = D4;
int pwm4 = D5;

BlynkTimer timer;

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

BLYNK_WRITE(V0)
{
  pinValue = param.asInt();   

  if(pinValue == 1){    
    analogWrite(pwm1,50);  
    analogWrite(pwm2,0); 
  }
  
  if(pinValue == 0) {
    analogWrite(pwm1,0);  
    analogWrite(pwm2,0);  
  }
  
}

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

  if(pinValue2 == 1){
    analogWrite(pwm1,0);  
    analogWrite(pwm2,50); 
  }
  
  if(pinValue2 == 0) {
    analogWrite(pwm1,0);  
    analogWrite(pwm2,0);   
  }

}

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

  if(pinValue3 == 1){
   digitalWrite(led,HIGH); 
  }
  
  if(pinValue3 == 0) {
   digitalWrite(led,LOW);
  }

}


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

  if(pinValue4 == 1){    
    analogWrite(pwm3,50);  
    analogWrite(pwm4,0); 
  }
  
  if(pinValue4 == 0) {
    analogWrite(pwm3,0);  
    analogWrite(pwm4,0);  
  }
  
}

BLYNK_WRITE(V4)
{
  pinValue5 = param.asInt();   

  if(pinValue5 == 1){
    analogWrite(pwm3,0);  
    analogWrite(pwm4,50); 
  }
  
  if(pinValue5 == 0) {
    analogWrite(pwm3,0);  
    analogWrite(pwm4,0);   
  }

}

void sendSensor()
 delay(100);
}

void setup() {
  
  pinMode(led,OUTPUT);
  pinMode(pwm1,OUTPUT);
  pinMode(pwm2,OUTPUT);
  pinMode(pwm3,OUTPUT);
  pinMode(pwm4,OUTPUT);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(1000L, sendSensor);
}

void loop() {
  Blynk.run();
  timer.run();
  delay(200);  
}



c. VIDEO HASILNYA




Kendali Suhu DHT22 Motor Servo FUZZY LOGIC MAMDANI EFLL ARDUINO

Kendali Suhu DHT22 Motor Servo FUZZY LOGIC MAMDANI EFLL ARDUINO




        Pada kesempatan kali ini saya akan membahas mengenai bagaimana cara membuat sebuah alat untuk mengendalikan suhu dengan motor servo menggunakan metode fuzzy logic mamdani EFLL dengan Arduino. jadi suhunya dijaga pada suhu tertentu dengan menggunakan Fuzzy Logic, untuk lebih jelasnya berikut adalah kompone dan kodingnya.



a. Komponen dan Skema



b. Program Arduino IDE

#include <Fuzzy.h>
#include <Wire.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <Servo.h>
#define ONE_WIRE_BUS 7  
#include "DHT.h"
#define DHTPIN 8
#define DHTTYPE DHT22
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);

DHT dht(DHTPIN, DHTTYPE);

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

Servo myservo1;

float t;
float suhu;
float setpoint = 35.0;
float error;
float errorx;
float delerror;
float output1;

Fuzzy *fuzzy = new Fuzzy();

// FuzzyInput
FuzzySet *ernb = new FuzzySet(-1.8, -1.8, -0.8, -0.8);
FuzzySet *erns = new FuzzySet(-1.8, -0.8, -0.8, 0);
FuzzySet *erz = new FuzzySet(-0.8, 0, 0, 0.8);
FuzzySet *erps = new FuzzySet(0, 0.8, 0.8, 1.8);
FuzzySet *erpb = new FuzzySet(0.8, 0.8, 1.8, 1.8);

// FuzzyInput
FuzzySet *dernb = new FuzzySet(-0.18, -0.18, -0.08, -0.08);
FuzzySet *derns = new FuzzySet(-0.18, -0.08, -0.08, 0);
FuzzySet *derz = new FuzzySet(-0.08, 0, 0, 0.08);
FuzzySet *derps = new FuzzySet(0, 0.08, 0.08, 0.18);
FuzzySet *derpb = new FuzzySet(0.08, 0.08, 0.18, 0.18);

// FuzzyOutput
FuzzySet *p = new FuzzySet(4, 5, 5, 6);
FuzzySet *sp = new FuzzySet(19, 20, 20, 21);
FuzzySet *n = new FuzzySet(74, 75, 75, 76);
FuzzySet *sd = new FuzzySet(109, 110, 110, 111);
FuzzySet *d = new FuzzySet(124, 125, 125, 126);

void setup()
{
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  myservo1.attach(9);
  myservo1.write(70);
  Serial.begin(9600);
  dht.begin();
  
  // FuzzyInput error
  FuzzyInput *errorsys = new FuzzyInput(1);

  errorsys->addFuzzySet(ernb);
  errorsys->addFuzzySet(erns);
  errorsys->addFuzzySet(erz);
  errorsys->addFuzzySet(erps);
  errorsys->addFuzzySet(erpb);
  fuzzy->addFuzzyInput(errorsys);

  // FuzzyInput delta error
  FuzzyInput *deltaerror = new FuzzyInput(2);

  deltaerror->addFuzzySet(dernb);
  deltaerror->addFuzzySet(derns);
  deltaerror->addFuzzySet(derz);
  deltaerror->addFuzzySet(derps);
  deltaerror->addFuzzySet(derpb);
  fuzzy->addFuzzyInput(deltaerror);

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

  pwmout->addFuzzySet(p);
  pwmout->addFuzzySet(sp);
  pwmout->addFuzzySet(n);
  pwmout->addFuzzySet(sd);
  pwmout->addFuzzySet(d);
  fuzzy->addFuzzyOutput(pwmout);

  // Building FuzzyRule 1
  FuzzyRuleAntecedent *iferrorsysErnbAnddeltaerrorDernb = new FuzzyRuleAntecedent();
  iferrorsysErnbAnddeltaerrorDernb->joinWithAND(ernb, dernb); 
  FuzzyRuleConsequent *thenPwmoutP= new FuzzyRuleConsequent();
  thenPwmoutP->addOutput(p);
  FuzzyRule *fuzzyRule1 = new FuzzyRule(1, iferrorsysErnbAnddeltaerrorDernb, thenPwmoutP);
  fuzzy->addFuzzyRule(fuzzyRule1);

  // Building FuzzyRule 2
  FuzzyRuleAntecedent *iferrorsysErnbAnddeltaerrorDerns = new FuzzyRuleAntecedent();
  iferrorsysErnbAnddeltaerrorDerns->joinWithAND(ernb, derns); 
  //FuzzyRuleConsequent *thenPwmoutP= new FuzzyRuleConsequent();
  thenPwmoutP->addOutput(p);
  FuzzyRule *fuzzyRule2 = new FuzzyRule(2, iferrorsysErnbAnddeltaerrorDerns, thenPwmoutP);
  fuzzy->addFuzzyRule(fuzzyRule2);

  // Building FuzzyRule 3
  FuzzyRuleAntecedent *iferrorsysErnbAnddeltaerrorDerz = new FuzzyRuleAntecedent();
  iferrorsysErnbAnddeltaerrorDerz->joinWithAND(ernb, derz); 
  //FuzzyRuleConsequent *thenPwmoutP= new FuzzyRuleConsequent();
  thenPwmoutP->addOutput(p);
  FuzzyRule *fuzzyRule3 = new FuzzyRule(3, iferrorsysErnbAnddeltaerrorDerz, thenPwmoutP);
  fuzzy->addFuzzyRule(fuzzyRule3);

  // Building FuzzyRule 4
  FuzzyRuleAntecedent *iferrorsysErnbAnddeltaerrorDerps = new FuzzyRuleAntecedent();
  iferrorsysErnbAnddeltaerrorDerps->joinWithAND(ernb, derps); 
  FuzzyRuleConsequent *thenPwmoutSp= new FuzzyRuleConsequent();
  thenPwmoutSp->addOutput(sp);
  FuzzyRule *fuzzyRule4 = new FuzzyRule(4, iferrorsysErnbAnddeltaerrorDerps, thenPwmoutSp);
  fuzzy->addFuzzyRule(fuzzyRule4);

  // Building FuzzyRule 5
  FuzzyRuleAntecedent *iferrorsysErnbAnddeltaerrorDerpb = new FuzzyRuleAntecedent();
  iferrorsysErnbAnddeltaerrorDerpb->joinWithAND(ernb, derpb); 
  FuzzyRuleConsequent *thenPwmoutN= new FuzzyRuleConsequent();
  thenPwmoutN->addOutput(n);
  FuzzyRule *fuzzyRule5 = new FuzzyRule(5, iferrorsysErnbAnddeltaerrorDerpb, thenPwmoutN);
  fuzzy->addFuzzyRule(fuzzyRule5);


  // Building FuzzyRule 6
  FuzzyRuleAntecedent *iferrorsysErnsAnddeltaerrorDernb = new FuzzyRuleAntecedent();
  iferrorsysErnsAnddeltaerrorDernb->joinWithAND(erns, dernb); 
  //FuzzyRuleConsequent *thenPwmoutP= new FuzzyRuleConsequent();
  thenPwmoutP->addOutput(p);
  FuzzyRule *fuzzyRule6 = new FuzzyRule(6, iferrorsysErnsAnddeltaerrorDernb, thenPwmoutP);
  fuzzy->addFuzzyRule(fuzzyRule6);

  // Building FuzzyRule 7
  FuzzyRuleAntecedent *iferrorsysErnsAnddeltaerrorDerns = new FuzzyRuleAntecedent();
  iferrorsysErnsAnddeltaerrorDerns->joinWithAND(erns, derns); 
  //FuzzyRuleConsequent *thenPwmoutP= new FuzzyRuleConsequent();
  thenPwmoutP->addOutput(p);
  FuzzyRule *fuzzyRule7 = new FuzzyRule(7, iferrorsysErnsAnddeltaerrorDerns, thenPwmoutP);
  fuzzy->addFuzzyRule(fuzzyRule7);

  // Building FuzzyRule 8
  FuzzyRuleAntecedent *iferrorsysErnsAnddeltaerrorDerz = new FuzzyRuleAntecedent();
  iferrorsysErnsAnddeltaerrorDerz->joinWithAND(erns, derz); 
  //FuzzyRuleConsequent *thenPwmoutSp= new FuzzyRuleConsequent();
  thenPwmoutSp->addOutput(sp);
  FuzzyRule *fuzzyRule8 = new FuzzyRule(8, iferrorsysErnsAnddeltaerrorDerz, thenPwmoutSp);
  fuzzy->addFuzzyRule(fuzzyRule8);

  // Building FuzzyRule 9
  FuzzyRuleAntecedent *iferrorsysErnsAnddeltaerrorDerps = new FuzzyRuleAntecedent();
  iferrorsysErnsAnddeltaerrorDerps->joinWithAND(erns, derps); 
  //FuzzyRuleConsequent *thenPwmoutN= new FuzzyRuleConsequent();
  thenPwmoutN->addOutput(n);
  FuzzyRule *fuzzyRule9 = new FuzzyRule(9, iferrorsysErnsAnddeltaerrorDerps, thenPwmoutN);
  fuzzy->addFuzzyRule(fuzzyRule9);

  // Building FuzzyRule 10
  FuzzyRuleAntecedent *iferrorsysErnsAnddeltaerrorDerpb = new FuzzyRuleAntecedent();
  iferrorsysErnsAnddeltaerrorDerpb->joinWithAND(erns, derpb); 
  FuzzyRuleConsequent *thenPwmoutSd= new FuzzyRuleConsequent();
  thenPwmoutSd->addOutput(sd);
  FuzzyRule *fuzzyRule10 = new FuzzyRule(10, iferrorsysErnsAnddeltaerrorDerpb, thenPwmoutSd);
  fuzzy->addFuzzyRule(fuzzyRule10);

  // Building FuzzyRule 11
  FuzzyRuleAntecedent *iferrorsysErzAnddeltaerrorDernb = new FuzzyRuleAntecedent();
  iferrorsysErzAnddeltaerrorDernb->joinWithAND(erz, dernb); 
  //FuzzyRuleConsequent *thenPwmoutP= new FuzzyRuleConsequent();
  thenPwmoutP->addOutput(p);
  FuzzyRule *fuzzyRule11 = new FuzzyRule(11, iferrorsysErzAnddeltaerrorDernb, thenPwmoutP);
  fuzzy->addFuzzyRule(fuzzyRule11);

  // Building FuzzyRule 12
  FuzzyRuleAntecedent *iferrorsysErzAnddeltaerrorDerns = new FuzzyRuleAntecedent();
  iferrorsysErzAnddeltaerrorDerns->joinWithAND(erz, derns); 
  //FuzzyRuleConsequent *thenPwmoutSp= new FuzzyRuleConsequent();
  thenPwmoutSp->addOutput(sp);
  FuzzyRule *fuzzyRule12 = new FuzzyRule(12, iferrorsysErzAnddeltaerrorDerns, thenPwmoutSp);
  fuzzy->addFuzzyRule(fuzzyRule12);

  // Building FuzzyRule 13
  FuzzyRuleAntecedent *iferrorsysErzAnddeltaerrorDerz = new FuzzyRuleAntecedent();
  iferrorsysErzAnddeltaerrorDerz->joinWithAND(erz, derz); 
  //FuzzyRuleConsequent *thenPwmoutN= new FuzzyRuleConsequent();
  thenPwmoutN->addOutput(n);
  FuzzyRule *fuzzyRule13 = new FuzzyRule(13, iferrorsysErzAnddeltaerrorDerz, thenPwmoutSp);
  fuzzy->addFuzzyRule(fuzzyRule13);

  // Building FuzzyRule 14
  FuzzyRuleAntecedent *iferrorsysErzAnddeltaerrorDerps = new FuzzyRuleAntecedent();
  iferrorsysErzAnddeltaerrorDerps->joinWithAND(erz, derps); 
  //FuzzyRuleConsequent *thenPwmoutSD= new FuzzyRuleConsequent();
  thenPwmoutSd->addOutput(sd);
  FuzzyRule *fuzzyRule14 = new FuzzyRule(14, iferrorsysErzAnddeltaerrorDerps, thenPwmoutSd);
  fuzzy->addFuzzyRule(fuzzyRule14);

  // Building FuzzyRule 15
  FuzzyRuleAntecedent *iferrorsysErzAnddeltaerrorDerpb = new FuzzyRuleAntecedent();
  iferrorsysErzAnddeltaerrorDerpb->joinWithAND(erz, derpb); 
  FuzzyRuleConsequent *thenPwmoutD= new FuzzyRuleConsequent();
  thenPwmoutD->addOutput(d);
  FuzzyRule *fuzzyRule15 = new FuzzyRule(15, iferrorsysErzAnddeltaerrorDerpb, thenPwmoutD);
  fuzzy->addFuzzyRule(fuzzyRule15);

  // Building FuzzyRule 16
  FuzzyRuleAntecedent *iferrorsysErpsAnddeltaerrorDernb = new FuzzyRuleAntecedent();
  iferrorsysErpsAnddeltaerrorDernb->joinWithAND(erps, dernb); 
  thenPwmoutSp->addOutput(sp);
  FuzzyRule *fuzzyRule16 = new FuzzyRule(16, iferrorsysErpsAnddeltaerrorDernb, thenPwmoutSp);
  fuzzy->addFuzzyRule(fuzzyRule16);

  // Building FuzzyRule 17
  FuzzyRuleAntecedent *iferrorsysErpsAnddeltaerrorDerns = new FuzzyRuleAntecedent();
  iferrorsysErpsAnddeltaerrorDerns->joinWithAND(erps, derns); 
  thenPwmoutN->addOutput(n);
  FuzzyRule *fuzzyRule17 = new FuzzyRule(17, iferrorsysErpsAnddeltaerrorDerns, thenPwmoutN);
  fuzzy->addFuzzyRule(fuzzyRule17);

  // Building FuzzyRule 18
  FuzzyRuleAntecedent *iferrorsysErpsAnddeltaerrorDerz = new FuzzyRuleAntecedent();
  iferrorsysErpsAnddeltaerrorDerz->joinWithAND(erps, derz); 
  thenPwmoutSd->addOutput(sd);
  FuzzyRule *fuzzyRule18 = new FuzzyRule(18, iferrorsysErpsAnddeltaerrorDerz, thenPwmoutSd);
  fuzzy->addFuzzyRule(fuzzyRule18);

  // Building FuzzyRule 19
  FuzzyRuleAntecedent *iferrorsysErpsAnddeltaerrorDerps = new FuzzyRuleAntecedent();
  iferrorsysErpsAnddeltaerrorDerps->joinWithAND(erps, derps); 
  thenPwmoutD->addOutput(d);
  FuzzyRule *fuzzyRule19 = new FuzzyRule(19, iferrorsysErpsAnddeltaerrorDerps, thenPwmoutD);
  fuzzy->addFuzzyRule(fuzzyRule19);

  // Building FuzzyRule 20
  FuzzyRuleAntecedent *iferrorsysErpsAnddeltaerrorDerpb = new FuzzyRuleAntecedent();
  iferrorsysErpsAnddeltaerrorDerpb->joinWithAND(erps, derpb); 
  thenPwmoutD->addOutput(d);
  FuzzyRule *fuzzyRule20 = new FuzzyRule(20, iferrorsysErzAnddeltaerrorDerpb, thenPwmoutD);
  fuzzy->addFuzzyRule(fuzzyRule20);

  // Building FuzzyRule 21
  FuzzyRuleAntecedent *iferrorsysErpbAnddeltaerrorDernb = new FuzzyRuleAntecedent();
  iferrorsysErpbAnddeltaerrorDernb->joinWithAND(erpb, dernb); 
  thenPwmoutN->addOutput(n);
  FuzzyRule *fuzzyRule21 = new FuzzyRule(21, iferrorsysErpbAnddeltaerrorDernb, thenPwmoutN);
  fuzzy->addFuzzyRule(fuzzyRule21);

  // Building FuzzyRule 22
  FuzzyRuleAntecedent *iferrorsysErpbAnddeltaerrorDerns = new FuzzyRuleAntecedent();
  iferrorsysErpbAnddeltaerrorDerns->joinWithAND(erpb, derns); 
  thenPwmoutSd->addOutput(sd);
  FuzzyRule *fuzzyRule22= new FuzzyRule(22, iferrorsysErpbAnddeltaerrorDerns, thenPwmoutSd);
  fuzzy->addFuzzyRule(fuzzyRule22);

  // Building FuzzyRule 23
  FuzzyRuleAntecedent *iferrorsysErpbAnddeltaerrorDerz = new FuzzyRuleAntecedent();
  iferrorsysErpbAnddeltaerrorDerz->joinWithAND(erpb, derz); 
  thenPwmoutD->addOutput(d);
  FuzzyRule *fuzzyRule23 = new FuzzyRule(23, iferrorsysErpbAnddeltaerrorDerz, thenPwmoutD);
  fuzzy->addFuzzyRule(fuzzyRule23);

  // Building FuzzyRule 24
  FuzzyRuleAntecedent *iferrorsysErpbAnddeltaerrorDerps = new FuzzyRuleAntecedent();
  iferrorsysErpbAnddeltaerrorDerps->joinWithAND(erpb, derps); 
  thenPwmoutD->addOutput(d);
  FuzzyRule *fuzzyRule24 = new FuzzyRule(24, iferrorsysErpbAnddeltaerrorDerps, thenPwmoutD);
  fuzzy->addFuzzyRule(fuzzyRule24);

  // Building FuzzyRule 25
  FuzzyRuleAntecedent *iferrorsysErpbAnddeltaerrorDerpb = new FuzzyRuleAntecedent();
  iferrorsysErpbAnddeltaerrorDerpb->joinWithAND(erpb, derpb); 
  thenPwmoutD->addOutput(d);
  FuzzyRule *fuzzyRule25 = new FuzzyRule(25, iferrorsysErzAnddeltaerrorDerpb, thenPwmoutD);
  fuzzy->addFuzzyRule(fuzzyRule25);

}

void loop()
{

  t = dht.readTemperature();
  sensors.requestTemperatures();
  suhu = sensors.getTempCByIndex(0);
  
  error = setpoint - t;
  delerror = error - errorx;

  lcd.setCursor(0,0);
  lcd.print("D/S= ");
  lcd.print(t,1);
  lcd.print("/");
  lcd.print(suhu,1);
  lcd.print("  ");

      
 // Serial.print("Suhu DHT22: ");
 // Serial.print(t);
 // Serial.print("|| Suhu DS: ");
 // Serial.println(suhu);

  fuzzy->setInput(1, error);
  fuzzy->setInput(2, delerror);

  fuzzy->fuzzify();

/*
  Serial.print("errorsys: NB-> ");
  Serial.print(ernb->getPertinence());
  Serial.print(", NS-> ");
  Serial.print(erns->getPertinence());
  Serial.print(", Z-> ");
  Serial.print(erz->getPertinence());
  Serial.print(", PS-> ");
  Serial.print(erps->getPertinence());
  Serial.print(", PB-> ");
  Serial.println(erpb->getPertinence());
  
  Serial.print("DELTA error: NB-> ");
  Serial.print(dernb->getPertinence());
  Serial.print(", NS-> ");
  Serial.print(derns->getPertinence());
  Serial.print(", Z-> ");
  Serial.print(derz->getPertinence());
  Serial.print(", PS-> ");
  Serial.print(derps->getPertinence());
  Serial.print(", PB-> ");
  Serial.println(derpb->getPertinence());
*/

  output1 = fuzzy->defuzzify(1);
  
 /*
  Serial.print("Output: ");
  Serial.print("PWMOUT: P-> ");
  Serial.print(p->getPertinence());
  Serial.print(", SP-> ");
  Serial.print(sp->getPertinence());
  Serial.print(", N-> ");
  Serial.print(n->getPertinence());
  Serial.print(", SD-> ");
  Serial.print(sd->getPertinence());
  Serial.print(", D-> ");
  Serial.println(d->getPertinence());
  Serial.print("OUTPUT: ");
  Serial.println(output1);
 */
  
  lcd.setCursor(0,1);
  lcd.print("OUT: ");
  lcd.print(output1);
  lcd.print("  ");

  if(output1 == 0){ 
  lcd.setCursor(13,1);
  lcd.print("ON ");
  myservo1.write(150);
  }

  if((output1 > 40)&&(output1 < 200)){ 
  lcd.setCursor(13,1);
  lcd.print("ON ");
  myservo1.write(150);
  }

  if((output1 > 10)&&(output1 < 40)){
  lcd.setCursor(13,1);
  lcd.print("OFF");
   myservo1.write(70);
  }
  
  errorx = error;
  delay(1000);
  kirimdata();
}

void kirimdata(){
Serial.print("*");
Serial.print(t * 100.0);
Serial.print(",");
Serial.print(suhu * 100.0);
Serial.print(",");
Serial.print(error * 100.0);
Serial.print(",");
Serial.print(delerror * 100.0);
Serial.println("#");    
}


c. Program ESP8266

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

int temp;
int x = 5;
int y;

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

float t;
float suhu;
float error;
float delerror;

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

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

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

                             client.print(String("GET ") + resource + apiKey + "&field1=" + t + "&field2=" + suhu + "&field3=" + error + "&field4=" + delerror + " 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.print("t: ");
                             Serial.print(t);
                             Serial.print(" suhu: ");
                             Serial.print(suhu);
                             Serial.println(". Send to Thingspeak.");
                        }
                       
          client.stop();

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

  delay(10000);
 
 }
}

void parsingData(){
int j=0;

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

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

 datain1 = dt[0].toInt();
 datain2 = dt[1].toInt();
 datain3 = dt[2].toInt();
 datain4 = dt[3].toInt();

//kirim data hasil parsing
Serial.print("data 1 : ");
Serial.print(datain1);
Serial.print("\n");
Serial.print("data 2 : ");
Serial.print(datain2);
Serial.print("\n");
Serial.print("data 3 : ");
Serial.print(datain3);
Serial.print("data 4 : ");
Serial.print(datain4);

 t = datain1 / 100.0;
 suhu = datain2 / 100.0;
 error = datain3 / 100.0;
 delerror = datain4 / 100.0;
 
}



d. VIDEO HASILNYA




Monitor Kecepatan dan Ketinggian Air (Water Level) IOT Blynk 2.0

Monitor Kecepatan dan Ketinggian Air (Water Level) IOT Blynk 2.0 


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor ketinggian air dan kecepatan air secara realtime dengan IOT blynk 2.0 sehingga nilai bisa di monitor secara jarak jauh. untuk lebih jelasnya berikut adalah koding dan skemanya.


a. Komponen




b. Program Arduino IDE

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

#define trigPin 4
#define echoPin 3

volatile byte half_revolutions;
unsigned int rpm;
unsigned long timeold;
int rpmold;
int timex;

void setup() {
  Serial.begin (9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

 attachInterrupt(0, rpm_fun, RISING);
 half_revolutions = 0;
 rpm = 0;
 timeold = 0;
}

void loop() {
 timex++;

if (half_revolutions >= 20) {
     rpm = 0;
     //Update RPM every 20 counts, increase this for better RPM resolution,
     //decrease for faster update   
     rpm = 30*1000 / (millis() - timeold) * half_revolutions;
     rpm = rpm / 10;
     timeold = millis();
     half_revolutions = 0;
     detachInterrupt(0);           //detaches the interrupt
     Serial.println(rpm,DEC);
}

  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;

  lcd.setCursor(0,0);
  lcd.print("S: ");
  lcd.print(distance);
  lcd.print(" cm   ");
  lcd.setCursor(0,1);
  lcd.print("RPM: ");
  lcd.print(rpm);
  lcd.print(" m/s   ");
  delay(200);

 attachInterrupt(0, rpm_fun, RISING);

rpmold = rpm;

if(timex > 50){
  if(rpm == rpmold){
    rpm = 0;
    timex = 0;
    }
}
  
Serial.print("*");
Serial.print(rpm);
Serial.print(",");
Serial.print(distance);
Serial.println("#");  
}

void rpm_fun()
 {
   half_revolutions++;
 }

 
 
c. Program ESP8266

#define BLYNK_TEMPLATE_ID "TMPL6mWi-B0xx"
#define BLYNK_TEMPLATE_NAME "monitor kecepatan air"
#define BLYNK_AUTH_TOKEN "APJjyV28gzQqQTjYaeEj-KUAJF8TArxx"

#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 jarak = 0;
int rpm = 0;

float datain1;
float datain2;

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, rpm);
 Blynk.virtualWrite(V1, jarak);
 delay(1000);
}


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

void loop()
{

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

if(parsing){
  parsingData();
    
  Blynk.run();
  timer.run();
}

}

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

 rpm = datain1 / 1;
 jarak = datain2 / 1;

}



d. VIDEO HASILNYA