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: "Sensor Readings"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-02-15 20:57:46
- ********* 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> //https://github.com/adafruit/DHT-sensor-library
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t myDHT22_DHT22_DOUT_PIN_D2 = 2;
- /***** DHT SENSOR CONFIGURATION *****/
- #define DHTTYPE DHT22 // DHT 22 (AM2302)
- DHT dht(myDHT22_DHT22_DOUT_PIN_D2, DHTTYPE); // Create DHT object
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(myDHT22_DHT22_DOUT_PIN_D2, INPUT_PULLUP);
- dht.begin(); // Initialize the DHT sensor
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- delay(2000); // Wait a few seconds between measurements
- // Read humidity and temperature
- 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;
- }
- // Print the results to the Serial Monitor
- Serial.print("Humidity: ");
- Serial.print(humidity);
- Serial.print(" %\t");
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.println(" *C");
- // Here you can add conditions to actuate outputs based on thresholds
- // For example:
- if (temperature > 30) {
- // Code to actuate a cooling system
- }
- else if (temperature < 15) {
- // Code to actuate a heating system
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement