Advertisement
pleasedontcode

Sensor Data rev_01

Dec 18th, 2023
67
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 Data
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-18 19:00:35
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* DHT sensor detects an temeperature and if its over */
  21.     /* 25 celsius it beeeeps */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h>
  26. #include <DHT.h>
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t Temp_DHT11_DOUT_PIN_D3 = 3;
  34.  
  35. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  36. DHT dht(Temp_DHT11_DOUT_PIN_D3, DHT11);
  37.  
  38. void setup(void)
  39. {
  40.   // put your setup code here, to run once:
  41.   Serial.begin(9600);
  42.   dht.begin();
  43. }
  44.  
  45. void loop(void)
  46. {
  47.   // put your main code here, to run repeatedly:
  48.   float humidity = dht.readHumidity();
  49.   float temperature = dht.readTemperature();
  50.  
  51.   // Check if any reads failed and exit early (to try again).
  52.   if (isnan(humidity) || isnan(temperature)) {
  53.     Serial.println("Failed to read from DHT sensor!");
  54.     return;
  55.   }
  56.  
  57.   Serial.print("Humidity: ");
  58.   Serial.print(humidity);
  59.   Serial.print(" %\t");
  60.   Serial.print("Temperature: ");
  61.   Serial.print(temperature);
  62.   Serial.print(" °C\t");
  63.   Serial.print("Temperature: ");
  64.   Serial.print(dht.readTemperature(true));
  65.   Serial.println(" °F");
  66.  
  67.   // Check if temperature is over 25°C and beep
  68.   if (temperature > 25) {
  69.     // Beep code here
  70.     Serial.println("Temperature is over 25°C. Beeping...");
  71.   }
  72.  
  73.   delay(2000);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement