Advertisement
pleasedontcode

Sensor Readings rev_01

Apr 15th, 2024
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 Readings
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-15 09:42:59
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The Arduino project shall read temperature data */
  21.     /* only from a DHT11 sensor connected to a pump. */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <DHT.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t DHT11_PIN = 2;
  33.  
  34. /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
  35. DHT dht(DHT11_PIN, DHT11);
  36.  
  37. void setup(void)
  38. {
  39.   // put your setup code here, to run once:
  40.   pinMode(DHT11_PIN, INPUT_PULLUP);
  41.   dht.begin();
  42.   Serial.begin(9600);
  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.   {
  54.     Serial.println(F("Failed to read from DHT sensor!"));
  55.     return;
  56.   }
  57.  
  58.   // Print temperature and humidity values.
  59.   Serial.print(F("Humidity: "));
  60.   Serial.print(humidity);
  61.   Serial.print(F("%  Temperature: "));
  62.   Serial.print(temperature);
  63.   Serial.println(F("°C"));
  64.  
  65.   delay(2000);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement