The Alpha Geek – Geeking Out

Project #6: MicroView – Alcohol Gas Sensor – Mk09

Alcohol Gas Sensor – MQ-3

This alcohol sensor is suitable for detecting alcohol concentration on your breath, just like your common breathalyzer. It has a high sensitivity and fast response time. Sensor provides an analog resistive output based on alcohol concentration. The drive circuit is very simple, all it needs is one resistor. A simple interface could be a 0-3.3V ADC.

Features

* 5V DC or AC circuit
* Requires heater voltage
* Operation Temperature: -10 to 70 degrees C
* Heater consumption: less than 750mW* 16.8mm diameter
* 9.3 mm height without the pins

Note: Again, the MQ-3 is heater-driven so be aware that the sensor will become warm and may even emit a smell at first. This is completely normal.

Calibration: If you take your time, you can find out what values equate to specific percentages or even blood alcohol concentration in the case of a breathalyzer. You will of course need to calibrate your MQ-3 based on your specific Arduino code since sensor readings will vary. Do not get the sensor wet with alcohol! Simply squeeze to breathe the vapors of the alcohol into the sensor and take your readings.

Alcohol Gas Sensor – MQ-3

1 x MicroView
1 x MicroView – USB Programmer
1 x Alcohol Gas Sensor – MQ-3
1 x NeoPixel Stick – 8 x 5050 RGB LED
1 x LED Green
1 x 10k Ohm
1 x 100k Ohm Potentiometer
1 x Potentiometer Knob
1 x 4 Header
2 x 2 Header
14 x Jumper Wires 3″ M/M
1 x Half-Size Breadboard
1 x Battery Holder 3xAAA with Cover and Switch
3 x Battery AAA

MicroView

Pot – PIN 05 – Analog A2
MQ-3 – PIN 07 – Analog A0
GND – PIN 08 – GND
VIN – PIN 15 – +5V
NEO – PIN 12 – Digital 3
LEDG – PIN 11 – Digital 2

DonLuc1807Mk01

DonLuc1807Mk01.ino

// ***** Don Luc *****
// Software Version Information
// Project #6: MicroView - Alcohol Gas Sensor - MQ-3 - Mk09
// 7.1
// DonLuc1807Mk01 7-1
// MicroView
// Alcohol Gas Sensor - MQ-3

// include the library code:
#include <MicroView.h>
#include <Adafruit_NeoPixel.h>

// Alcohol Gas Sensor - MQ-3
int mq3Pin0 = A0;                         // Connected to the output pin of MQ3 
int mq3Value = 0;

// NeoPixels
#define PIN 3                             // On digital pin 3
#define NUMPIXELS 8                       // NeoPixels NUMPIXELS = 8
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int red = 0;                              // Red
int green = 0;                            // Green
int blue = 0;                             // Blue
int iNeo = 0;                             // Neopix
const int iBriPin = A2;                   // Panel Mount 1K potentiometer Brightneed
int iBri = 0;                             // Neopix Brightness
int iBriMin = 1023;                       // Brightneed minimum sensor value
int iBriMax = 0;                          // Brightneed maximum sensor value

// LED
int ledG = 1;                             // LED Green

void loop() {
  
  // Alcohol Gas Sensor - MQ-3
  // Give ample warmup time for readings to stabilize
  isMQ3();

  delay(100);
  
  uView.clear(PAGE);  // Erase the memory buffer, the OLED will be cleared
  
}

getMQ3.ino

// Alcohol Gas Sensor - MQ-3
void isMQ3(){

  // LEDs - Low
  for(int z=0; z<NUMPIXELS; z++){ 
     // Black
     red = 0;                                 // Red
     green = 0;                               // Green
     blue = 0;                                // Blue
     iNeo = z;                                // Neopix       
     neopix(); 
  }
    
  // Probe
  mq3Value = analogRead(mq3Pin0);              // Take a reading from the probe
  
  if( mq3Value >= 1 ){                         // If the reading isn't zero, proceed
    
    if (mq3Value > 1){                         // If the average is over 50 ...
      // Green
      red = 0;                                 // Red
      green = 255;                             // Green
      blue = 0;                                // Blue
      iNeo = 0;                                // Neopix       
      neopix();      
    }
    else{                                      // and if it's not ...
      // Black
      red = 0;                                 // Red
      green = 0;                               // Green
      blue = 0;                                // Blue
      iNeo = 0;                                // Neopix        
      neopix();      
    }

    if (mq3Value > 250){                        // and so on ...
      // Green
      red = 0;                                 // Red
      green = 255;                             // Green
      blue = 0;                                // Blue
      iNeo = 1;                                // Neopix       
      neopix();
    }
    else{
      // Black
      red = 0;                                 // Red
      green = 0;                               // Green
      blue = 0;                                // Blue
      iNeo = 1;                                // Neopix        
      neopix(); 
    }

    if (mq3Value > 350){
      // Green
      red = 0;                                 // Red
      green = 255;                             // Green
      blue = 0;                                // Blue
      iNeo = 2;                                // Neopix       
      neopix();
    }
    else{
      // Black
      red = 0;                                 // Red
      green = 0;                               // Green
      blue = 0;                                // Blue
      iNeo = 1;                                // Neopix        
      neopix(); 
    }


    if (mq3Value > 500){
      // Yellow
      red = 255;                               // Red
      green = 255;                             // Green
      blue = 0;                                // Blue
      iNeo = 3;                                // Neopix
      neopix();
    }
    else{
      // Black
      red = 0;                                 // Red
      green = 0;                               // Green
      blue = 0;                                // Blue
      iNeo = 3;                                // Neopix       
      neopix(); 
    }

    if (mq3Value > 650){
      // Yellow
      red = 255;                               // Red
      green = 255;                             // Green
      blue = 0;                                // Blue
      iNeo = 4;                                // Neopix      
      neopix();
    }
    else{
      // Black
      red = 0;                                 // Red
      green = 0;                               // Green
      blue = 0;                                // Blue
      iNeo = 4;                                // Neopix        
      neopix(); 
    }

    if (mq3Value > 750){
      // Yellow
      red = 255;                               // Red
      green = 255;                             // Green
      blue = 0;                                // Blue
      iNeo = 5;                                // Neopix  
      neopix();
    }
    else{
      // Black
      red = 0;                                 // Red
      green = 0;                               // Green
      blue = 0;                                // Blue
      iNeo = 5;                                // Neopix        
      neopix(); 
    }

    if (mq3Value > 850){
      // Red
      red = 255;                               // Red
      green = 0;                               // Green
      blue = 0;                                // Blue
      iNeo = 6;                                // Neopix       
      neopix();
    }
    else{
      // Black
      red = 0;                                 // Red
      green = 0;                               // Green
      blue = 0;                                // Blue
      iNeo = 6;                                // Neopix       
      neopix();
    }

    if (mq3Value > 950){
      // Red
      red = 255;                               // Red
      green = 0;                               // Green
      blue = 0;                                // Blue
      iNeo = 7;                                // Neopix      
      neopix();
    }
    else{
      // Black
      red = 0;                                 // Red
      green = 0;                               // Green
      blue = 0;                                // Blue
      iNeo = 7;                                // Neopix        
      neopix();
    }

  }
  
  uView.setFontType(0);  // Set font type 0: Numbers and letters. 10 characters per line (6 lines)

  uView.setCursor(0,10); // Alcohol Gas Sensor
  uView.print( "Alcohol" );
  uView.setCursor(0,30); // Alcohol Gas Sensor
  uView.print( mq3Value ); 
        
  uView.display();       // Display
   
}

neopix.ino

// Neopix
void neopix() { 

    // Brightness
    iBri = analogRead(iBriPin);

    // iBri apply the calibration to the sensor reading
    iBri = map(iBri, iBriMin, iBriMax, 0, 255);

    // iBri in case the sensor value is outside the range seen during calibration
    iBri = constrain(iBri, 0, 255);  
    
    pixels.setBrightness( iBri );
    // Pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor( iNeo, pixels.Color(red,green,blue) ); 
    // This sends the updated pixel color to the hardware
    pixels.show(); 
    // Delay for a period of time (in milliseconds)
    delay(50);     
  
}

setup.ino

// Setup
void setup() {

  uView.begin();           // Begin of MicroView
  uView.clear(ALL);        // Erase hardware memory inside the OLED controller
  uView.display();         // Display the content in the buffer memory, by default it is the MicroView logo
  
  delay(1000);
  
  uView.clear(PAGE);       // Erase the memory buffer, the OLED will be cleared.
   
  uView.setFontType(1);    // Set font type 1: Numbers and letters. 7 characters per line (3 lines)
  uView.setCursor(0,20);
  uView.print("Don Luc");  // Don Luc
  uView.display();         // Display
  
  delay(5000);

  uView.clear(PAGE);       // Erase the memory buffer, the OLED will be cleared.

  uView.setFontType(1);    // Set font type 1: Numbers and letters. 7 characters per line (3 lines)
  uView.setCursor(0,20);
  uView.print("MQ-3");     // Alcohol Gas Sensor - MQ-3
  uView.display();         // Display 
  
  delay(5000);
  
  uView.clear(PAGE);       // Erase the memory buffer, the OLED will be cleared

  // NeoPixels
  pixels.begin();          // This initializes the NeoPixel library

  // LED
  pinMode( ledG, OUTPUT ); // LED Green 
  // LED Green - High 
  digitalWrite( ledG, HIGH);
       
}

Don Luc

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories
Archives