[lwptoc title=”Daftar Isi”]
Asap rokok merupakan problem yang banyak dialami saat ini, banyak upaya yang dilakukan untuk menekan penggunaan rokok dikarenakan bahaya yang ditimbulkan oleh rokok. Pengguna rokok pula terkadang merokok diruangan yang membuat ruangan penuh dengan asap, untuk itu perlu adanya alat yang dapat mengetahui kadar asap rokok dalam sebuah ruangan agar pengguna merasa terganggu dan berhenti merokok diruangan tersebut.
[membership level=”0,1,2,4″]
1. Alat / Bahan
- Arduino IDE Download
- Library: LiquidCrystal_I2C Download
- Arduino Uno 1 Buah
- Sensor Mq-2 1 Buah
- LCD 16×2 1 Buah
- I2C 1 Buah
- Project Board 1 Buah
- Kabel Jumper Secukupnya
Segera dapatkan komponen elektronik di atas silahkan temukan disini.
2. Skema Rangkaian
Gambar Rangkaian Alat Ukur Kadar Asap Rokok Dalam Ruangan
Keterangan:
- 5V – VCC Mq-2, VCC I2C
- GND – GND Mq-2, GND I2C
- A0 – Pin Data Mq-2
- SDA – SDA I2C
- SCL – SCL I2C
- Pin LCD – Pin I2C
[/membership]
Belajar Elektronika, Arduino, dan IoT step by step dengan bantuan tangga belajar?Segera Daftar sekarang dan dapatkan PROMO
3. Langkah Kerja
- Pertama Siapkan alat dan 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
- Kemudian Unduh semua library di atas dan masukkan libray tersebut dengan cara buka Arduino IDE pilih Sketch->Include Library->Add.Zip Library
- Setelah itu Ketikkan sketch program pada halaman Arduino IDE
- Selanjutnya Masukan alamat I2C LCD pada sketch program, untuk mengetahui alamat I2C pelajari materi berikut:
Mencari Tahu Alamat I2C Pada Modul I2C - Kemudian Untuk memahami cara kerja sensor MQ-2, pelajari materi berikut:
Mengakses sensor Gas MQ-2 dengan tampilan LCD 16×2 - Segera Lakukan proses uploading program
4. Sketch Program
Dapatkan akses ratusan video tutorial dan pembelajaran dengan registrasi melalui tombol di bawah!
/* Program Alat Ukur Kadar Asap Rokok Dalam Ruangan dibuat oleh Indobot */ #include <LiquidCrystal_I2C.h> //Library I2C LCD LiquidCrystal_I2C lcd(0x27,16,2); //Alamat I2C /************************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 void setup() { 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() { //Pilih jenis gas yang akan dideteksi dengan menghilangkan komentar "//" //long iPPM_LPG = 0; //long iPPM_CO = 0; long iPPM_Smoke = 0; //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("CO2: "); lcd.print(iPPM_Smoke); 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]))); }
Kesimpulannya:
Kesimpulannya Ketika Sensor Mq-2 mulai aktif, sensor akan mulai mendeteksi kadar asap diruangan tersebut dan menampilkan hasil pembacaan sensor pada layar LCD.
[/membership]
Kamu ingin memperbanyak jam terbang dan portofolio bikin project elektronika/ Arduino/ IoT? Segera Ikuti program dari Indobot!