Advertisement
pleasedontcode

Flame Buzzer rev_02

May 18th, 2024
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Flame Buzzer
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-05-18 20:21:48
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Turns on and off when it senses flame */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <ezBuzzer.h>   //https://github.com/ArduinoGetStarted/buzzer
  26. #include <DHT.h>    //https://github.com/adafruit/DHT-sensor-library
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31. void updateOutputs(void); // Added function prototype
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t FlameSensor_DHT22_DOUT_PIN_D3 = 3;
  35.  
  36. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  37. const uint8_t PassiveBuzzer_Signal_PIN_D2 = 2; // Corrected variable name
  38.  
  39. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  40. bool PassiveBuzzer_Signal_PIN_D2_rawData = 0; // Corrected variable name
  41.  
  42. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  43. float PassiveBuzzer_Signal_PIN_D2_phyData = 0.0; // Corrected variable name
  44.  
  45. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  46. const int BUZZER_PIN = 5; // Define the buzzer pin
  47.  
  48. ezBuzzer buzzer(BUZZER_PIN); // Initialize the ezBuzzer object with the buzzer pin
  49.  
  50. #define DHTPIN 3
  51. #define DHTTYPE DHT22
  52.  
  53. DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor object with the pin and type
  54.  
  55. void setup(void)
  56. {
  57.     // put your setup code here, to run once:
  58.     pinMode(FlameSensor_DHT22_DOUT_PIN_D3, INPUT_PULLUP);
  59.     pinMode(PassiveBuzzer_Signal_PIN_D2, OUTPUT);
  60.     dht.begin(); // Initialize the DHT sensor
  61. }
  62.  
  63. void loop(void)
  64. {
  65.     // put your main code here, to run repeatedly:
  66.     updateOutputs(); // Refresh output data
  67.  
  68.     if (digitalRead(FlameSensor_DHT22_DOUT_PIN_D3) == HIGH) {
  69.         PassiveBuzzer_Signal_PIN_D2_rawData = 1; // Turn on the buzzer
  70.     } else {
  71.         PassiveBuzzer_Signal_PIN_D2_rawData = 0; // Turn off the buzzer
  72.     }
  73. }
  74.  
  75. void updateOutputs(void)
  76. {
  77.     digitalWrite(PassiveBuzzer_Signal_PIN_D2, PassiveBuzzer_Signal_PIN_D2_rawData);
  78. }
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement