AlcoTest

We are constantly expanding our range for our customers and so we have again received samples for our online shop from the manufacturer. (Trial delivery) This time with it, an MQ-03 sensor module. The sensors MQ-02  and MQ-135  we have already included in our delivery program. What is special about the MQ-03: this module is calibrated to detect alcohol in the air. We took this as an opportunity to open a breath tester for you today Arduino-Based base we dug up in a forum. With gas sensors it should be noted that they require a lot of electricity and require a certain preheating time.

We use:
1x Nano V3
1x Mini breadboard
1x MB102
1x LCD12864
Jumper cable

Optionally, predefined LEDs are stored in the code to display the result, which we do not use in our application example.

The pins of all modules are labeled. (Display on the back)

Nano V3 MQ-03 Display MB-102
GND GND GND GND
5V VCC VCC + 5V
A0 A0
D3 RS
D4 R / W
D5 E
D6 RST
3.3V BLA
BLK GND

 

Required libraries: u8glib from the library manager

Code:

 

#include "U8glib.h"

U8GLIB_ST7920_128X64_1X u8g(5, 4, 3 , 6);

#define qtdLED 6

int LEDs[qtdLED];
int count;
int value_sensor = 0;
unsigned long time;
int maxTime = 300;
int status = 1;
String state;
int position 1;
int i;
int j;
int maximum reading;

void draw() {   u8g.setFont(u8g_font_8x13B);   u8g.drawRFrame(0, 20, 128, 44, 4);   u8g.drawStr( 30, 10, "AlcoTester");   u8g.setFont(u8g_font_robot_de_niro);   u8g.drawStr( 8, 20, "Don't drink and drive");   u8g.setFont(u8g_font_8x13B);   u8g.drawStr( 10, 37, "Wait");   if (status == 1) {     u8g.drawBox(80, 25, 20, 30);     u8g.drawHLine(77, 24, 26);     u8g.drawRFrame(78, 25 , 24, 32, 0);     u8g.drawRFrame(77, 25 , 26, 32, 0);     u8g.drawHLine(76, 57, 28);     u8g.drawHLine(76, 58, 28);     u8g.drawRFrame(102, 30 , 7, 20, 2);     u8g.drawRFrame(102, 28 , 9, 24, 2);     u8g.setColorIndex(0);     if (time == 0) {       time = 1;     }     u8g.drawBox(79, 25, 22, time);     u8g.setColorIndex(1);   }   if (status == 0) {     u8g.setFont(u8g_font_fub20);     u8g.setColorIndex(0);     u8g.drawBox(10, 25, 110, 33);     u8g.setColorIndex(1);     if (value_sensor <= 99) {       position 1 = 50;     }     else {       position 1 = 43;     }     u8g.setPrintPos(position 1, 45);     u8g.print(value_sensor);     u8g.setFont(u8g_font_orgv01);     int size = state.length();     int position = (128 / 2) - ((size * 5) / 2);     u8g.setPrintPos(position, 60);     u8g.print(state);   }
}

void set up(void) {      Serial.begin(9600);   pinMode(A0, INPUT);   if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {     u8g.setColorIndex(255);   }   else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {     u8g.setColorIndex(3);   }   else if ( u8g.getMode() == U8G_MODE_BW ) {     u8g.setColorIndex(1);   }   else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {     u8g.setHiColorByRGB(255, 255, 255);   }   i = 0;   j = 7;   while (i < qtdLED) {     LEDs[i] = j;     i++;     j++;   }   for (i = 0; i < qtdLED; i++)   {     pinMode(LEDs[i], OUTPUT);   }   digitalWrite(2, OUTPUT);
}

void loop(void) {      value_sensor = analogRead(A0);   time = millis() / 1000;   u8g.firstPage();   if (time <= maxTime) {     time = map(time, 0, maxTime, 0, 30);     status = 1;   }   else {     status = 0;   }   if (value_sensor >= 0 and value_sensor <= 100) {     state = "no input recognized";   }   else if (value_sensor >= 101 and value_sensor <= 200) {     state = "was probably only apple juice";   }   else if (value_sensor >= 201 and value_sensor <= 300) {     state = "Sure it was just a beer?";   }   else if (value_sensor >= 301 and value_sensor <= 400) {     state = "I guess there was schnapps!";   }   else if (value_sensor >= 401 and value_sensor <= 550) {     state = "Even too much in Bavaria!";   }   else if (value_sensor >= 551) {     state = "Um ... ambulance?";   }   do {     draw();   }   while (u8g.nextPage() );   delay(50);         int sensor = analogRead(A0);   if (sensor >= 40) {     digitalWrite(2, HIGH);     maximum reading = 0;     for (count = 0; count <= 500; count++) {       int sensor = analogRead(A0);       delay(1);       if (sensor > maximum reading) {         maximum reading = sensor;       }     }     digitalWrite(2, LOW);     int level = map(maximumReading, 0, 551, 0, qtdLED);     for (i = 0; i < qtdLED; i++) {       if (i < level) {         digitalWrite(LEDs[i], HIGH);         delay(100);       } else {         digitalWrite(LEDs[i], LOW);       }     }     delay(500);     for (i = 0; i < qtdLED; i++) {       digitalWrite(LEDs[i], LOW);     }   }
}

 

For arduinoSpecials

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN