Introduction: Smoke and Carbon Monoxide Detector Using Arduino, the MQ2 Gas Sensor and a OLED Display
In this instructable I am going to be making a carbon monoxide and smoke detector.
In this version of a smoke detector we are going to have 3 buttons, that controls different aspects of the smoke and CO detector.
If high levels of smoke or CO is detected by the MQ2 gas sensor the LED flashes and the buzzer makes an alarm noise, alerting others if its presence. Its very important to have one of these as CO, carbon monoxide has no odor, color or taste and is virtually impossible to sense, and has the capability of giving us carbon monoxide poisoning.
If the sensor detects more than 100 PPM of either smoke or CO, the alarm goes off, the amount of smoke or CO will be displayed on the OLED display for you to see exactly how much CO or smoke is around you in PPM.
Supplies
1x Arduino Uno
1x Small Solderless Breadboard
1x MQ2 Gas Sensor
1x 0.96" I2C OLED Display
1x Buzzer
3x Push Buttons
3x 10k Ohm Resistors
1x 330 Ohm Resistor
1x Red LED
Wires (Any Color)
Step 1: Assembly and Wiring
This is where the bulk of your time is going to be spent, the wiring and assembly. Yours doesn't have to look like mine you can assemble in anyway you would like.
Start with adding your OLED, 3 buttons, 1 red LED and 1 buzzer to ap[propriate places on your breadboard.
OLED: To wire the OLED add a jumper cable from the power and ground rail into the VCC and GND pins of the display. Furthermore put the SCL pin in the A5 pin on the Arduino, and put the SDA pin in A4 on the Arduino, and that's all for the the OLED display.
LED: Put a 330 OHM resistor in the cathode side of the LED. Make a wired connection to the LED with Digital Pin 12 on the Arduino, making sure this wire goes into the anode side. Now, your LED is nice and wired
Push Buttons: Start by putting a 10k OHM resistor in each button from the negative rail of the breadboard. After doing so add a power jumper cable from the power rail to the opposite side that you put the resistor. Lastly, in Button 1 (The one on the furthest left), connect the same side that you put the resistor to with Digital Pin #3 on the Arduino, repeat steps for other buttons, and connect Button 2 (Middle) to the Digital Pin #4, and make the last button connected to Digital Pin #6.
Buzzer: For the buzzer add a ground jumper cable from the negative rail of the breadboard to the ground side of the buzzer, next connect a wire coming form Digital Pin #2 to the positive side of the buzzer.
MQ2 Gas Sensor: For the Gas Sensor, add a positive and negative jumper cable from each respective rail of the breadboard, the the positive in VCC and the ground in GND. To finish off put a wire in the A0 pin of the Arduino and connect it to the A0 pin of the MQ2 Gas Sensor.
To conclude make sure your wiring is neat and will connected to reduce risk of wires coming out, and you should be all set to run the code!
Step 2: Upload the Code!
The libraries needed are listed below.
Code is provided below. To explain briefly:
In void setup, we initialize the serial monitor, OLED Display, LED, Buzzer, & Buttons. Then Calibrate the MQ2 Sensor.
In the loop section, we read the button state and display different modes on OLED Display. Then We calculate Smoke and CO from the MQ2 sensor and store those values on ppm and ppm1 variables. Now, Arduino sends these values to the OLED Display for Monitoring. At the same time, It also checks if these values are above the safe level then it sends a command to the buzzer and a LED. IF values are above safe levels then the buzzer starts alarming with a flashing LED.
Attachments
Step 3: How It Works!
The smoke detector has 3 buttons, the furthest left makes the CO appear as the main gas that's being measures, the middle button make Smoke the main gas measured on the OLED, and lastly the button on the very left, turns the alarm on and off. Now to activate the buttons you have to press and hold for 2 seconds, let go and wait 1-2 seconds, and it should change. Above are 2 pictures showing the circuit in 2 modes, CO and smoke, they measure at the same time, but one or the other can be set as the main one.
Step 4: Demonstration
Step 5: Extension!
This is an optional extension that adds a 7 Segment Display, and a Green LED
The display goes from numbers 1-9, depending on the concentration (PPM) of the smoke or CO. This is a fun extension just to show how severe the concentration of CO or Smoke is in your environment, and this adds an extra challenge.
The green LED is an extra indication that there is power going to the carbon monoxide detector, as CO is an invisible gas we need to make sure that is has power and is working. It not working would be worse than being safe.