You are on page 1of 3

[IOT WORKSHOP][2022-2023]

6.Controlling LEDs based on Smoke Sensor

AIM:
The main objective of this experiment is to read the analogue sensor value and Turn on Buzzer if
analogue sensor value exceeds its threshold value.

APPARATUS REQUIRED:

Name of the Component No of Units


Arduino Uno development board 1
USB cable 1
Buzzer ,LED 1 /2

Resistor (220Ω, 1KΩ) 2


Smoke Sensor(MQ2) 1
Bread board 1
Jumper wires 6

CONNECTION DIAGRAM:

PROCEDURE:
1. Give the connections to the Arduino board as shown in the connection diagram.
2. Open Arduino IDE in the computer
3. Create new file File_-- New

1
[IOT WORKSHOP][2022-2023]

4. Type your program and Save it in appropriate location in your computer.


5. Compile your program by clicking Verify option in the menu.
6. Once the program compiled successfully, connect the Arduino board to the computer using USB
cable.
7. After connecting, go to Tools ---- Board --- Select Arduino/Genuino Uno option
8. After selecting board, go to Tools ---- Port --- Select Arduino Uno COM port 3 (name may
appear differently for other computers).
**Note that this port option will be displayed only when board is connected to
computer
9. Now upload the program to the Arduino board by clicking Upload option.
10. Once the program uploaded successfully, open serial monitor window in Arduino IDE to see
the value of Gas Sensor. When you change the Smoke content of MQ2, observe the buzzer beeps
when Sensor values reaches threshold “300” and according to that LED glove.

PROGRAM:
int redled=3;
int greenled=2;
int buz=4;
int sensor = A0;
int sensThre = 400;
void setup()
{
pinMode(redled, OUTPUT);
pinMode(greenled, OUTPUT);
pinMode(buz, OUTPUT);
pinMode(sensor, INPUT);
5
Serial.begin(9600);
}
void loop()
{
int sensValue=analogRead(sensor);
Serial.println(sensValue);
if (sensValue > 300)
{
digitalWrite(redled, HIGH);
tone(buz,10000,10);
digitalWrite(greenled, LOW);
}
else
{
digitalWrite(greenled, HIGH);
noTone(buz);
digitalWrite(redled, LOW);
}
}

2
[IOT WORKSHOP][2022-2023]

RESULT:

You might also like