• MQ-4 Gas Sensor Arduino Nano v3

    sensor gas Displayed on 4 Digit 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

    Schema

    MQ-4 Gas Sensor

    Code


    int aPin = 2;
    int bPin = 3;
    int cPin = 4;
    int dPin = 5;
    int ePin = 12;
    int fPin = 7;
    int gPin = 8;
    int GND1 = 6;
    int GND2 = 11;
    int GND3 = 10;
    int GND4 = 9;
    int j;
    int num;
    int dig1 = 0;
    int dig2 = 0;
    int dig3 = 0;
    int dig4 = 0;
    int DTime = 4;
    int sensorP = A7;
    void setup()
    {
    pinMode(aPin, OUTPUT);
    pinMode(bPin, OUTPUT);
    pinMode(cPin, OUTPUT);
    pinMode(dPin, OUTPUT);
    pinMode(ePin, OUTPUT);
    pinMode(fPin, OUTPUT);
    pinMode(gPin, OUTPUT);
    pinMode(GND1, OUTPUT);
    pinMode(GND2, OUTPUT);
    pinMode(GND3, OUTPUT);
    pinMode(GND4, OUTPUT);
    }
    void loop()
    {



    num = analogRead(sensorP);
    j = num;
    dig1 = num / 1000;
    num = num - (dig1 * 1000);
    dig2 = num / 100;
    num = num - (dig2 * 100);
    dig3 = num / 10;
    dig4 = num - (dig3 * 10);


    for (int i = 1; i <= 5; i++)
    {

    if (j >= 1000)
    {
    digitalWrite( GND4, HIGH); //digit 4
    pickNumber(dig4);
    delay(DTime);
    digitalWrite( GND4, LOW);

    digitalWrite( GND3, HIGH); //digit 3
    pickNumber(dig3);
    delay(DTime);
    digitalWrite( GND3, LOW);

    digitalWrite( GND2, HIGH); //digit 2
    pickNumber(dig2);
    delay(DTime);
    digitalWrite( GND2, LOW);

    digitalWrite( GND1, HIGH); //digit 1
    pickNumber(dig1);
    delay(DTime);
    digitalWrite( GND1, LOW);
    }
    else if (j >= 100)
    {
    digitalWrite( GND4, HIGH); //digit 4
    pickNumber(dig4);
    delay(DTime);
    digitalWrite( GND4, LOW);

    digitalWrite( GND3, HIGH); //digit 3
    pickNumber(dig3);
    delay(DTime);
    digitalWrite( GND3, LOW);

    digitalWrite( GND2, HIGH); //digit 2
    pickNumber(dig2);
    delay(DTime);
    digitalWrite( GND2, LOW);

    digitalWrite( GND1, LOW); //digit 1
    pickNumber(dig1);
    delay(DTime);
    digitalWrite( GND1, LOW);
    }
    else if (j >= 10)
    {
    digitalWrite( GND4, HIGH); //digit 4
    pickNumber(dig4);
    delay(DTime);
    digitalWrite( GND4, LOW);

    digitalWrite( GND3, HIGH); //digit 3
    pickNumber(dig3);
    delay(DTime);
    digitalWrite( GND3, LOW);

    digitalWrite( GND2, LOW); //digit 2
    pickNumber(dig2);
    delay(DTime);
    digitalWrite( GND2, LOW);

    digitalWrite( GND1, LOW); //digit 1
    pickNumber(dig1);
    delay(DTime);
    digitalWrite( GND1, LOW);
    }

    else if (j >= 0)
    {
    digitalWrite( GND4, HIGH); //digit 4
    pickNumber(dig4);
    delay(DTime);
    digitalWrite( GND4, LOW);

    digitalWrite( GND3, LOW); //digit 3
    pickNumber(dig3);
    delay(DTime);
    digitalWrite( GND3, LOW);

    digitalWrite( GND2, LOW); //digit 2
    pickNumber(dig2);
    delay(DTime);
    digitalWrite( GND2, LOW);

    digitalWrite( GND1, LOW); //digit 1
    pickNumber(dig1);
    delay(DTime);
    digitalWrite( GND1, LOW);
    }
    }
    }
    void pickNumber(int x) {
    switch (x) {
    case 0: zero(); break;
    case 1: one(); break;
    case 2: two(); break;
    case 3: three(); break;
    case 4: four(); break;
    case 5: five(); break;
    case 6: six(); break;
    case 7: seven(); break;
    case 8: eight(); break;
    case 9: nine(); break;
    }
    }



    void zero()
    {
    digitalWrite( aPin, LOW);
    digitalWrite( bPin, LOW);
    digitalWrite( cPin, LOW);
    digitalWrite( dPin, LOW);
    digitalWrite( ePin, LOW);
    digitalWrite( fPin, LOW);
    digitalWrite( gPin, HIGH);
    }

    void one()
    {
    digitalWrite( aPin, HIGH);
    digitalWrite( bPin, LOW);
    digitalWrite( cPin, LOW);
    digitalWrite( dPin, HIGH);
    digitalWrite( ePin, HIGH);
    digitalWrite( fPin, HIGH);
    digitalWrite( gPin, HIGH);
    }

    void two()
    {
    digitalWrite( aPin, LOW);
    digitalWrite( bPin, LOW);
    digitalWrite( cPin, HIGH);
    digitalWrite( dPin, LOW);
    digitalWrite( ePin, LOW);
    digitalWrite( fPin, HIGH);
    digitalWrite( gPin, LOW);
    }

    void three()
    {
    digitalWrite( aPin, LOW);
    digitalWrite( bPin, LOW);
    digitalWrite( cPin, LOW);
    digitalWrite( dPin, LOW);
    digitalWrite( ePin, HIGH);
    digitalWrite( fPin, HIGH);
    digitalWrite( gPin, LOW);
    }

    void four()
    {
    digitalWrite( aPin, HIGH);
    digitalWrite( bPin, LOW);
    digitalWrite( cPin, LOW);
    digitalWrite( dPin, HIGH);
    digitalWrite( ePin, HIGH);
    digitalWrite( fPin, LOW);
    digitalWrite( gPin, LOW);
    }

    void five()
    {
    digitalWrite( aPin, LOW);
    digitalWrite( bPin, HIGH);
    digitalWrite( cPin, LOW);
    digitalWrite( dPin, LOW);
    digitalWrite( ePin, HIGH);
    digitalWrite( fPin, LOW);
    digitalWrite( gPin, LOW);
    }

    void six()
    {
    digitalWrite( aPin, LOW);
    digitalWrite( bPin, HIGH);
    digitalWrite( cPin, LOW);
    digitalWrite( dPin, LOW);
    digitalWrite( ePin, LOW);
    digitalWrite( fPin, LOW);
    digitalWrite( gPin, LOW);
    }

    void seven()
    {
    digitalWrite( aPin, LOW);
    digitalWrite( bPin, LOW);
    digitalWrite( cPin, LOW);
    digitalWrite( dPin, HIGH);
    digitalWrite( ePin, HIGH);
    digitalWrite( fPin, HIGH);
    digitalWrite( gPin, HIGH);
    }

    void eight()
    {
    digitalWrite( aPin, LOW);
    digitalWrite( bPin, LOW);
    digitalWrite( cPin, LOW);
    digitalWrite( dPin, LOW);
    digitalWrite( ePin, LOW);
    digitalWrite( fPin, LOW);
    digitalWrite( gPin, LOW);
    }

    void nine()
    {
    digitalWrite( aPin, LOW);
    digitalWrite( bPin, LOW);
    digitalWrite( cPin, LOW);
    digitalWrite( dPin, LOW);
    digitalWrite( ePin, HIGH);
    digitalWrite( fPin, LOW);
    digitalWrite( gPin, LOW);
    }
    « iptv gratuit 2016
    Partager via Gmail Delicious Technorati Yahoo! Google Bookmarks Blogmarks Pin It

  • Comments

    No comments yet

    Suivre le flux RSS des commentaires


    Add comment

    Name / User name:

    E-mail (optional):

    Website (optional):

    Comment: