Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: Sensor Controller
- - Source Code compiled for: Arduino Opta WiFi
- - Source Code created on: 2025-08-04 23:34:26
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Implement a gas detection alert system on Arduino */
- /* Opta WiFi, utilizing MQ3 sensor for alcohol */
- /* detection and potentiometer for sensitivity */
- /* adjustment, with RGB LED indicators for alert */
- /* status. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- // No external libraries are used in this project.
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- // ***** DEFINITION OF ANALOG INPUT PINS *****
- const uint8_t mq3_MQ3_AOUT_PIN_A0 = A0;
- const uint8_t pot_Potentiometer_Vout_PIN_A2 = A2;
- // ***** DEFINITION OF DIGITAL OUTPUT PINS *****
- const uint8_t led_LEDRGB_Red_PIN_D0 = 0;
- const uint8_t led_LEDRGB_Green_PIN_D1 = 1;
- const uint8_t led_LEDRGB_Blue_PIN_D2 = 2;
- // ***** DEFINITION OF OUTPUT RAW VARIABLES *****
- /***** used to store raw data *****/
- bool led_LEDRGB_Red_PIN_D0_rawData = 0;
- bool led_LEDRGB_Green_PIN_D1_rawData = 0;
- bool led_LEDRGB_Blue_PIN_D2_rawData = 0;
- // ***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****
- /***** used to store data after characteristic curve transformation *****/
- float led_LEDRGB_Red_PIN_D0_phyData = 0.0;
- float led_LEDRGB_Green_PIN_D1_phyData = 0.0;
- float led_LEDRGB_Blue_PIN_D2_phyData = 0.0;
- // Additional variables for gas detection
- float gasThreshold = 0.5; // Default threshold, can be adjusted via potentiometer
- float gasSensorValue = 0.0;
- void setup(void)
- {
- // Initialize serial communication for debugging
- Serial.begin(9600);
- // Configure pins
- pinMode(mq3_MQ3_AOUT_PIN_A0, INPUT);
- pinMode(pot_Potentiometer_Vout_PIN_A2, INPUT);
- pinMode(led_LEDRGB_Red_PIN_D0, OUTPUT);
- pinMode(led_LEDRGB_Green_PIN_D1, OUTPUT);
- pinMode(led_LEDRGB_Blue_PIN_D2, OUTPUT);
- }
- void loop(void)
- {
- // Read the potentiometer for sensitivity adjustment
- int potValue = analogRead(pot_Potentiometer_Vout_PIN_A2);
- // Map potentiometer value (0-1023) to a threshold range (e.g., 0.1 to 1.0)
- gasThreshold = map(potValue, 0, 1023, 10, 100) / 100.0;
- // Read the MQ3 sensor value
- int sensorReading = analogRead(mq3_MQ3_AOUT_PIN_A0);
- // Convert sensor reading to voltage (assuming 5V ADC reference)
- float sensorVoltage = sensorReading * (5.0 / 1023.0);
- // For simplicity, normalize sensor voltage to a 0-1 range
- gasSensorValue = sensorVoltage / 5.0;
- // Determine if gas level exceeds threshold
- if (gasSensorValue >= gasThreshold)
- {
- // Gas detected - turn on red LED
- led_LEDRGB_Red_PIN_D0_rawData = HIGH;
- led_LEDRGB_Green_PIN_D1_rawData = LOW;
- led_LEDRGB_Blue_PIN_D2_rawData = LOW;
- }
- else
- {
- // No gas detected - turn on green LED
- led_LEDRGB_Red_PIN_D0_rawData = LOW;
- led_LEDRGB_Green_PIN_D1_rawData = HIGH;
- led_LEDRGB_Blue_PIN_D2_rawData = LOW;
- }
- // Update physical data if needed (here we directly use rawData for simplicity)
- updateOutputs();
- // Optional: print values for debugging
- Serial.print("Gas Sensor Value: ");
- Serial.print(gasSensorValue);
- Serial.print(" Threshold: ");
- Serial.println(gasThreshold);
- delay(200); // Delay for stability
- }
- void updateOutputs()
- {
- digitalWrite(led_LEDRGB_Red_PIN_D0, led_LEDRGB_Red_PIN_D0_rawData);
- digitalWrite(led_LEDRGB_Green_PIN_D1, led_LEDRGB_Green_PIN_D1_rawData);
- digitalWrite(led_LEDRGB_Blue_PIN_D2, led_LEDRGB_Blue_PIN_D2_rawData);
- }
Advertisement
Add Comment
Please, Sign In to add comment