/********* 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 Alerts"
- Source Code NOT compiled for: Arduino Uno
- Source Code created on: 2024-06-16 22:09:17
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* Develop a flame sensor system using Arduino that */
/* triggers a passive buzzer alarm when flame is */
/* detected. Utilize ezBuzzer and forcedBMX280 */
/* libraries for buzzer control and environmental */
/* data monitoring. Ensure accurate and timely */
/* alerts. */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include //https://github.com/ArduinoGetStarted/buzzer
#include //https://github.com/soylentOrange/Forced-BMX280
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t pb_PassiveBuzzer_Signal_PIN_D2 = 2;
const uint8_t flameSensor_PIN = 7; // Define the pin for the flame sensor
/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool pb_PassiveBuzzer_Signal_PIN_D2_rawData = 0;
/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float pb_PassiveBuzzer_Signal_PIN_D2_phyData = 0.0;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
ezBuzzer buzzer(pb_PassiveBuzzer_Signal_PIN_D2); // Initialize ezBuzzer object
ForcedBMX280 climateSensor = ForcedBMX280(); // Initialize ForcedBMX280 object
int32_t g_temperature; // current temperature in hundredths of a degree Celsius
void setup(void) {
// put your setup code here, to run once:
pinMode(pb_PassiveBuzzer_Signal_PIN_D2, OUTPUT);
pinMode(flameSensor_PIN, INPUT);
digitalWrite(pb_PassiveBuzzer_Signal_PIN_D2, LOW);
Serial.begin(9600);
while (!Serial) {
delay(10);
}
Wire.begin();
while (climateSensor.begin()) {
Serial.println("Waiting for sensor...");
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
delay(1000);
}
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("BMX280 ready");
Serial.print("\tChipID: 0x");
Serial.println(climateSensor.getChipID(), HEX);
}
void loop(void) {
// put your main code here, to run repeatedly:
buzzer.loop(); // Call the loop function of ezBuzzer to handle non-blocking operations
updateOutputs(); // Refresh output data
// Read temperature from the sensor every 2 seconds
delay(2000);
climateSensor.takeForcedMeasurement();
g_temperature = climateSensor.getTemperatureCelsius();
Serial.print("Temperature: ");
Serial.print(g_temperature / 100);
Serial.print(".");
Serial.print(g_temperature % 100);
Serial.println(" °C");
// Check the flame sensor
int flameSensorValue = digitalRead(flameSensor_PIN);
if (flameSensorValue == LOW) {
// Flame detected
Serial.println("Flame detected! Triggering buzzer...");
buzzer.beep(1000); // Beep for 1 second
}
}
void updateOutputs() {
digitalWrite(pb_PassiveBuzzer_Signal_PIN_D2, pb_PassiveBuzzer_Signal_PIN_D2_rawData);
}