/* Materials 1. Arduino Uno 2. MQ-135 Gas Sensor 3. OOTDTY 4 Bits Digital Tube LED Display Module 4. Lcd 1602 Module 5. Passive Buzzer Module 5V 6. PVC box Tools 1. Laser cutter 2. Hot glue gun PVC box making 1. Create a scheme of your box or use mine (link). Dont forget to cut out holes for mounting sensors and modules later. You need 6 pieces for 6 sides of the box. 2. Use laser cutter to cut it out. 3. Use a hot glue gun to stick 5 sides together. The 6th one will be a lid so you can open and close it. Assembly 1. Upload the code, using arduino software. You can use mine ( download it from here), or write your own. 2. Connect all modules and sensors to our arduino according to the circuit. 3. Put everything inside the box and mount sensors and modules using hot glue gun. Detail steps have shown in https://www.instructables.com/id/Toxic-Gas-Detector Made by Andrew Wang & Litchee Lab 2017. Wrote on C++, based on Arduino. */ #include #include LiquidCrystal_I2C lcd(0x3F,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display #SDA //#SDA ¡ª¡ª¡ª¡ª A4£¨SDA behind AREF£© //#SCL ¡ª¡ª¡ª¡ª A5 (SCL behind AREF) // Define the number of samples to keep track of. The higher the number, // the more the readings will be smoothed, but the slower the output will // respond to the input. Using a constant rather than a normal variable lets // use this value to determine the size of the readings array. const int numReadings = 10; int readings[numReadings]; // the readings from the analog input int readIndex = 0; // the index of the current reading int total = 0; // the running total int average = 0; // the average float v; int v0,v1,v2,v_int; int inputPin = A0; //int Pin_buzzer = 5; //buzzer pin unsigned char LED_0F[] = {// 0 1 2 3 4 5 6 7 8 9 A b C d E F - //0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x8C,0xBF,0xC6,0xA1,0x86,0xFF,0xbf 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff }; unsigned char LED_0F_DP2[] = {// 0 1 2 3 4 5 6 7 8 9 A b C d E F - //0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x8C,0xBF,0xC6,0xA1,0x86,0xFF,0xbf 0x40,0x79,0x24,0x30,0x19,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e }; unsigned char LED[4]; // used for LCD¡¯s 4 digit cache int SCLK = 2; int RCLK = 3; int DIO = 4; // defined those 3 pins at here int buzzer = 8; void setup() { // initialize serial communication with computer //initialize all the readings to 0: for (int thisReading = 0; thisReading < numReadings; thisReading++) { readings[thisReading] = 0; } pinMode(SCLK,OUTPUT); pinMode(RCLK,OUTPUT); pinMode(DIO,OUTPUT); // let those 3 pins at output status pinMode(buzzer,OUTPUT); lcd.init(); // initialize the lcd digitalWrite(buzzer,HIGH); // Print a message to the LCD. lcd.backlight(); lcd.setCursor(0,0); lcd.print("Harmful gas are"); lcd.setCursor(4,1); lcd.print("DETECTED"); } void loop() { // subtract the last reading: total = total - readings[readIndex]; // read from the sensor: readings[readIndex] = analogRead(inputPin); // add the reading to the total: total = total + readings[readIndex]; // advance to the next position in the array: readIndex = readIndex + 1; // if we're at the end of the array... if (readIndex >= numReadings) { // ...wrap around to the beginning: readIndex = 0; } // calculate the average: average = total / numReadings; v = average/1024.00 * 5.00; v_int = int(v*100); v0 = v_int%10; v1 = v_int/10%10; v2 = v_int/100%10; if(v_int>100) { digitalWrite(buzzer,LOW); delay(1); digitalWrite(buzzer,HIGH); } LED[3]=16; LED[2]=v2; LED[1]=v1; LED[0]=v0; LED4_Display (); } void LED4_Display (void) { unsigned char *led_table; unsigned char i; // display the first digit led_table = LED_0F + LED[0]; i = *led_table; LED_OUT(i); LED_OUT(0x01); digitalWrite(RCLK,LOW); digitalWrite(RCLK,HIGH); // display the second digit led_table = LED_0F + LED[1]; i = *led_table; LED_OUT(i); LED_OUT(0x02); digitalWrite(RCLK,LOW); digitalWrite(RCLK,HIGH); // display the third digit led_table = LED_0F_DP2 + LED[2]; i = *led_table; LED_OUT(i); LED_OUT(0x04); digitalWrite(RCLK,LOW); digitalWrite(RCLK,HIGH); // display the forth digit led_table = LED_0F + LED[3]; i = *led_table; LED_OUT(i); LED_OUT(0x08); digitalWrite(RCLK,LOW); digitalWrite(RCLK,HIGH); } void LED_OUT(unsigned char X) { unsigned char i; for(i=8;i>=1;i--) { if (X&0x80) { digitalWrite(DIO,HIGH); } else { digitalWrite(DIO,LOW); } X<<=1; digitalWrite(SCLK,LOW); digitalWrite(SCLK,HIGH); } }