Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: AlcoholDetector - Source Code compiled for: Arduino Pro Mini 5V - Source Code created on: 2023-12-26 09:22:47 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* If sensor detects an alcohol percentage over a */ /* threshold2, so activate the buzzer and led, switch */ /* off relay and print on lcd ""Eccessive alcohol". */ /****** SYSTEM REQUIREMENT 2 *****/ /* If sensor detects an alcohol concentrati on below */ /* a threshold1 (that Is lower of threshold2), so */ /* switch off the led and buzzer, maintain on the */ /* relay and do not display anything on lcd. */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include
#include
#include
#include
/****** SYSTEM PARAMETERS *****/ const int threshold1 = 100; // Threshold 1 for low alcohol concentration const int threshold2 = 200; // Threshold 2 for high alcohol concentration /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void handleAlcoholConcentration(int alcoholConcentration); /***** DEFINITION OF ANALOG INPUT PINS *****/ const uint8_t Mq3_alcohol_value_PIN_A0 = A0; /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t Buzzer_ActiveBuzzer_output_PIN_D2 = 2; const uint8_t Led_LED_PIN_D3 = 3; const uint8_t Relay_powerSupplyDCMotor_PIN_D4 = 4; /***** DEFINITION OF I2C PINS *****/ const uint8_t Lcd_LCD1602I2C_I2C_PIN_SDA_A4 = A4; const uint8_t Lcd_LCD1602I2C_I2C_PIN_SCL_A5 = A5; const uint8_t Lcd_LCD1602I2C_I2C_SLAVE_ADDRESS = 0x27; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ MQUnifiedsensor MQ3("Arduino Pro Mini 5V", 5, 10, Mq3_alcohol_value_PIN_A0, "MQ-3"); LiquidCrystal_I2C lcd(Lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // Assuming you are using 16x2 LCD void setup(void) { // put your setup code here, to run once: pinMode(Mq3_alcohol_value_PIN_A0, INPUT); pinMode(Buzzer_ActiveBuzzer_output_PIN_D2, OUTPUT); pinMode(Led_LED_PIN_D3, OUTPUT); pinMode(Relay_powerSupplyDCMotor_PIN_D4, OUTPUT); lcd.begin(16, 2); // Initialize LCD with 16 columns and 2 rows lcd.backlight(); } void loop(void) { // Read alcohol concentration from the MQ-3 sensor MQ3.update(); int alcoholConcentration = MQ3.readSensor(); // Handle the alcohol concentration based on the system requirements handleAlcoholConcentration(alcoholConcentration); // Display the alcohol concentration on the LCD lcd.setCursor(0, 0); lcd.print("Alcohol: "); lcd.print(alcoholConcentration); lcd.print(" ppm"); delay(500); } void handleAlcoholConcentration(int alcoholConcentration) { // If alcohol concentration is above threshold2 if (alcoholConcentration > threshold2) { digitalWrite(Buzzer_ActiveBuzzer_output_PIN_D2, HIGH); digitalWrite(Led_LED_PIN_D3, HIGH); digitalWrite(Relay_powerSupplyDCMotor_PIN_D4, LOW); lcd.setCursor(0, 1); lcd.print("Excessive alcohol"); } // If alcohol concentration is below threshold1 else if (alcoholConcentration < threshold1) { digitalWrite(Buzzer_ActiveBuzzer_output_PIN_D2, LOW); digitalWrite(Led_LED_PIN_D3, LOW); digitalWrite(Relay_powerSupplyDCMotor_PIN_D4, HIGH); lcd.setCursor(0, 1); lcd.print(" "); } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)