/* an arduino program for the following:
MQ3 Alcohol Sensor Module that measure the alcohol concentration constinuously
and shown in I2C LCD 16x2 display constinuously.
When the alcohol concentration is high, a piezo buzzer on pin 8 will sound high pitch
and a servo motor will move from 20 degree to 150 degree.
When alcohol concentration is low, piezo buzzer is quite and servo motor stays at 20 degree.
Note: The value of 500 for the alcohol level threshold is arbitrary
and may need to be adjusted based on the specific sensor and setup being used.
Also, the I2C address of the LCD display may be different, check the datasheet for the address.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
Servo myservo;
LiquidCrystal_I2C lcd(0x27, 16, 2);
int sensorPin = A0;
int buzzerPin = 8;
int alcoholLevel = 0;
void setup() {
myservo.attach(9);
myservo.write(20);
lcd.begin();
pinMode(buzzerPin, OUTPUT);
}
void loop() {
alcoholLevel = analogRead(sensorPin);
lcd.setCursor(0,0);
lcd.print("Alcohol Level: ");
lcd.print(alcoholLevel);
if (alcoholLevel > 500) {
myservo.write(150);
tone(buzzerPin, 2000);
lcd.setCursor(0,1);
lcd.print("Dangerous Level!");
}
else {
myservo.write(20);
noTone(buzzerPin);
}
delay(1000);
}
No comments:
Post a Comment