Translate

Monitor Suhu dan Debu ONLINE BLYNK Sensor DHT11 dan GP2Y1010AU0F

Monitor Suhu dan Debu ONLINE BLYNK Sensor DHT11 dan GP2Y1010AU0F


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa mengukur suhu dan debu secara online dengan menggunakan Blynk. alat ini menggunakan sensor DHT11 dan GP2Y1010AU0F. untuk lebih jelasnya berikut adalah komponen dan kodingnya. 



a. Nodemcu ESP8266




b. Sensor DHT11




c. Sensor Debu GP2Y1010AU0F




d. LCD + I2C





e. Program Arduino IDE

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

int ledx = D6;
int h;
int t;
float Dustval;
int dataadc;
float v;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "TMJHGJ764HFJGF434NVNBCVXNBVNHMMVBVX";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Yanuar Iphone";
char pass[] = "13579ynr";

#define DHTPIN 0          // D3 dan led di D4

// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
  Blynk.virtualWrite(V9, t);
  Blynk.virtualWrite(V10, Dustval);
}

void setup()
{

  lcd.begin(); //set lcd i2c
  lcd.noCursor(); //biar gak ada cursor di lcd
  lcd.clear(); //clear lcd
  pinMode(ledx,OUTPUT); 
  
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

  dht.begin();

  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
}

void loop()
{

  h = dht.readHumidity();
  t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

//aktif low
//GP2Y1010AU0F_SAMPLEDELAY should be 280us to perform the correct reading
//this delay should consider that ADC conversion takes 13 ADC clock cycles
//ADCtime(s) = (1/ADCclock)*13 = (1/FCPU/ADCprescaler)*13
// es (1/(8000000/64))*13 = 0.000104s = 104us
//so to perform reading at correct time
//280 - (1/FCPU/ADCprescaler)*13*1000000   , 1000000 is the conversion factor from s to us
// es. 280 - 104 = 176

digitalWrite(ledx,LOW);    //on
delayMicroseconds(176);

dataadc = analogRead(A0);
delayMicroseconds(40);

digitalWrite(ledx,HIGH);   //off
delayMicroseconds(9680);

v = dataadc * (5.0 / 1023.0);

//y = 0.166x - 0.129
Dustval = (v * 0.166) - 0.129;

   lcd.setCursor(0, 0);
   lcd.print("Suhu: ");
   lcd.print(t);
   lcd.print(" C   ");
   lcd.setCursor(0, 1);
   lcd.print("Dust= ");
   lcd.print(Dustval);
   lcd.print(" mg/m3   ");
   
  Blynk.run();
  timer.run();
}




f. VIDEO HASILNYA







No comments:

Post a Comment