Smoke or Gas Detector With CloudX M633
by DwealthJossy in Circuits > Microcontrollers
833 Views, 0 Favorites, 0 Comments
Smoke or Gas Detector With CloudX M633

In this project, we check for smoke or gas leakage with a smoke detector and control the state of a buzzer, a RED Led, with GREEN Led with respect to the sensor's Output.
MQ2 Smoke Detector

How Does the Smoke Alarm Work?
The MQ-2 smoke sensor will give the output in the form of analog/ Digital voltage.we are going to use digital in this project,We have set a condition in our code that if the sensor detect high, then the buzzer will start to beep and the red LED will light up; and if the sensor detect low , then the buzzer will remain quiet and the green LED will light up.
COMPONENTS:









- CloudX M633
- CloudX SoftCard
- V3 Cable
- Smoke Sensor (MQ2)
- BreadBoard
- Buzzer
- RedLed
- GreenLed
- Jumper Wire
- 330 ohm resistor
HARDWARE

Connect the MQ-2 gas sensor with the CloudX M633. Connect the VCC and the GND on the gas sensor to the 5V and GND pins on the CloudX M633. Then connect the D0 pin on the MQ-2 gas sensor to the pin1 on the CloudX M633.
if you are using Analog pin, connect the MQ-2 gas sensor with the CloudX M633. Connect the VCC and the GND on the gas sensor to the 5V and GND pins on the CloudX M633. Then connect the A0 pin on the MQ-2 gas sensor to the A0 on the CloudX M633.
After that, connect the Buzzer and the LEDs to the CloudX M633.
Connect the positive on the buzzer with pin2 on the CloudX M633 and the negative on the buzzer with GND on the CloudX M633. Then connect the negative side of the LEDs to the GND through the 330-ohm resistor and the positive side of the RED led to pin3 and the positive side of the GREEN led to pin4 on the CloudX M633.
Coding
For Digital Pin:
#include<CloudX/M633.h><br>
#define DO 1 #define Buzzer 2 #define RedLED 3 #define GreenLED 4
setup(){ //setup here pinMode(DO, INPUT); pinMode(Buzzer, OUTPUT); pinMode(RedLED, OUTPUT); pinMode(GreenLED, OUTPUT);
loop(){
if (readPin(DO)) { digitalWrite(Buzzer, HIGH); digitalWrite(RedLED, HIGH); digitalWrite(GreenLED, LOW); } else { digitalWrite(Buzzer, LOW); digitalWrite(RedLED, LOW); digitalWrite(GreenLED, HIGH); }
} }
For Analog Pin:
#include<CloudX/M633.h><br>#include<CloudX/Adc.h>
#define DO 1 #define Buzzer 2 #define RedLED 3 #define GreenLED 4
int AOValue;
setup(){ //setup here pinMode(DO, INPUT); pinMode(Buzzer, OUTPUT); pinMode(RedLED, OUTPUT); pinMode(GreenLED, OUTPUT); analogSetting();
loop(){
AOValue = analogRead(A0);
if (AOValue >= 300 ) { digitalWrite(Buzzer, HIGH); digitalWrite(RedLED, HIGH); digitalWrite(YellowLED, LOW); digitalWrite(GreenLED, LOW); }
else if (AOValue >= 135 && AOValue < 300 ){ digitalWrite(Buzzer, HIGH); digitalWrite(RedLED, LOW); digitalWrite(YellowLED, HIGH); digitalWrite(GreenLED, LOW); delayMs(100); digitalWrite(Buzzer, LOW); }
else if (AOValue < 135 ) { digitalWrite(Buzzer, LOW); digitalWrite(RedLED, LOW); digitalWrite(YellowLED, LOW); digitalWrite(GreenLED, HIGH); }
} }