Luc Paquin
Published © CC BY

Project #15: Environment - Gas Sensor MQ3 - Mk30

Project #15: Environment - Gas Sensor MQ3 - Mk30

BeginnerFull instructions provided1 hour54
Project #15: Environment - Gas Sensor MQ3 - Mk30

Things used in this project

Hardware components

Elecrow Crowduino Uno - SD
×1
Elecrow Crowtail - Base Shield
×1
Elecrow Crowtail - I2C LCD
×1
Elecrow Crowtail - Gas Sensor MQ3
×1
Elecrow Crowtail - LED Matrix 2.0
×1
Elecrow Crowtail - LED(Green)
×1
USB Battery Pack
×1
SparkFun USB Mini-B Cable - 6 Foot
SparkFun USB Mini-B Cable - 6 Foot
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Fritzing

Code

DL2505Mk05p.ino

Arduino
/****** Don Luc Electronics © ******
Software Version Information
Project #15: Environment - Gas Sensor MQ3 - Mk30
DL2505Mk05p.ino
DL2505Mk05
1 x Crowduino Uno - SD
1 x Crowtail - Base Shield
1 x Crowtail - I2C LCD
1 x Crowtail - Gas Sensor MQ3
1 x Crowtail - LED Matrix 2.0
1 x Crowtail - LED(Green)
1 x USB Battery Pack
1 x USB Mini-B Cable
*/

// Include the Library Code
// EEPROM library to read and write EEPROM with unique ID for unit
#include <EEPROM.h>
// Wire
#include <Wire.h>
// Liquid Crystal
#include "LiquidCrystal.h"
// Matrix Adafruit LED Backpack
#include "Adafruit_LEDBackpack.h"

// 8x8 Matrix 
Adafruit_8x8matrix matrix = Adafruit_8x8matrix();
// BMP
static const uint8_t PROGMEM
  smile_bmp[] =
  { B00111100,
    B01000010,
    B10100101,
    B10000001,
    B10100101,
    B10011001,
    B01000010,
    B00111100 },
  neutral_bmp[] =
  { B00111100,
    B01000010,
    B10100101,
    B10000001,
    B10111101,
    B10000001,
    B01000010,
    B00111100 },
  frown_bmp[] =
  { B00111100,
    B01000010,
    B10100101,
    B10000001,
    B10011001,
    B10100101,
    B01000010,
    B00111100 };

// MQ3 Alcohol
int iMQ3Alcohol = A0;
// MQ3 Value
float MQ3Value;
// Sober
#define Sober 120
// Drunk
#define Drunk 400

// Liquid Crystal
// Connect via i2c
LiquidCrystal lcd(0);

// LED Green
int iLEDGreen = 6;

// EEPROM Unique ID Information
String uid = "";

// Software Version Information
String sver = "15-30";

void loop() {

  // MQ3 Alcohol
  // isMQ3
  isMQ3();

  // Display Alcohol
  isDisplayAlcohol();

  // Delay
  delay( 2000 );

}

getDisplay.ino

Arduino
// getDisplay
// Crowbits - OLED 128X64 UID
// Display UID
void isDisplayUID(){

  // Set up the LCD's number of rows and columns: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  // Cursor
  lcd.setCursor(0, 0);
  lcd.print("Don Luc Electron");
  // Cursor
  lcd.setCursor(0, 1);
  // Print a message to the LCD.
  lcd.print( sver );

}
// Display Alcohol
void isDisplayAlcohol(){

  // Clear
  lcd.clear();
  // Set the cursor to column 0, line 0
  lcd.setCursor(0, 0);
  lcd.print( "MQ3 Alcohol" );
  // Set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  lcd.print( MQ3Value );
  
}

getEEPROM.ino

Arduino
// EEPROM
// isUID EEPROM Unique ID
void isUID() {
  
  // Is Unit ID
  uid = "";
  for (int x = 0; x < 7; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }
  
}

getMQ3.ino

Arduino
// MQ3 Alcohol
// isMQ3
void isMQ3(){

  // MQ3 Alcohol
  MQ3Value = digitalRead(iMQ3Alcohol);

  // Determine the status
  if (MQ3Value < Sober) {
    
    // Smile
    matrix.clear();
    matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_ON);
    matrix.writeDisplay();
    
  } else if (MQ3Value >= Sober && MQ3Value < Drunk) {

     // Neutral
     matrix.clear();
     matrix.drawBitmap(0, 0, neutral_bmp, 8, 8, LED_ON);
     matrix.writeDisplay();

    
  } else {

    // DRUNK
    matrix.clear();
    matrix.drawBitmap(0, 0, frown_bmp, 8, 8, LED_ON);
    matrix.writeDisplay();

  }

}

setup.ino

Arduino
// Setup
void setup()
{
 
  // Delay
  delay(100);
  
  // isUID EEPROM Unique ID
  isUID();
  
  // Delay
  delay(100);

  // Initialize the LED Green
  pinMode(iLEDGreen, OUTPUT);
  // LED Green
  digitalWrite(iLEDGreen, HIGH);

  // Delay
  delay(100);

  // 8x8 Matrix 
  matrix.begin(0x70);
  // Smile
  matrix.drawBitmap(0, 0, smile_bmp, 8, 8, LED_ON);
  matrix.writeDisplay();

  // Delay
  delay( 100 );

  // Display UID
  isDisplayUID();
  
  // Delay 5 Second
  delay( 5000 );

}

Credits

Luc Paquin
44 projects • 4 followers
Teacher, Instructor, E-Mentor, R&D and Consulting -Programming Language -Microcontrollers -IoT -Robotics -Machine Learning -AI -Sensors

Comments