Translate

Monitor Gas MQ2 dan MQ135 serta suhu DHT22

Monitor Gas MQ2 dan MQ135 serta suhu DHT22 
 

           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor suhu dan gas. sensor yang dipakai yaitu DHT22 dan GAS MQ2 MQ135. jadi alat ini menampilkan nilai suhu dan gas secara realtime pada lcd. untuk lebih jelasnya berikut adalah program dan komponennya.



a. Komponen Penyusun




b. Program Arduino IDE

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

#define DHTPIN 8
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define DHTTYPE DHT22

float t;
int mq135;
int mq2;
int v;

DHT dht(DHTPIN, DHTTYPE);


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

void loop()
{
  t = dht.readTemperature();
  mq135 = analogRead(A0);
  mq2 = analogRead(A1);
  
  lcd.setCursor(0,0);
  lcd.print("Suhu= ");
  lcd.print(t);
  lcd.print("   ");
  
  lcd.setCursor(0,1);
  lcd.print("G1/G2= ");
  lcd.print(mq135);
  lcd.print("/");
  lcd.print(mq2);
  lcd.print("   ");
  
  delay(200);
}



c. VIDEO HASILNYA




Monitor Suhu Tubuh, Tegangan dan Arus AC, Kemiringan TILT, Flow dan Pressure Udara via Arduino Blynk 2.0

Monitor Suhu Tubuh, Tegangan dan Arus AC, Kemiringan TILT, Flow dan Pressure Udara via Arduino Blynk 2.0 


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor tekanan dan flow udara, arus dan tegangan ac, suhu dan kemiringan. alat ini dimonitor menggunakan Blynk 2.0. sensor yang dipakai diantaranya yaitu MPU6050, PZEM-004t, Ds18b20. untuk lebih jelasnya berikut adalah komponen dan programnya.



a. Komponen Penyusun




b. Program Arduino IDE

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

#include <DallasTemperature.h>
#include <OneWire.h> 
#include <MPU6050.h>
#include <PZEM004Tv30.h>
PZEM004Tv30 pzem(10, 11);
LiquidCrystal_I2C lcd(0x27, 16, 2);

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

MPU6050 mpu;

byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin       = 2;

float calibrationFactor = 4.5;

volatile byte pulseCount;

unsigned int frac;
float flowRate;
unsigned int flowMilliLitres;
float totalMilliLitres;
unsigned long oldTime;

int x;
float v;
float psi;
float bar;
float voltage;
float current;
float efisiensi;

int dataadc;
float pressure;
float suhu;
int sudut;

void setup() {
  sensors.begin();
  lcd.begin();
  lcd.noCursor();
  lcd.clear();
  Serial.begin(9600);
  delay(10);
  
  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;

  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);

  //Serial.println("Initialize MPU6050");
  
  while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
  {
    //Serial.println("tidak ada sensor MPU6050 yang terpasang!");
    delay(500);
  }
 
  //Kalibrasi gyrometer
  mpu.calibrateGyro();
  mpu.setThreshold(3);
     
}


void loop() {
  
  voltage = pzem.voltage();
  current = pzem.current();
  sensors.requestTemperatures();
  suhu = sensors.getTempCByIndex(0);
    
  x = analogRead(A0);
  v = x*(5.0/1023.0);
  psi = 250 * (v/5.0);
  psi = psi - 27.0;
  bar = psi * 0.0689476;
  
  if(bar < 0){
    bar = 0;
  }

  if((millis() - oldTime) > 1000) 
  {

    detachInterrupt(sensorInterrupt);
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    oldTime = millis();
    flowMilliLitres = (flowRate / 60) * 1000;
    totalMilliLitres += flowMilliLitres;
    frac = (flowRate - int(flowRate)) * 10;
    pulseCount = 0;
   
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
  }

  Vector rawAccel = mpu.readRawAccel();
  sudut = rawAccel.XAxis;

  efisiensi = (9.81*(bar+1.032)*10000*flowRate)/(1.723*voltage*current*0.85);

  lcd.setCursor(0,0);
  lcd.print(sudut);
  lcd.print("/");
  lcd.print(bar,1);
  lcd.print("/");
  lcd.print(suhu,1);
  lcd.print("     ");
  
  lcd.setCursor(0,1);
  lcd.print(flowRate,1);
  lcd.print("/");  
  lcd.print(efisiensi,1);
  lcd.print("/");  
  lcd.print(current);
  lcd.print("   "); 
  
  /*Serial.println("Accelerometer");
  Serial.print("X : ");
  Serial.print(rawAccel.XAxis);
  Serial.print("Y : ");
  Serial.print(rawAccel.YAxis);
  Serial.print("Z : ");
  Serial.println(rawAccel.ZAxis);
  */

Serial.print("*");
Serial.print(bar*100);
Serial.print(",");
Serial.print(flowRate*100);
Serial.print(",");
Serial.print(sudut);
Serial.print(",");
Serial.print(voltage*100);
Serial.print(",");
Serial.print(current*100);
Serial.print(",");
Serial.print(suhu*100);
Serial.println("#");  
  
delay(200);
}

void pulseCounter()
{
  pulseCount++;
}



c. Program ESP8266

#define BLYNK_TEMPLATE_ID "HJFDR678gdvhjf"

#define BLYNK_TEMPLATE_NAME "monitor flow presure"
#define BLYNK_AUTH_TOKEN "HJHGyu68gdkjgffh89hfdhbcgfghjggfd7n"

#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 presure = 0;
float flow = 0;
int accel = 0;
float tegangan = 0;
float arus = 0;
float suhu = 0;

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

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

BlynkTimer timer;

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


void sendSensor()
{

 Blynk.virtualWrite(V0, presure);
 Blynk.virtualWrite(V1, flow);
 Blynk.virtualWrite(V2, accel);
 Blynk.virtualWrite(V3, tegangan);
 Blynk.virtualWrite(V4, arus);
 Blynk.virtualWrite(V5, suhu);
 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();
datain3 = dt[2].toInt();
datain4 = dt[3].toInt();
datain5 = dt[4].toInt();
datain6 = dt[5].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("\n");
Serial.print("data 4 : ");
Serial.print(datain4);
Serial.print("\n");

//Serial.print("data 3 : ");
//Serial.print(dt[2].toInt());
//Serial.print("\n\n");

 presure = datain1 / 100.0;
 flow = datain2 / 100.0;
 accel = datain3 / 1;
 tegangan = datain4 / 100.0;
 arus = datain5 / 100.0;
 suhu = datain6 / 100.0;
  
}




d. VIDEO ALATNYA





Monitor Suhu Tubuh Non-Contact MLX90614 dan Sensor Gerak PIR

Monitor Suhu Tubuh Non-Contact MLX90614 dan Sensor Gerak PIR




       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat untuk memonitor suhu tubuh secara non-contact. alat ini akan memonitor suhu saat adanya gerakan, jadi pada saat sensor gerak (PIR) aktif maka akan mengambil nilai suhu tubuh. sensor yang dipakai yaitu MLX90614 dan sensor PIR. untuk lebih jelasnya berikut adalah koding dan komponennya.



a. Komponen Penyusun




b. Program Arduino IDE

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

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

float TargetC;
int ledmerah = 2;
int dataadc;

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

void loop(){
           
 TargetC = mlx.readObjectTempC();
 dataadc = analogRead(A0);

  if(dataadc > 10){
      lcd.setCursor(0,0);
      lcd.print("Suhu= ");
      lcd.print(TargetC);
      lcd.println(" 'C     ");
     }
     
      lcd.setCursor(0,1);
      lcd.print("ADC: ");
      lcd.print(dataadc);
      lcd.print("  ");
   
      if(TargetC <=  31.0) { 
       digitalWrite(ledmerah,HIGH);  
      }
      if (TargetC > 31.0 ) {
       digitalWrite(ledmerah,LOW);
      }
   
delay(200);
}
   


c. VIDEO HASILNYA




Monitor PH Kelembaban Suhu Fertili Tanah via Blynk 2.0 dan Kendali Pompa Automatis / Manual

Monitor PH Kelembaban Suhu Fertili Tanah via Blynk 2.0 dan Kendali Pompa Automatis / Manual


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor 4 buah parameter yaitu suhu dan kelembaban tanah serta PH dan fertili tanah. jadi alat ini ada 2 mode yaitu mode otomatis dan manual. untuk mode otomatis maka relay pompa akan bekerja sesuai nilai sensor, jika mode manual maka on/off pompa relay menggunakan aplikasi Blynk 2.0. alat ini selain kendali juga terdapat fitur IOT untuk monitor 4 parameter tersebut via Blynk 2.0. untuk lebih jelasnya berikut adalah koding dan komponennya.


a. Komponen Penyusun



b, Program Arduino IDE

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

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

float ntu;
int soil;
int adcntu;
int phfertil;
float suhu;
int bt1 = 2;
int bt2 = 3;
int bt3 = 4;
int bt4 = 5;
int bt1x;
int bt2x;
int bt3x;
int bt4x;
int relay1 = 6; //pompa air
int relay2 = 7; //pompa pupuk
int relay3 = 8; //pompa desinfektan
int relay4 = 9;
float ph;
int fertili;
int tanda;
int adcnya;
int otomatis;
int input1 = A2;
int input2 = 12;
int input3 = 11;
int input1x;
int input2x;
int input3x;

void setup()
{
  Serial.begin(9600);
  sensors.begin();
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  pinMode(bt1,INPUT_PULLUP);
  pinMode(bt2,INPUT_PULLUP);
  pinMode(bt3,INPUT_PULLUP);
  pinMode(bt4,INPUT_PULLUP);
  pinMode(relay1,OUTPUT);
  pinMode(relay2,OUTPUT);
  pinMode(relay3,OUTPUT);
  pinMode(relay4,OUTPUT);
  digitalWrite(relay1,LOW);
  digitalWrite(relay2,LOW);
  digitalWrite(relay3,LOW);
  digitalWrite(relay4,LOW);
  pinMode(relay4,OUTPUT);
  pinMode(input1,INPUT);
  pinMode(input2,INPUT);
  pinMode(input3,INPUT);
}

void loop()
{

bt1x = digitalRead(bt1);
bt2x = digitalRead(bt2);
bt3x = digitalRead(bt3);
bt4x = digitalRead(bt4);
  
adcntu = analogRead(A0);             
soil = map(adcntu, 1023, 0, 0, 100);

sensors.requestTemperatures();
suhu = sensors.getTempCByIndex(0);

   lcd.setCursor (0,0);
   lcd.print ("T/S= ");
   lcd.print (suhu,1);
   lcd.print ("/");
   lcd.print (soil);
   lcd.print ("% ");

if(bt3x == 0){
  otomatis = 0;
}

if(bt4x == 0){
  otomatis = 1;
}

if(tanda == 0){
   adcnya = analogRead(A1);
   ph = (-0.1538 * adcnya) + 7;
   lcd.setCursor (0,1);
   lcd.print ("PH= ");
   lcd.print (ph);
   lcd.print ("             ");
}

if(tanda == 1){
   fertili = analogRead(A1);
   lcd.setCursor (0,1);
   lcd.print ("Fer= ");
   lcd.print (fertili);
   lcd.print ("    ");

   if(fertili < 10){
   lcd.setCursor (9,1);
   lcd.print ("KURANG  ");
}

if((fertili >= 10)&&(fertili < 20)){
   lcd.setCursor (9,1);
   lcd.print ("IDEAL  ");
}

if(fertili > 20){
   lcd.setCursor (9,1);
   lcd.print ("LEBIH  ");
}
}


if(otomatis == 0){
  input1x = digitalRead(input1);
  input2x = digitalRead(input2);
  input3x = digitalRead(input3);

  lcd.setCursor (15,0);
  lcd.print ("M"); //manual

  if((input1x == 1)&&(otomatis == 0)){
    digitalWrite(relay1,HIGH); //POMPA AIR ON 
  }

  if((input1x == 0)&&(otomatis == 0)){
    digitalWrite(relay1,LOW); //POMPA AIR OFF
  }

  if((input2x == 1)&&(otomatis == 0)){
    digitalWrite(relay2,HIGH); //POMPA PUPUK ON 
  }

  if((input2x == 0)&&(otomatis == 0)){
    digitalWrite(relay2,LOW); //POMPA PUPUK OFF
  }

  if((input3x == 1)&&(otomatis == 0)){
    digitalWrite(relay3,HIGH); //POMPA DESINFEKTAN ON 
  }

  if((input3x == 0)&&(otomatis == 0)){
    digitalWrite(relay3,LOW); //POMPA DESINFEKTAN OFF
  }

}

if(otomatis == 1){
   lcd.setCursor (15,0);
   lcd.print ("O");
   
   if(soil < 50){
   digitalWrite(relay1,HIGH); //POMPA AIR ON 
   }
   if(soil >= 50){
   digitalWrite(relay1,LOW); //POMPA AIR OFF
   }

   if(fertili < 10){
   digitalWrite(relay2,HIGH); //POMPA PUPUK ON 
   }
   if(fertili >= 10){
   digitalWrite(relay2,LOW); //POMPA PUPUK OFF
   }
 
}

if(bt1x == 0){
  tanda = 0;
}

if(bt2x == 0){
  tanda = 1;
}
   
Serial.print("*");
Serial.print(suhu,0);
Serial.print(",");
Serial.print(soil);
Serial.print(",");
Serial.print(ph);
Serial.print(",");
Serial.print(fertili);
Serial.println("#");  

delay(200);
}



c. Program ESP8266

#define BLYNK_TEMPLATE_ID "UHBF46HGJhghb"
#define BLYNK_TEMPLATE_NAME "monitor tanah"
#define BLYNK_AUTH_TOKEN "jkghjhfttrg456fhFGHFhtfdggfdgfd6tghjhg"

#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 suhu = 0;
int soil = 0;
int ph = 0;
int fertili = 0;

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

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

BlynkTimer timer;

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


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

  if(pinValue == 1){
    digitalWrite(D6, HIGH);
  }
  
  if(pinValue == 0) {
    digitalWrite(D6, LOW);
  }
  
}

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

  if(pinValue2 == 1){
    digitalWrite(D7, HIGH);
  }
  
  if(pinValue2 == 0) {
    digitalWrite(D7, LOW);
  }
  
}

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

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



void sendSensor()
{

 Blynk.virtualWrite(V2, suhu);
 Blynk.virtualWrite(V3, soil);
 Blynk.virtualWrite(V4, ph);
 Blynk.virtualWrite(V5, fertili);
 delay(1000);
}


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

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();
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("\n");
Serial.print("data 4 : ");
Serial.print(datain4);
Serial.print("\n");

//Serial.print("data 3 : ");
//Serial.print(dt[2].toInt());
//Serial.print("\n\n");

 suhu = datain1 / 1;
 soil = datain2 / 1;
 ph = datain3 / 1;
 fertili = datain4 / 1;

}



d. VIDEO HASILNYA