hi to everyone, it's the first time that i start a new topic (i'm not english so i'm sorry if i'll do some mistakes) :-X
as you can see from the title i'm trying to do a breathalyzer with a lcd 16x2 I2c a buzzer and a push button for a school project. i'm using arduino uno
i tried to follow this tutorial https://openhardwarehealthcare.com/arduino-breathalyzer/
but i've noticed that the sensor in the turorial is mq-x while should be mq-3 that has 4 pins (i think that is this the name ) gnd vcc dout and aout Scheda con sensore di GAS - MQ-3
the lcd that i've bought is this http://www.futurashop.it/display-lcd-16x2-con-interfaccia-i²c-2846-lcd16x2ai2c
this is the buzzer Buzzer con elettronica 5V - 12 mm
ad this the push button Minipulsante da circuito stampato- 6x6 mm
the resistor used is of 10k ohm as wrote on the tutorial
the first question is where i should connect the dout and aout of the mq-3 sensor than is it right the program ( arduino sketch)?
can someone if it's not right draw me the scheme of the project and the program if there are some mistakes?
i tried to make everything right ( from the photo) but when i load the program the only thing that happens is that the buzzer makes noise for 5 sec in loop, the lcd just turns on but no letters (i added the lcd 16x2 i2c library)
if you can made a better program with this components with also a better calibration should be better
thanks to everyone that will help me
here is the sketch
#include <LiquidCrystal_I2C.h>
// Libraries
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Warmup
int TIME_UNTIL_WARMUP = 20;
unsigned long time;
// Measurement
int TIME_UNTIL_MEASURE = 5;
unsigned long measurement_start;
// Sensor readings
int analogPin = A0;
int val = 0;
// Buzzer
const int buzzerPin = 7;
// Button
const int buttonPin = 2;
// Modes
bool measurement_mode;
bool measurement_done;
// LCD
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup() {
// Serial
Serial.begin(115200);
// Init LCD
lcd.init();
lcd.backlight();
}
void loop() {
// Read button state
int button_state = digitalRead(buttonPin);
if (button_state && !measurement_mode) {
lcd.clear();
measurement_mode = true;
measurement_start = millis()/1000;
measurement_done = false;
}
// Wait
delay(100);
// Get time
time = millis()/1000;
// Warmup
if(time<=TIME_UNTIL_WARMUP)
{
int progress_time = map(time, 0, TIME_UNTIL_WARMUP, 0, 100);
printWarming(progress_time);
}
else
{
if (measurement_mode == false && !measurement_done) {
// Instruction
printPress();
}
if (measurement_mode && !measurement_done) {
// Instruction
printMeasure();
// Sound
tone(buzzerPin, 1000);
// Read alcohol level
val = readAlcohol();
}
if (measurement_mode && !measurement_done && ((time - measurement_start)> TIME_UNTIL_MEASURE)){
noTone(buzzerPin);
measurement_mode = false;
measurement_done = true;
lcd.clear();
}
if(measurement_done) {
printAlcohol(val);
printAlcoholLevel(val);
}
}
}
void printWarming(int progress)
{
lcd.setCursor(0,0);
lcd.print("Riscaldamento: ");
lcd.print(progress);
lcd.print("%");
}
void printPress()
{
lcd.setCursor(0,0);
lcd.print("Premere per iniziare");
}
void printMeasure()
{
lcd.setCursor(0,0);
lcd.print("Soffia fino a...");
lcd.setCursor(0,1);
lcd.print("sound stops ...");
}
void printAlcohol(int value)
{
lcd.setCursor(0,0);
lcd.print("Sensor reading: ");
lcd.print(val);
}
void printAlcoholLevel(int value)
{
lcd.setCursor(0,2);
if(value<200)
{
lcd.print("You are sober.");
}
if (value>=200 && value<280)
{
lcd.print("You had a beer.");
}
if (value>=280 && value<350)
{
lcd.print("Two or more beers.");
}
if (value>=350 && value <450)
{
lcd.print("Too much ...");
}
if(value>450)
{
lcd.print("You are drunk!");
}
}
int readAlcohol()
{
// Number measurements
int nb_measurements = 5;
int measurements;
// Measure
for (int i = 0; i < nb_measurements; i++) {
measurements = measurements + analogRead(analogPin);
}
measurements = measurements/nb_measurements;
return measurements;
}