Advertisement
pleasedontcode

"Sensor Alerts" rev_03

Jun 16th, 2024
768
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: "Sensor Alerts"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-06-16 22:09:17
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop a flame sensor system using Arduino that */
  21.     /* triggers a passive buzzer alarm when flame is */
  22.     /* detected. Utilize ezBuzzer and forcedBMX280 */
  23.     /* libraries for buzzer control and environmental */
  24.     /* data monitoring. Ensure accurate and timely */
  25.     /* alerts. */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <ezBuzzer.h>  //https://github.com/ArduinoGetStarted/buzzer
  30. #include <forcedBMX280.h>  //https://github.com/soylentOrange/Forced-BMX280
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void updateOutputs(void);
  36.  
  37. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  38. const uint8_t pb_PassiveBuzzer_Signal_PIN_D2 = 2;
  39. const uint8_t flameSensor_PIN = 7;  // Define the pin for the flame sensor
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. /***** used to store raw data *****/
  43. bool pb_PassiveBuzzer_Signal_PIN_D2_rawData = 0;
  44.  
  45. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  46. /***** used to store data after characteristic curve transformation *****/
  47. float pb_PassiveBuzzer_Signal_PIN_D2_phyData = 0.0;
  48.  
  49. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  50. ezBuzzer buzzer(pb_PassiveBuzzer_Signal_PIN_D2);  // Initialize ezBuzzer object
  51. ForcedBMX280 climateSensor = ForcedBMX280();  // Initialize ForcedBMX280 object
  52.  
  53. int32_t g_temperature;  // current temperature in hundredths of a degree Celsius
  54.  
  55. void setup(void) {
  56.   // put your setup code here, to run once:
  57.   pinMode(pb_PassiveBuzzer_Signal_PIN_D2, OUTPUT);
  58.   pinMode(flameSensor_PIN, INPUT);
  59.   digitalWrite(pb_PassiveBuzzer_Signal_PIN_D2, LOW);
  60.  
  61.   Serial.begin(9600);
  62.   while (!Serial) {
  63.     delay(10);
  64.   }
  65.  
  66.   Wire.begin();
  67.   while (climateSensor.begin()) {
  68.     Serial.println("Waiting for sensor...");
  69.     digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  70.     delay(1000);
  71.   }
  72.  
  73.   digitalWrite(LED_BUILTIN, HIGH);
  74.   Serial.println("BMX280 ready");
  75.   Serial.print("\tChipID: 0x");
  76.   Serial.println(climateSensor.getChipID(), HEX);
  77. }
  78.  
  79. void loop(void) {
  80.   // put your main code here, to run repeatedly:
  81.   buzzer.loop();  // Call the loop function of ezBuzzer to handle non-blocking operations
  82.   updateOutputs();  // Refresh output data
  83.  
  84.   // Read temperature from the sensor every 2 seconds
  85.   delay(2000);
  86.   climateSensor.takeForcedMeasurement();
  87.   g_temperature = climateSensor.getTemperatureCelsius();
  88.   Serial.print("Temperature: ");
  89.   Serial.print(g_temperature / 100);
  90.   Serial.print(".");
  91.   Serial.print(g_temperature % 100);
  92.   Serial.println(" °C");
  93.  
  94.   // Check the flame sensor
  95.   int flameSensorValue = digitalRead(flameSensor_PIN);
  96.   if (flameSensorValue == LOW) {
  97.     // Flame detected
  98.     Serial.println("Flame detected! Triggering buzzer...");
  99.     buzzer.beep(1000);  // Beep for 1 second
  100.   }
  101. }
  102.  
  103. void updateOutputs() {
  104.   digitalWrite(pb_PassiveBuzzer_Signal_PIN_D2, pb_PassiveBuzzer_Signal_PIN_D2_rawData);
  105. }
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement