sensor gas Displayed on 7 segment
The MQ-4 gas sensor modules are used in gas leakage detecting equipments, they are suitable for the detection of CH4,Natural gas.LNG, avoid alcohol and cooking fumes and cigarette smoke with this sensor.
- High sensitivity to CH4 and Natural gas
- Slight sensitivity to alcohol, smoke
- Fast response
- Stable and long life
- Simple drive circuit
- VCC - 5V
- GND - GND
- A0 - Analog pin7
- D0 - LED
download |
Geekcreit® ATmega328P Nano V3 Controller Board Compatible Arduino Improved Version
Gas Sensor Module For Arduino |
Code
int sensorValue; int num; void setup() { pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); pinMode(8, OUTPUT); Serial.begin(9600); } void loop() { sensorValue = analogRead(7); if (sensorValue < 300) { digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW); digitalWrite(8, LOW); digitalWrite(2, LOW); digitalWrite(3, HIGH); delay(200); digitalWrite(3, LOW); digitalWrite(4, HIGH); delay(200); digitalWrite(4, LOW); digitalWrite(5, HIGH); delay(200); digitalWrite(5, LOW); digitalWrite(6, HIGH); delay(200); digitalWrite(6, LOW); digitalWrite(7, HIGH); delay(200); digitalWrite(7, LOW); digitalWrite(2, HIGH); delay(200); } else { if (sensorValue >= 750) {num = 9;} else if (sensorValue >= 700) {num = 8;} else if (sensorValue >= 650) {num = 7;} else if (sensorValue >= 600) {num = 6;} else if (sensorValue >= 550) {num = 5;} else if (sensorValue >= 500) {num = 4;} else if (sensorValue >= 450) {num = 3;} else if (sensorValue >= 400) {num = 2;} else if (sensorValue >= 350) {num = 1;} else if (sensorValue >= 300) {num = 0;} } switch (num) { case 9: digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, HIGH); digitalWrite(5, HIGH); digitalWrite(6, LOW); digitalWrite(7, HIGH); digitalWrite(8, HIGH); break; case 8: digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, HIGH); digitalWrite(5, HIGH); digitalWrite(6, HIGH); digitalWrite(7, HIGH); digitalWrite(8, HIGH); break; case 7: digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, HIGH); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW); digitalWrite(8, LOW); break; case 6: digitalWrite(2, HIGH); digitalWrite(3, LOW); digitalWrite(4, HIGH); digitalWrite(5, HIGH); digitalWrite(6, HIGH); digitalWrite(7, HIGH); digitalWrite(8, HIGH); break; case 5: digitalWrite(2, HIGH); digitalWrite(3, LOW); digitalWrite(4, HIGH); digitalWrite(5, HIGH); digitalWrite(6, LOW); digitalWrite(7, HIGH); digitalWrite(8, HIGH); break; case 4: digitalWrite(2, LOW); digitalWrite(3, HIGH); digitalWrite(4, HIGH); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, HIGH); digitalWrite(8, HIGH); break; case 3: digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, HIGH); digitalWrite(5, HIGH); digitalWrite(6, LOW); digitalWrite(7, LOW); digitalWrite(8, HIGH); break; case 2: digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, LOW); digitalWrite(5, HIGH); digitalWrite(6, HIGH); digitalWrite(7, LOW); digitalWrite(8, HIGH); break; case 1: digitalWrite(2, LOW); digitalWrite(3, HIGH); digitalWrite(4, HIGH); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW); digitalWrite(8, LOW); break; case 0: digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, HIGH); digitalWrite(5, HIGH); digitalWrite(6, HIGH); digitalWrite(7, HIGH); digitalWrite(8, LOW); break; } }
No comments:
Post a Comment