You are on page 1of 5

Experiment 2.

Student Name: Amit Sharma UID:21MCA3077

Branch: MCA Section/Group:21MCA/

Semester: 4th Date :04-03-2023

Subject Name: Embedded Programming Lab Subject Code:21CAH752

1) Task to be done:

Design the circuit and write a program to interface Gas Sensor (MQ2)
with Arduino Uno and used as gas leakage detector.

2) Steps for experiment/practical & Output:


Components Used:
• LED’s
• Resistor
• Arduino Uno R3
• Breadboard
• Gas Sensor
• Buzzer
Code:
// C++ code

int redled=3;
int greenled=2;
int buzzer=4;
int sensor= A0;
int sensorThresh=400;

void setup()
{
pinMode(redled,OUTPUT);
pinMode(greenled,OUTPUT);
pinMode(buzzer,OUTPUT);
pinMode(sensor,INPUT);
Serial.begin(9600);
lcd.begin(16,2);
}
void loop()
{
int analogValue= analogRead(sensor);
Serial.print(analogValue);
if(analogValue>sensorThresh)
{

digitalWrite(redled,HIGH);
digitalWrite(greenled,LOW);
tone(buzzer,1000,10000);
delay(1000);
delay(1000);
}
else
{
digitalWrite(greenled,HIGH);
digitalWrite(redled,LOW);
noTone(buzzer);
delay(1000);
delay(1000);
}
}
Output:
Before Simulation

After Simulation
Learning Outcomes (What I have learnt):

 How to design circuit with breadboard and Ardiono Uno.


 How to use Buzzer and Gas sensor
 Learned how to use 4 resistors with different values and connect it with ground.
 Learned how Buzzer works when gas sensor detects smoke and create noise and
red led blinks

Evaluation Grid:
Sr. No. Parameters Marks Obtained Maximum Marks
1. Demonstration and Performance 5
2. Worksheet 10
3. Post Lab Quiz 5

You might also like