Advertisement
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: **Alert System**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-02-15 21:28:08
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The project shall continuously read data from */
- /* connected sensors and actuate outputs based on */
- /* predefined thresholds, ensuring real-time */
- /* responsiveness to environmental changes. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <DHT.h> // Include the DHT library
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t myDHT22_DHT22_DOUT_PIN_D2 = 2;
- // Create an instance of the DHT class
- DHT dht(myDHT22_DHT22_DOUT_PIN_D2, DHT22); // Initialize DHT sensor
- // Define thresholds
- float temperatureThreshold = 25.0; // Example threshold for temperature
- float humidityThreshold = 60.0; // Example threshold for humidity
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(myDHT22_DHT22_DOUT_PIN_D2, INPUT_PULLUP);
- dht.begin(); // Start the DHT sensor
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- delay(2000); // Wait a few seconds between measurements
- // Read temperature and humidity
- float humidity = dht.readHumidity();
- float temperature = dht.readTemperature();
- // Check if any reads failed and exit early (to try again).
- if (isnan(humidity) || isnan(temperature)) {
- Serial.println("Failed to read from DHT sensor!");
- return;
- }
- // Actuate outputs based on thresholds
- if (temperature > temperatureThreshold) {
- // Code to actuate output for high temperature
- Serial.println("Temperature is above threshold!");
- }
- if (humidity > humidityThreshold) {
- // Code to actuate output for high humidity
- Serial.println("Humidity is above threshold!");
- }
- // Optionally, print the values for debugging
- Serial.print("Humidity: ");
- Serial.print(humidity);
- Serial.print("% Temperature: ");
- Serial.print(temperature);
- Serial.println("°C");
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement