Translate

Monitor PH - Turbidity - Suhu via IOT Blynk 2.0 ARDUINO Wifi

Monitor PH - Turbidity - Suhu via IOT Blynk 2.0 ARDUINO Wifi 


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk memonitor PH, Turbidity dan suhu secara realtime dengan menggunakan IOT Blynk 2.0 sehingga bisa dipantau secara jarak jauh untuk lebih jelasnya berikut adalah koding dan skemanya. 


a. Skema



b. Program Arduino IDE

#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(0x27,16,2);

float TempC;
float pHValue;
//deklarasi pin analog
float ntu;
int adctds,tds,tdsx;
int adcPH;
int TempCx;
int pHValuex;
int ntux;
float ntufix;
int relay = 8;

void setup(){  
Wire.begin();  
sensors.begin();
Serial.begin(9600);
lcd.begin();  
lcd.clear(); 
pinMode(relay,OUTPUT);
}

void loop(){
            
 adctds = analogRead(A1);             
 tds = map(adctds, 855, 1, 0, 100);
 tdsx = tds * 100;
 
adcPH = analogRead(A0); //menggunakan pin A0 untuk membaca output sensor pH
pHValue = (adcPH-962.19)/ -33.961;

pHValuex = pHValue * 100.0;
 
 sensors.requestTemperatures();
 TempC = sensors.getTempCByIndex(0); // Celcius
 TempCx =  TempC * 100.0;

  lcd.setCursor(0,1);
  lcd.print("TDS= ");
  lcd.print(tds);
  lcd.print("  ");
  
  lcd.setCursor(8,0);
  lcd.print("T:");
  lcd.print(TempC,1);
  lcd.print("C");
  lcd.setCursor(0,0);
  lcd.print("PH:");
  lcd.print(pHValue,2);
  lcd.print("  ");

if(pHValue > 7){
  digitalWrite(relay,LOW);  
}
if(pHValue <= 7){
  digitalWrite(relay,HIGH);  
}
  
  Serial.print("*");
  Serial.print(tdsx);
  Serial.print(",");
  Serial.print(pHValuex);
  Serial.print(",");
  Serial.print(TempCx);
  Serial.println("#");
  
  delay(900);
}


c. Program ESP8266

#define BLYNK_TEMPLATE_ID "TMPL6wOCxxxx"
#define BLYNK_TEMPLATE_NAME "monitor daya"
#define BLYNK_AUTH_TOKEN "VOK0cWiFN5ycHj3SV_snEDXTfTxxxxxx"
#define BLYNK_PRINT Serial  

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

float TempC = 0;
float pHValue = 0;
float ntu = 0;

int datain1;
int datain2;
int datain3;

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

BlynkTimer timer;

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


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

  if(pinValue == 1){
    digitalWrite(D6, LOW);
  }
  
  if(pinValue == 0) {
    digitalWrite(D6, HIGH);
  }
  
//  Serial.print("button value is: "); 
//  Serial.println(pinValue);

}

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

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

  dataIn=""; 

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

void loop(){

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

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

}

void parsingData(){
  
int j=0;

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

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

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

ntu = datain1 / 100.0;
pHValue = datain2 / 100.0;
TempC =datain3 / 100.0;
 
//kirim data hasil parsing
Serial.print("data 1 : ");
 Serial.println(datain1);
Serial.print("data 2 : ");
Serial.println(datain2);
Serial.print("data 3 : ");
Serial.println(datain3);
 Serial.print("\n\n");

}



d. VIDEO HASILNYA




MULTIPLE SENSOR MPU-6050 GY-521 (Cara menghubungkan 5 sensor Accelero dan Gyro MPU-6050) Arduino & Multiplex 74HC4051 (HW-529)

MULTIPLE SENSOR MPU-6050 (Cara menghubungkan 5 sensor Accelero dan Gyro MPU-6050) Arduino & Multiplex 74HC4051 (HW-529)


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang menggunakan 5 pcs sensor Accelero dan Gyro MPU-6050 yang mana digunakan hanya pada 1 Arduino, caranya yaitu mengunakan modul multiplexer HC4051. untuk lebih jelasnya berikut adalah koding dan skemanya.


a, Skema 


b. Program Arduino IDE

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

MPU6050 mpu(Wire);
unsigned long timer = 0;
float sumbux;
float sumbuy;
float sumbuz;
float linex;
int led1 = 2;      
int led2 = 3;       
int led3 = 4;   
 
void setup() {
  Serial.begin(9600);
  Wire.begin();
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  pinMode(led3,OUTPUT);
  
  byte status = mpu.begin();
  Serial.print(F("MPU6050 status: "));
  Serial.println(status);
  while(status!=0){ } // stop everything if could not connect to MPU6050
  
  Serial.println(F("Calculating offsets, do not move MPU6050"));
  delay(1000);
  // mpu.upsideDownMounting = true; // uncomment this line if the MPU6050 is mounted upside-down
  mpu.calcOffsets(); // gyro and accelero
  Serial.println("Done!\n");
}

void loop() {

//data sensor1
digitalWrite(led1, LOW);                        
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
ambilsen1();
delay(200);  

//data sensor2
digitalWrite(led1, HIGH);                        
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
ambilsen2();
delay(200);  

//data sensor3
digitalWrite(led1, LOW);                        
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
ambilsen3();
delay(200);  

//data sensor4
digitalWrite(led1, HIGH);                        
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
ambilsen4();
delay(200);  

//data sensor5
digitalWrite(led1, LOW);                        
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
ambilsen5();
delay(200);  
    
  Serial.print("X1 : ");
  Serial.print(sumbux1);
  Serial.print(" Y1 : ");
  Serial.print(sumbuy1);
  Serial.print(" Z1 : ");
  Serial.println(sumbuz1);

  Serial.print("X2 : ");
  Serial.print(sumbux2);
  Serial.print(" Y2 : ");
  Serial.print(sumbuy2);
  Serial.print(" Z2 : ");
  Serial.println(sumbuz2);

  Serial.print("X3 : ");
  Serial.print(sumbux3);
  Serial.print(" Y3 : ");
  Serial.print(sumbuy3);
  Serial.print(" Z3 : ");
  Serial.println(sumbuz3);

  Serial.print("X4 : ");
  Serial.print(sumbux4);
  Serial.print(" Y4 : ");
  Serial.print(sumbuy4);
  Serial.print(" Z4 : ");
  Serial.println(sumbuz4);

  Serial.print("X5 : ");
  Serial.print(sumbux5);
  Serial.print(" Y5 : ");
  Serial.print(sumbuy5);
  Serial.print(" Z5 : ");
  Serial.println(sumbuz5);
 
}

void ambilsen1(){
  mpu.update();
  sumbux1 = mpu.getAngleX();
  sumbuy1 = mpu.getAngleY();
  sumbuz1 = mpu.getAngleZ();   
}

void ambilsen2(){
  mpu.update();
  sumbux2 = mpu.getAngleX();
  sumbuy2 = mpu.getAngleY();
  sumbuz2 = mpu.getAngleZ();   
}

void ambilsen3(){
  mpu.update();
  sumbux3 = mpu.getAngleX();
  sumbuy3 = mpu.getAngleY();
  sumbuz3 = mpu.getAngleZ();   
}

void ambilsen4(){
  mpu.update();
  sumbux4 = mpu.getAngleX();
  sumbuy4 = mpu.getAngleY();
  sumbuz4 = mpu.getAngleZ();   
}

void ambilsen5(){
  mpu.update();
  sumbux5 = mpu.getAngleX();
  sumbuy5 = mpu.getAngleY();
  sumbuz5 = mpu.getAngleZ();   
}


Pakan Ikan Otomatis dan Monitor PH & Turbidity & Amoniak Serta Level Air via Telegram

Pakan Ikan Otomatis dan Monitor PH & Turbidity & Amoniak Serta Level Air via Telegram 


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor PH dan turbidity serta mengendalikan servo untuk pakan otomatis, jadi servo akan bergerak pada jam yang tealah disetting. untuk lebih jelasya berikut adalah koding dan skemanya.


 
a. Skema Alat



b. Program Arduino IDE

#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#include <DS3231.h>
#include <EEPROM.h>
#define ONE_WIRE_BUS 8  
#include <Servo.h>

#define trigPin1 6
#define echoPin1 5
#define trigPin2 4
#define echoPin2 3

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

LiquidCrystal_I2C lcd(0x27,20,4);
DS3231  rtc(SDA, SCL);
Servo myservo;

int addr1 = 0;
int addr2 = 1;
int addr3 = 2;
int addr4 = 3;
int addr5 = 4;

Time  t;
int jampagi,jamsiang,jamsore;
float TempC;
float pHValue;
int tds;
int adctds;
int adcPH;
int TempCx;
int pHValuex;
int ntux;
float ntufix;
long duration1, distance1;
long duration2, distance2;  
int btset = 2;
int btup = 10;
int btdown = 11;
int btok = 12;
int btsetx;
int btupx;
int btdownx;
int btokx;
float batasamo;
float batasph;
float amoniak;
int relayout = A3;
int relayin = A2;
int relayaerator = 7;
int tanda = 0;
int kolam;
int tinggipakan;


void setup(){  
  
jampagi = EEPROM.read(addr1);
jamsiang = EEPROM.read(addr2);
jamsore = EEPROM.read(addr3);
batasamo = EEPROM.read(addr4);
batasph = EEPROM.read(addr5);

pinMode(relayout,OUTPUT);
pinMode(relayin,OUTPUT);
pinMode(relayaerator,OUTPUT);
digitalWrite(relayout,LOW);
digitalWrite(relayin,LOW);
digitalWrite(relayaerator,LOW);

pinMode(btset,INPUT_PULLUP);
pinMode(btup,INPUT_PULLUP);
pinMode(btdown,INPUT_PULLUP);
pinMode(btok,INPUT_PULLUP);

pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);  

Wire.begin();  
sensors.begin();
Serial.begin(9600);
lcd.begin();  
lcd.clear(); 

rtc.begin();
//rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAmy
rtc.setTime(6, 15, 0);     // Set the time to 12:00:00 (24hr format)
rtc.setDate(1, 1, 2014);   // Set the date to January 1st, 2014

myservo.attach(9);
myservo.write(100);
}

void loop(){

btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);

if(btsetx == 0){
delay(1000);
lcd.clear();
setjampagi();
setjamsiang();
setjamsore();
setbatasamo();
setbatasph();
}
  
 t = rtc.getTime();

  //ketinggian air kolam 
  digitalWrite(trigPin1, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin1, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin1, LOW);
  duration1 = pulseIn(echoPin1, HIGH);
  distance1 = (duration1/2) / 29.1;

  //ketinggian pakan ikan
  digitalWrite(trigPin2, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin2, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin2, LOW);
  duration2 = pulseIn(echoPin2, HIGH);
  distance2 = (duration2/2) / 29.1;
  
  if(distance1 > 35){
    distance1 = 35;
  }

  if(distance2 > 30){
    distance2 = 30;
  }
  
  kolam = 35 - distance1; 
  tinggipakan = map(distance2, 5,30,100,0);

if((kolam >= 29)&&(kolam <= 31)){
  digitalWrite(relayin,LOW);
  digitalWrite(relayout,LOW);  
  }

if(kolam < 29){
  digitalWrite(relayin,HIGH);
  digitalWrite(relayout,LOW);
  }

if(kolam > 31){
  digitalWrite(relayin,LOW);
  digitalWrite(relayout,HIGH);
  }
     
 adcPH = analogRead(A0); //menggunakan pin A0 untuk membaca output sensor pH
 pHValue = (adcPH - 906.84) / -37.283;

 adctds = analogRead(A1);             
 tds = map(adctds, 855, 1, 0, 100);
 
 pHValuex = pHValue * 100.0;
 
  sensors.requestTemperatures();
  TempC = sensors.getTempCByIndex(0); // Celcius
  TempCx =  TempC * 100.0;

if(pHValue < 6.5){
  amoniak = (pHValue / TempC) * 0.202; 
}

if(pHValue == 7.0){
  amoniak = (pHValue / TempC) * 1.131; 
}

if(pHValue > 7.0){
  amoniak = (pHValue / TempC) * 3.306; 
}

if(amoniak > batasamo){
  digitalWrite(relayaerator,HIGH);
  }

if(amoniak <= batasamo){
  digitalWrite(relayaerator,LOW);
  }

if((t.hour == jampagi)&&(jampagi > 0)&&(tanda == 0)){
  myservo.write(150);
  delay(5000);
  myservo.write(100);
  tanda = 1;
}

if((t.hour == jamsiang)&&(jamsiang > 0)&&(tanda == 1)){
  myservo.write(150);
  delay(5000);
  myservo.write(100);
  tanda = 2;
}

if((t.hour == jamsore)&&(jamsore > 0)&&(tanda == 2)){
  myservo.write(150);
  delay(5000);
  myservo.write(100);
  tanda = 0;
}

  lcd.setCursor(0,0);
  lcd.print("TDS:");
  lcd.print(tds);
  lcd.print("% ");
 
  lcd.print("PH:");
  lcd.print(pHValue);
  lcd.print(" ");

  lcd.setCursor(0,1);
  lcd.print("T:");
  lcd.print(TempC,1);
  lcd.print("c ");
  
  lcd.print(batasamo,1);
  lcd.print("/");
  lcd.print(batasph,1);
  lcd.print("");

  lcd.setCursor(0,2);
  lcd.print(t.hour, DEC);
  lcd.print(":");
  lcd.print(t.min, DEC);
  lcd.print(":");
  lcd.print(t.sec, DEC);
  lcd.print("  ");
  lcd.print(jampagi);
  lcd.print("/");
  lcd.print(jamsiang);
  lcd.print("/");
  lcd.print(jamsore);
  lcd.print("");

  lcd.setCursor(0,3);
  lcd.print("S=");
  lcd.print(kolam);
  lcd.print("/");
  lcd.print(tinggipakan);
  lcd.print("  ");

  lcd.setCursor(9,3);
  lcd.print("Mg/l:");
  lcd.print(amoniak);
  lcd.print("");

  Serial.print("*");
  Serial.print(pHValue * 100.0);
  Serial.print(",");
  Serial.print(tds);
  Serial.print(",");
  Serial.print(amoniak * 100.0);
  Serial.print(",");
  Serial.print(TempC * 100.0);
  Serial.println("#");
  
  delay(1000);
}

void setjampagi(){
  
btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);  

  lcd.setCursor(0,0);
  lcd.print("Waktu Pakan Pagi");
  lcd.setCursor(0,1);
  lcd.print("Jam: ");
  lcd.print(jampagi);
  lcd.print("   ");

if(btupx == 0){
  delay(200);
  jampagi++; 
}

if(btdownx == 0){
  delay(200);
  jampagi--; 
}

if(jampagi > 23){
jampagi = 0;  
}

if(btokx == 0){
  lcd.clear();
  delay(2000);
  EEPROM.write(addr1, jampagi);
  return; 
}

setjampagi();  
}

void setjamsiang(){
  
btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);  

  lcd.setCursor(0,0);
  lcd.print("Waktu Pakan Siang  ");
  lcd.setCursor(0,1);
  lcd.print("Jam: ");
  lcd.print(jamsiang);
  lcd.print("   ");

if(btupx == 0){
  delay(200);
  jamsiang++; 
}

if(btdownx == 0){
  delay(200);
  jamsiang--; 
}

if(jamsiang > 23){
jamsiang = 0;  
}

if(btokx == 0){
  lcd.clear();
  delay(2000);
  EEPROM.write(addr2, jamsiang);
  return; 
}

setjamsiang();  
}

void setjamsore(){
  
btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);  

  lcd.setCursor(0,0);
  lcd.print("Waktu Pakan Sore  ");
  lcd.setCursor(0,1);
  lcd.print("Jam: ");
  lcd.print(jamsore);
  lcd.print("   ");

if(btupx == 0){
  delay(200);
  jamsore++; 
}

if(btdownx == 0){
  delay(200);
  jamsore--; 
}

if(jamsore > 23){
jamsore = 0;  
}

if(btokx == 0){
  lcd.clear();
  delay(2000);
  EEPROM.write(addr3, jamsore);
  return; 
}

setjamsore();  
}

void setbatasamo(){
  
btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);  

  lcd.setCursor(0,0);
  lcd.print("BATAS AMONIAK  ");
  lcd.setCursor(0,1);
  lcd.print("mg/l: ");
  lcd.print(batasamo);
  lcd.print("   ");

if(btupx == 0){
  delay(200);
  batasamo = batasamo + 0.1; 
}

if(btdownx == 0){
  delay(200);
  batasamo = batasamo - 0.1; 
}

if(batasamo > 100.0){
batasamo = 0;  
}

if(btokx == 0){
  lcd.clear();
  delay(2000);
  EEPROM.write(addr4, batasamo);
  return; 
}

setbatasamo();  
}

void setbatasph(){
  
btsetx = digitalRead(btset);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);  

  lcd.setCursor(0,0);
  lcd.print("BATAS PH  ");
  lcd.setCursor(0,1);
  lcd.print("PH: ");
  lcd.print(batasph);
  lcd.print("   ");

if(btupx == 0){
  delay(200);
  batasph = batasph + 0.1; 
}

if(btdownx == 0){
  delay(200);
  batasph = batasph - 0.1; 
}

if(batasph > 100.0){
batasph = 0;  
}

if(btokx == 0){
  lcd.clear();
  delay(2000);
  EEPROM.write(addr5, batasph);
  return; 
}

setbatasph();  
}


c. Program ESP8266

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

int temp;
int x = 5;
int y;

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

float ph;
int tds;
float amoniak;
float suhu;

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

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

char ssid[ ] = "hotspothpku";
char pass[ ] = "123456789"; //password wifi

#define BOTtoken "7466123220:AAHwCUgAxYAeHYyJp3ce5HvLBTCCfDGxxxx" //token bot telegram
#define idChat "1890145123" //idbot

WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);

void setup() {

  client.setInsecure();
  Serial.begin(9600);
  Serial.print("Connecting Wifi: ");
  Serial.println(ssid);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  delay(5000);
 
}

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

if(parsing){
    parsingData();

    bot.sendChatAction(idChat, "Sedang mengetik...");
    String nilainya = " PH/TDS/AMO/SUHU: ";
    nilainya += ph;
    nilainya += " / \n";
    nilainya += tds;
    nilainya += " / \n";
    nilainya += amoniak;
    nilainya += " / \n";
    nilainya += suhu;
    nilainya += " / \n";    
    nilainya += "TERIMA KASIH\n";
    bot.sendMessage(idChat, nilainya, "");
    Serial.print("Mengirim data sensor ke telegram");

}
 
delay(100);
}

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

 ph = datain1 / 100.0;
 tds = datain2 / 1;
 amoniak = datain3 / 100.0;
 suhu = datain4 / 100.0;
 
}


d. VIDEO HASILNYA



Kendali dan Monitor Suhu Heater PID Control serta Fitur Timer LCD OLED

Kendali dan Monitor Suhu Heater PID Control serta Fitur Timer LCD OLED


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengendalikan suhu panas heater dengan PID Control dan juga menggunakan modul dimmer AC karena menggunakan tegangan 220 Volt AC. alat ini juga memiliki fitur timer dan juga lcd Oled. untuk lebih jelasnya berikut adalah koding dan skemanya.


a. Skema Alat



b. Program Arduino IDE

#include <Wire.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <RBDdimmer.h>//
#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK);   

#define DS3231_I2C_ADDRESS 0x68

float kp = 15.15;
float ki = 1.67;
float kd = 1.15;

#define outputPin  9 
#define zerocross  2 

dimmerLamp dimmer(outputPin); 

int buzzer = 5;
int x;
char tmp_string1[8];
char tmp_string2[8];
char tmp_string3[8];
char tmp_string4[8];
float suhu;
int btdown = 3;
int btup = 4;
int btset = 10;
int btok = 11;
int btsetx;
int btupx;
int btdownx;
int btokx;
int menit;
int setpoint;
float p,i,d;
float error,errorx,sumerr;
int sp;
int pid;

#define ONE_WIRE_BUS 7 

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


byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}

void setup(void) {

  Serial.begin(9600);
  sensors.begin();
  dimmer.begin(NORMAL_MODE, ON);
  pinMode(9,OUTPUT); 
  pinMode(btset,INPUT_PULLUP);
  pinMode(btup,INPUT_PULLUP);
  pinMode(btdown,INPUT_PULLUP);
  pinMode(btok,INPUT_PULLUP); 
  pinMode(buzzer,OUTPUT);
  digitalWrite(buzzer,LOW);   

  Wire.begin();
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
   setDS3231time(0,0,0,6,29,7,24);
  
  if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(255);     // white
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(3);         // max intensity
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(1);         // pixel on
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255,255,255);
  }
}

void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}
void displayTime()
{
  
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
  if (minute<10)
  {
    Serial.print("0");
  }
  Serial.print(minute, DEC);
  Serial.print(":");
  if (second<10)
  {
    Serial.print("0");
  }
  Serial.print(second, DEC);
  Serial.println(" ");

}

void loop(void) {
displayTime();

  error = setpoint - suhu;
  p = error * kp;
  sumerr = error + errorx;
  i = ki * sumerr;
  d = kd * (error - errorx) ;
  pid = p + i + d;

Serial.println(pid);
dimmer.setPower(pid); // name.setPower(0%-100%)
  
btokx = digitalRead(btok);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btsetx = digitalRead(btset);

  sensors.requestTemperatures();
  suhu = sensors.getTempCByIndex(0);
 
  // picture loop
  u8g.firstPage(); 
  do {
    draw();
  } while( u8g.nextPage() );

if(btupx == 0){
menit = menit + 5;  
}

if(btdownx == 0){
menit = menit - 5;  
}

if(menit > 15){
menit = 15;
}

if(menit < 5){
menit = 5;
}

if(btsetx == 0){
setpoint = setpoint + 1;  
}

if(btokx == 0){
setpoint = setpoint - 1;  
}

if(setpoint > 41){
setpoint = 41;
}

if(setpoint < 36){
setpoint = 36;
}

 errorx = error;
 
  // rebuild the picture after some delay
  delay(200);

if(minute == menit){
  setDS3231time(0,0,0,6,29,7,24);
  u8g.firstPage(); 
  do {   
  } while( u8g.nextPage() );
  digitalWrite(buzzer,HIGH); 
  delay(3000);
  digitalWrite(buzzer,LOW);     
  selesai();
}

}

void draw(void) {
 
  //float dua angka dibelakang koma
  dtostrf(suhu, 4, 2, tmp_string1);
  dtostrf(menit, 4, 0, tmp_string2);
  dtostrf(setpoint, 4, 0, tmp_string3);
    
  // graphic commands to redraw the complete screen should be placed here 
  u8g.setFont(u8g_font_unifont);
  //u8g.setFont(u8g_font_osb21);
  u8g.drawStr(0, 22, "suhu= ");
  u8g.drawStr(60, 22, tmp_string1);   
  u8g.drawStr(0, 42, "menit= ");
  u8g.drawStr(60, 42, tmp_string2); 
  u8g.drawStr(0, 62, "SP= ");
  u8g.drawStr(60, 62, tmp_string3); 
}

void selesai(void){

  u8g.setFont(u8g_font_unifont);
  u8g.drawStr(0, 22, "selesai");
  dimmer.begin(NORMAL_MODE, OFF);
  dimmer.setPower(0);
   
selesai();  
}



c. VIDEO HASILNYA




Monitor Tegangan dan Arus AC 220 Volt dan Notif SMS

Monitor Tegangan dan Arus AC 220 Volt dan Notif SMS


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana membuat sebuah alat yang dapat memonitor tegangan atau arus drop dengan notifikasi sms, jadi alat ini selain memiliki fitur sms dia juga dapat memonitor tegangan dan arus secara rael time dengan menggunakan sensor PZEM-004t. 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 <PZEM004Tv30.h>
#include <LiquidCrystal_I2C.h>
#include "sms.h"
SMSGSM sms;

PZEM004Tv30 pzem(11, 12);
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];
float tegangan;
float arus;

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("081234567890", "Alat Ready"))
          Serial.println("\nSMS sent OK");
     }    
}

void loop() {

  tegangan = pzem.voltage();
  arus = pzem.current();

  lcd.setCursor(0,0);
  lcd.print("V: ");
  lcd.print(tegangan);
  lcd.print("   ");
  
  lcd.setCursor(0,1);
  lcd.print("I: ");
  lcd.print(arus);
  lcd.print("   ");

 if((arus >= 0.1)&&(kondisi == 0)){
    Serial.println("GSM Shield testing.");
     if (gsm.begin(2400)) {
          Serial.println("\nstatus=READY");
          started=true;
     } else Serial.println("\nstatus=IDLE");
     
      if (sms.SendSMS("081234567890", "telah terjadi arus bocor atau melebihi 300 mA"))
      Serial.println("\nSMS sent OK");
      kondisi = 1;
      delay(1000);
   }
 
 if((arus < 0.1)&&(kondisi == 1)){
      kondisi = 0;
      delay(3000);
   }
     
delay(200);
}



c. VIDEO HASILNYA



 

Monitor Arus dan Tegangan 3 Fasa via IOT BLYNK 2.0

Monitor Arus dan Tegangan 3 Fasa via IOT BLYNK 2.0 



       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor tegangan 3 fasa dengan menggunakan IOT Blynk. sensor yang dipakai yaitu PZEM-004t dengan Microcontroller Arduino dan Nodemcu / wemos ESP8266. untuk lebih jelasnya berikut adalah koding dan skemanya.


 
a. Skema



b. Program Arduino IDE

#include <Wire.h>  // i2C Conection Library
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <PZEM004Tv30.h>
#include <SoftwareSerial.h>
LiquidCrystal_I2C lcd(0x27,20,4); 
PZEM004Tv30 pzem1(A12, A13);
PZEM004Tv30 pzem2(A8, A9);
PZEM004Tv30 pzem3(A10, A11);
int voltage1, voltage2, voltage3;
float arusR, arusS, arusT;

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

void loop() {
  
voltage1 = pzem1.voltage();
voltage2 = pzem2.voltage();
voltage3 = pzem3.voltage();
arusR = pzem1.current();
arusS = pzem2.current();
arusT = pzem3.current();

/*
lcd.setCursor(0, 0);
lcd.print(arusR);
lcd.print("/");
lcd.print(arusS);
lcd.print("/");
lcd.print(arusT);
lcd.print(" ");
*/

lcd.setCursor(0, 1);
lcd.print("VR:  ");
lcd.print(voltage1);
lcd.print("  ");

lcd.setCursor(0, 2);
lcd.print("VS:  ");
lcd.print(voltage2);
lcd.print("  ");

lcd.setCursor(0, 3);
lcd.print("VT:  ");
lcd.print(voltage3);
lcd.print("  ");

Serial.print("*");
Serial.print(voltage1);
Serial.print(",");
Serial.print(voltage2);
Serial.print(",");
Serial.print(voltage3);
Serial.print(",");
Serial.print(arusR * 100.0);
Serial.print(",");
Serial.print(arusS * 100.0);
Serial.print(",");
Serial.print(arusT * 100.0);
Serial.println("#");  

delay(200);
}



c. Progam ESP8266

#define BLYNK_TEMPLATE_ID "TMPL6wxxxxxxx"
#define BLYNK_TEMPLATE_NAME "monitor daya"
#define BLYNK_AUTH_TOKEN "VOK0cWiFN5ycHj3SV_snEDXTfTxxxxx"

#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 vr = 0;
float vs = 0;
float vt = 0;
float arusR = 0;
float arusS = 0;
float arusT = 0;

float datain1;
float datain2;
float datain3;
float datain4;
float datain5;
float datain6;

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "hotspothpku";
char pass[] = "1234567890";

BlynkTimer timer;

void sendSensor()
{

 Blynk.virtualWrite(V0, vr);
 Blynk.virtualWrite(V1, vs);
 Blynk.virtualWrite(V2, vt);
 Blynk.virtualWrite(V3, arusR);
 Blynk.virtualWrite(V4, arusS);
 Blynk.virtualWrite(V5, arusT);
 delay(1000);

}

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

void loop()
{


if(vr < 200){
   Blynk.logEvent("tegangan Drop"); 
}

if(vs < 200){
   Blynk.logEvent("tegangan Drop"); 
}

if(vt < 200){
   Blynk.logEvent("tegangan Drop"); 
}
  

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();
datain3 = dt[2].toInt();
datain4 = dt[3].toInt();
datain5 = dt[4].toInt();
datain6 = dt[5].toInt();

 vr = datain1 / 1;
 vs = datain2 / 1;
 vt = datain3 / 1;
 arusR = datain4 / 100.0;
 arusS = datain5 / 100.0;
 arusT = datain6 / 100.0;

}



d. VIDEO HASILNYA