Introduction: Anay Shah - Gas Detector - Arduino Tinkercad

This project inherits the idea of a Smoke Alarm we see in our houses. The purpose is to help users to understand the threshold of what their gas sensor can withstand, and ultimately display a message saying if the gas is either detected or not. For when the gas is detected it displays a message as well as a buzzer starts creating sounds.

Supplies

Step 1: Setup

Start by bringing in all of our components for our Gas Sensor. The purpose of this step is very crucial as it makes the process and steps much easier to follow. This also helps because everything is organized and you won't have to look for parts after completing this step.

Bring in the following: 1 Arduino Uno, 2 LED (green and red), 4 Resistors (330Ω), 1 Breadboard, 1 Gas Sensor, 1 LCD Display, and 1 Piezo Buzzer.

Step 2: Creating the Base

Now we start to get hands-on and bring our components into life. Remember right now we will not be getting any results as we will not be coding just yet.

Shall we start?

1) Wire in the 5V and GND pin from the Arduino into our breadboard just like the image.

Purpose: Allows for connectivity and enables the usage of the breadboard

2) Insert the Gas Sensor as shown and connect the A1 pin from the sensor to any Analog IN pin seen on Arduino. Then take the 2 other pins beside the A1 pin called H1 and Terminal 1 and connect to ground power as seen on the image.

Purpose: This allows and enables the usage of the Gas Sensor. The bottom pins connected to the "+" terminal and the top pins connected to the arduino and the "-" terminal also known as GND (ground) allow for the gas sensor to work.

3) Connect the LED's both green and red with their appropriate 330 ohm resistors. Make sure that for both LED's the cathode is conencted with the resistor, and the anode is connected via the wire from the arduino.

Purpose: This is a simple LED connection allowing their to be power for the LED to turn on and off, as well as direct connection with the arduino which allows code to control the LED.

4) Finally connect the positive terminal of the piezo buzzer to the arduino and the negative terminal to the GND port on the breadboard.

Purpose: Another simple connection that allows for the Piezo Buzzer to access power as well as have connectivity with the arduino which allows for code to control the component.

Step 3: Finalize and Setup LCD Display

Now that we have completed Step 2 which helps create the foundation of the circuit, let's make this circuit 10x cooler with the use of an LCD Display. The goal for this is to display a message "Safe" when the gas is not detected or "Not Safe" when the gas is detected.

Shall we start?

1) Start by orienting the LCD display horizontally in the same manner as seen from the image above. Then simply proceed to connect the ground port on the GND port on the Arduino and connect the power port on the bottom "+" terminal rail of the breadboard.

2) Now follow the wiring diagram for the other pins up until the "Register Select" pin on the LCD display. Right after you are done, here comes the crucial part. All pins from pin "Register Select" to "DB7" (excluding the read and write pin) need to be put in chronological order. The code library file "Liquid Crystal" requires this order as a header file and the initialization line can then operate the LCD Display. In the next step "Code" (step 4) the comments on the code will further explain the "LiquidCrystal" library.

3) As for all the other pins that are not connected, simply follow the wiring diagram and plugin accordingly. Also, the 4th resistor will be used in this step for when you handle with pin "LED anode" as this can just be seen as another simple led connection with a mandatory resistor attachment.

Step 4: Code

Explanation:

This is the TinkerCad code for the Gas Detector circuit. It simply uses the "SensorState" variable to determine the positioning of the gas and determines if the buzzer will stay on or off depending on the set threshold. The Serial Monitor can be turned on which shows the positioning of the gas, and when the gas position is greater than 60, the buzzer will turn on as well as the displaying an " Exit Now " and " Not Good :( " message on the LCD display.

Comments and Liquid Crystal Library:

Every orange text seen on the code is shown as a comment which helps the user of the circuit have a brief of what each line of code does.

Moving on, let's talk about the Liquid Crystal Library. This is a library that allows for the Arduino and LCD Display connection and functionality to work together. The pins also need to be initialized in the same order as the circuit itself. The line of code shows us this: LiquidCrystal lcd(6,7,8,9,10,11);. The first set of comments, also shows what the pin is on the LCD Display itself.

Further Explanation:

1) The Gas Sensor uses an Analog In pin. This is then read using the "AnalogRead(pin) function which converts the value of the voltage on an analog input pin and returns a digital value from 0 to 1023.

2) All other components such as the LED's and Buzzer use a simple digital pin that enables and allows for the components to work.

Downloadable File:

Seen below is the INO file for the Gas Detector I have created.

Step 5: Circuit in Action

Here is a short little video showing the circuit in action. The buzzer might make some noise so make sure audio isn't on max as it can be disturbing like the real smoke alarms at our homes.