Here's a basic Arduino code for a Breathalyzer project using an MQ-3 alcohol sensor

const int sensorPin = A0; // MQ-3 sensor connected to analog pin A0
const int ledPin = 13; // LED connected to digital pin 13
const float refVoltage = 5.0; // Reference voltage for the sensor
const float voutToAlcoholRatio = 0.0048828125; // Ratio to convert voltage output to alcohol concentration

void setup() {
  Serial.begin(9600); // Initialize serial communication at 9600 bps
  pinMode(ledPin, OUTPUT); // Set LED pin as output
}

void loop() {
  float sensorVoltage = analogRead(sensorPin) * refVoltage / 1023.0; // Read analog input and convert to voltage
  float alcoholConcentration = sensorVoltage / voutToAlcoholRatio; // Convert voltage to alcohol concentration
  Serial.print("Alcohol Concentration: "); // Print the alcohol concentration to the serial monitor
  Serial.print(alcoholConcentration);
  Serial.println(" ppm");
  if (alcoholConcentration >= 0.5) { // If the alcohol concentration is above the threshold, turn on the LED
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW); // Otherwise, turn off the LED
  }
  delay(1000); // Wait for 1 second before taking the next reading
}

This code reads the analog output of the MQ-3 alcohol sensor connected to analog pin A0 and converts the voltage output to alcohol concentration in parts per million (ppm) using the voutToAlcoholRatio. The alcohol concentration is then printed to the serial monitor and compared to a threshold of 0.5 ppm. If the concentration is above the threshold, the LED connected to digital pin 13 is turned on. The code then waits for 1 second before taking the next reading. Note that the threshold value may need to be adjusted depending on the sensitivity of the sensor and the desired level of accuracy.

Related Articles

- All From ChatGPT
PLG_GSPEECH_SPEECH_BLOCK_TITLE