Translate

Membuat Alat Monitoring Gas Polutan ( CO / Co2 / NO ) dan Debu Menggunakan Data Logger SD Card / Micro SD ARDUINO

Membuat Alat Monitoring Gas Polutan ( CO / Co2 / NO ) dan Debu Menggunakan Data Logger SD Card / Micro SD ARDUINO


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa digunakan untuk monitor gas polutan yaitu CO, CO2, NO dll. dan juga debu. alat ini dilengkapi dengan data logger berupa micro SD atau SD card sehingga data akan disimpan kedalam memori. alat ini memang sengaja tidak menggunakan LCD untuk interfacenya. untuk lebih jelasnya berikut adalah skema dan programnya.




a. Arduino Uno




b. Sensor Gas Polutan MQ-7 dan MQ-135





c. Sensor Debu




d. Modul Micro SD






e. Program Arduino IDE

//https://github.com/R2D2-2017/R2D2-2017/wiki/MQ-7-gas-sensor

#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include "MQ135.h"
#define ANALOGPIN A1    //  Define Analog PIN on Arduino Board
#define RZERO 206.85    //  Define RZERO Calibration Value
MQ135 gasSensor = MQ135(ANALOGPIN);

  float RS_air; //  Get the value of RS via in a clear air
  float R0 = 0.25;  // Get the value of R0 via in H2
  float sensorValue;
  float sensor_volt;
  float RS_gas;
  float ratio;


//mosi - 11
//miso - 12
//clk - 13
//cs - 4

int cacah = 0;
File myFile;
int ledx = 2;

float Dustval;

float ppm;
float ppm2;


void setup(){
  Serial.begin(9600);
 pinMode(ledx,OUTPUT);

  float rzero = gasSensor.getRZero();
  delay(3000);
  Serial.print("MQ135 RZERO Calibration Value : ");
  Serial.println(rzero);
    
}

void loop(){
gasmq135();
gasmq7();
debu();

  Serial.print(ppm);
  Serial.print(" ");
  Serial.print(ppm2);
  Serial.print(" ");
  Serial.println(Dustval);

delay(200);

cacah++;

if(cacah > 10){
cacah = 0;
simpan();
}

}


void gasmq135(){

  ppm = gasSensor.getPPM();
  delay(1000);
  //Serial.print("CO2 ppm value : ");
  //Serial.println(ppm);
    
}


void gasmq7(){

analogWrite(A5, 1023);
//Heather 1.4 V 90 s
    analogWrite(A5, (1023/5)*1.4 );
    for(int i = 0; i<90; i++){
        sensorValue = analogRead(A2);
        sensor_volt = sensorValue/1024*5.0;
        RS_gas = (5.0-sensor_volt)/sensor_volt;
        ratio = RS_gas/R0; //Replace R0 with the value found using the calibration code
        float kal = 83.39 / ratio;
        ppm2 = pow(kal , 0.63);      
        delay(100);
    }

}


void debu(){
//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);

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

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

float v = dataadc * (5.0 / 1023.0);

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

}



void simpan(){

while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  pinMode(10, OUTPUT);

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
     
    myFile.print("CO2= ");
    myFile.println(ppm);
    myFile.print("CO= ");
    myFile.println(ppm2);
    myFile.print("Debu= ");
    myFile.println(Dustval);
     
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }


}






f. VIDEO HASILNYA









No comments:

Post a Comment