Devices & Components
Arduino Uno Rev3
5 mm LED: Red
HC-05 Bluetooth Module
Buzzer
5 mm LED: Green
Resistor 1k ohm
Resistor 221 ohm
IR receiver (generic)
Breadboard (generic)
Jumper wires (generic)
Resistor 10k ohm
Grove - Gas Sensor(MQ2)
Software & Tools
Arduino IDE
MIT App Inventor 2
Project description
Code
The Code
arduino
1#define flamePin A0 2#define gasPin A1 3#define buzzer1 10 4#define 5 buzzer2 9 6#define greenLed 2 7#define redLed 3 8int flameVal; 9int gasVal; 10int 11 btSwitch=49; 12unsigned long curTime; 13void(* resetFunc) (void) = 0; 14 15void 16 setup() { 17 // put your setup code here, to run once: 18 Serial.begin(9600); 19 20 pinMode(buzzer1, OUTPUT); 21 pinMode(buzzer2, OUTPUT); 22 pinMode(greenLed, 23 OUTPUT); 24 pinMode(redLed, OUTPUT); 25 curTime=millis(); 26} 27 28void loop() 29 { 30 // put your main code here, to run repeatedly: 31 if(Serial.available() 32 > 0){ // Checks whether data is comming from the serial port 33 btSwitch = 34 Serial.read(); // Reads the data from the serial port 35 } 36 if(btSwitch=='1'){digitalWrite(greenLed,HIGH);digitalWrite(redLed,LOW);} 37 38 else if(btSwitch=='0'){digitalWrite(redLed,HIGH);digitalWrite(greenLed,LOW);} 39 40 else if(btSwitch=='2'){resetFunc();} 41 42 flameVal=analogRead(flamePin); 43 44 gasVal=analogRead(gasPin); 45 46 if (flameVal<1000 && gasVal>159 && btSwitch=='1'){ 47 48 buzzerCall(); 49 } 50 else if(gasVal>159 && btSwitch=='1'){ 51 buzzerCall(); 52 53 } 54} 55 56void buzzerCall(){ 57 digitalWrite(greenLed,LOW); 58 digitalWrite(redLed,HIGH); 59 60 tone(buzzer1, 5000); 61 delay(1000); 62 noTone(buzzer1); 63 tone(buzzer2, 64 1000); 65 digitalWrite(redLed,LOW); 66 delay(1000); 67 noTone(buzzer2); 68 69 } 70
The Code
arduino
1#define flamePin A0 2#define gasPin A1 3#define buzzer1 10 4#define buzzer2 9 5#define greenLed 2 6#define redLed 3 7int flameVal; 8int gasVal; 9int btSwitch=49; 10unsigned long curTime; 11void(* resetFunc) (void) = 0; 12 13void setup() { 14 // put your setup code here, to run once: 15 Serial.begin(9600); 16 pinMode(buzzer1, OUTPUT); 17 pinMode(buzzer2, OUTPUT); 18 pinMode(greenLed, OUTPUT); 19 pinMode(redLed, OUTPUT); 20 curTime=millis(); 21} 22 23void loop() { 24 // put your main code here, to run repeatedly: 25 if(Serial.available() > 0){ // Checks whether data is comming from the serial port 26 btSwitch = Serial.read(); // Reads the data from the serial port 27 } 28 if(btSwitch=='1'){digitalWrite(greenLed,HIGH);digitalWrite(redLed,LOW);} 29 else if(btSwitch=='0'){digitalWrite(redLed,HIGH);digitalWrite(greenLed,LOW);} 30 else if(btSwitch=='2'){resetFunc();} 31 32 flameVal=analogRead(flamePin); 33 gasVal=analogRead(gasPin); 34 35 if (flameVal<1000 && gasVal>159 && btSwitch=='1'){ 36 buzzerCall(); 37 } 38 else if(gasVal>159 && btSwitch=='1'){ 39 buzzerCall(); 40 } 41} 42 43void buzzerCall(){ 44 digitalWrite(greenLed,LOW); 45 digitalWrite(redLed,HIGH); 46 tone(buzzer1, 5000); 47 delay(1000); 48 noTone(buzzer1); 49 tone(buzzer2, 1000); 50 digitalWrite(redLed,LOW); 51 delay(1000); 52 noTone(buzzer2); 53 } 54
Downloadable files
The Circuit
I couldn't find a MQ 2 fritzing diagram so i used a MQ 9 instead which has a similar pin out. Don't forget to disconnect the Rx and TX pins from the Bluetooth module before uploading your code else you will have issues uploading your code
The Circuit

Documentation
The apk
The apk
The apk
The apk
Comments
Only logged in users can leave comments