Pemanasan global semakin kesini semakin parah. Salah satu penyebabnya ialah asap kendaraan bermotor. Pemerintah sendiri sudah menetapkan ambang batas zat buangan pada kadar tertentu. Namun, apakah kalian tahu bagaimana cara mengukur gas CO tersebut? Kali ini kita akan membuat alat yang dapat mengukur kadar gas CO yang dikeluarkan dari kendaraan bermotor dan menghubungkannya dengan internet.
[membership level=”0,1,2,4″]
1. Alat / Bahan
- Arduino IDE Download
- Library: Blynk Download
- Library: ESP8266 Download
- Library: LiquidCrystal_I2C Download
- NodeMCU 1 Buah
- Sensor MQ-2 1 Buah
- LCD 16×2 1 Buah
- I2C 1 Buah
- Project Board 1 Buah
- Kabel Jumper Secukupnya
- Smartphone 1 Buah
Untuk mendapatkan komponen elektronik di atas silahkan temukan disini.
2. Skema Rangkaian
Gambar Rangkaian Pengukur Tingkat Asap Knalpot Kendaraan Bermotor berbasis IoT
Keterangan:
- VU – VCC MQ-2, VCC I2C
- GND – GND MQ-2, GND I2C
- A0 – Pin Data MQ-2
- D1 – SCL I2C
- D2 – SDA I2C
- Pin LCD – Pin I2C
[/membership]
3. Layout Blynk
Keterangan:
- Konsentrasi Asap (Gauge)
- Input V0, Low = 0, High = 1000
- Label = /pin.#/ppm
- Design Text = Red
4. Langkah Kerja
- Siapkan alat dan juga bahan yang akan digunakan
- kedua Lakukan proses wiring dengan menggunakan Gambar skematik rangkaian diatas
- ketiga Buka software Arduino IDE yang telah terinstal pada laptop/komputer
- Unduh semua library di atas dan juga masukkan libray tersebut dengan cara buka Arduino IDE pilih Sketch->Include Library->Add.Zip Library
- Ketikkan sketch program pada halaman Arduino IDE
- Sesuaikan Auth Tokens dengan proyek aplikasi Blynk. Cara setting dan mendapatkan Auth Tokens dapat dilihat pada tutorial berikut:
Setting Blynk untuk NodeMCU ESP8266 - Ganti ssid dan juga pass dengan nama wifi dan password wifi yang kalian gunakan
- Lakukan proses uploading program
- kemudian Buka aplikasi Blynk
- selanjutnya Buat layout Blynk seperti gambar di atas.
- Tekan tombol Play pada aplikasi Blynk lalu tunggu hingga proyek kalian terhubung dengan aplikasi Blynk
5. Sketch Program
Belajar elektronika step by step dengan bantuan tangga belajar? Regitrasi dulu dan dapatkan konsultasi dari kami!
/* Program Pengukur Tingkat Asap Knalpot Kendaraan Bermotor berbasis IoT dibuat oleh Indobot */ #include <ESP8266WiFi.h> //Library ESP8266 #include <BlynkSimpleEsp8266.h> //Library Blynk #include <LiquidCrystal_I2C.h> //Library I2C LCD LiquidCrystal_I2C lcd(0x27,16,2); //Alamat I2C char auth[] = "HoP9z23_PbWp-iEyMBYFGnnALYBvvcXS"; //Token char ssid[] = "Wifi.id"; //Nama wifi char pass[] = "alam oye"; //Password wifi BlynkTimer timer; /************************Hardware Related Macros************************************/ const int calibrationLed = 13; //when the calibration start , LED pin 13 will light up , off when finish calibrating const int MQ_PIN=A0; //define which analog input channel you are going to use int RL_VALUE=5; //define the load resistance on the board, in kilo ohms float RO_CLEAN_AIR_FACTOR=9.83; //RO_CLEAR_AIR_FACTOR=(Sensor resistance in clean air)/RO, //which is derived from the chart in datasheet /***********************Software Related Macros************************************/ int CALIBARAION_SAMPLE_TIMES=50; //define how many samples you are going to take in the calibration phase int CALIBRATION_SAMPLE_INTERVAL=500; //define the time interal(in milisecond) between each samples in the //cablibration phase int READ_SAMPLE_INTERVAL=50; //define how many samples you are going to take in normal operation int READ_SAMPLE_TIMES=5; //define the time interal(in milisecond) between each samples in //normal operation /**********************Application Related Macros**********************************/ #define GAS_LPG 0 #define GAS_CO 1 #define GAS_SMOKE 2 /*****************************Globals***********************************************/ float LPGCurve[3] = {2.3,0.21,-0.47}; //two points are taken from the curve. //with these two points, a line is formed which is "approximately equivalent" //to the original curve. //data format:{ x, y, slope}; point1: (lg200, 0.21), point2: (lg10000, -0.59) float COCurve[3] = {2.3,0.72,-0.34}; //two points are taken from the curve. //with these two points, a line is formed which is "approximately equivalent" //to the original curve. //data format:{ x, y, slope}; point1: (lg200, 0.72), point2: (lg10000, 0.15) float SmokeCurve[3] ={2.3,0.53,-0.44}; //two points are taken from the curve. //with these two points, a line is formed which is "approximately equivalent" //to the original curve. //data format:{ x, y, slope}; point1: (lg200, 0.53), point2: (lg10000, -0.22) float Ro = 10; //Ro is initialized to 10 kilo ohms //Pilih jenis gas yang akan dideteksi dengan menghilangkan komentar "//" //long iPPM_LPG = 0; long iPPM_CO = 0; //long iPPM_Smoke = 0; void setup() { Blynk.begin(auth, ssid, pass); //Inisialisasi token, wifi dan password timer.setInterval(1000L, sendSensor); //Kirim data sensor lcd.init (); lcd.setBacklight(HIGH); pinMode(calibrationLed,OUTPUT); digitalWrite(calibrationLed,HIGH); lcd.print("Calibrating..."); //LCD display Ro = MQCalibration(MQ_PIN); //Calibrating the sensor. Please make sure the sensor is in clean air digitalWrite(calibrationLed,LOW); lcd.clear(); lcd.print("done!"); //LCD display lcd.setCursor(0,1); lcd.print("Ro= "); lcd.print(Ro); lcd.print(" kohm"); delay(3000); } void loop() { Blynk.run(); //Jalankan pembacaan Blynk timer.run(); //iPPM_LPG = MQGetGasPercentage(MQRead(MQ_PIN)/Ro,GAS_LPG); iPPM_CO = MQGetGasPercentage(MQRead(MQ_PIN)/Ro,GAS_CO); //iPPM_Smoke = MQGetGasPercentage(MQRead(MQ_PIN)/Ro,GAS_SMOKE); lcd.clear(); lcd.setCursor(0,0); lcd.print("Konsentrasi Asap"); lcd.setCursor(0,1); lcd.print("CO: "); lcd.print(iPPM_CO); lcd.print(" ppm"); delay(200); } float MQResistanceCalculation(int raw_adc) { return ( ((float)RL_VALUE*(1023-raw_adc)/raw_adc)); } float MQCalibration(int mq_pin) { int i; float val=0; for (i=0;i<CALIBARAION_SAMPLE_TIMES;i++) { //take multiple samples val += MQResistanceCalculation(analogRead(mq_pin)); delay(CALIBRATION_SAMPLE_INTERVAL); } val = val/CALIBARAION_SAMPLE_TIMES; //calculate the average value val = val/RO_CLEAN_AIR_FACTOR; //divided by RO_CLEAN_AIR_FACTOR yields the Ro return val; //according to the chart in the datasheet } float MQRead(int mq_pin) { int i; float rs=0; for (i=0;i<READ_SAMPLE_TIMES;i++) { rs += MQResistanceCalculation(analogRead(mq_pin)); delay(READ_SAMPLE_INTERVAL); } rs = rs/READ_SAMPLE_TIMES; return rs; } long MQGetGasPercentage(float rs_ro_ratio, int gas_id) { if ( gas_id == GAS_LPG ) { return MQGetPercentage(rs_ro_ratio,LPGCurve); } else if ( gas_id == GAS_CO ) { return MQGetPercentage(rs_ro_ratio,COCurve); } else if ( gas_id == GAS_SMOKE ) { return MQGetPercentage(rs_ro_ratio,SmokeCurve); } return 0; } long MQGetPercentage(float rs_ro_ratio, float *pcurve) { return (pow(10,( ((log(rs_ro_ratio)-pcurve[1])/pcurve[2]) + pcurve[0]))); } void sendSensor(){ //Kirim data sensor Blynk.virtualWrite(V0, iPPM_CO); //CO ke pin V0 }
Kesimpulan:
Pada layar LCD akan tertampil jumlah asap knalpot kendaraan. Data ini juga dikirim ke aplikasi Blynk pengguna sehingga dapat dipantau dari mana saja.
[/membership]
Kamu pemula dan ingin belajar atau bahkan bikin project elektronika dari nol? Ikuti program dari Indobot!