Advertisement
pleasedontcode

Sensor Data rev_01

Dec 30th, 2023
85
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-30 14:16:40
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Read the temperature and display it on waveshare */
  21.     /* 2.4lcd module */
  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 DHTPIN = 2;
  34.  
  35. /****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
  36. DHT dht(DHTPIN, DHT22);
  37.  
  38. void setup(void)
  39. {
  40.   // put your setup code here, to run once:
  41.   Serial.begin(9600);
  42.   Serial.println(F("DHTxx test!"));
  43.  
  44.   dht.begin();
  45. }
  46.  
  47. void loop(void)
  48. {
  49.   // put your main code here, to run repeatedly:
  50.   delay(2000);
  51.  
  52.   float humidity = dht.readHumidity();
  53.   float temperatureC = dht.readTemperature();
  54.   float temperatureF = dht.readTemperature(true);
  55.  
  56.   if (isnan(humidity) || isnan(temperatureC) || isnan(temperatureF))
  57.   {
  58.     Serial.println(F("Failed to read from DHT sensor!"));
  59.     return;
  60.   }
  61.  
  62.   Serial.print(F("Humidity: "));
  63.   Serial.print(humidity);
  64.   Serial.print(F("%  Temperature: "));
  65.   Serial.print(temperatureC);
  66.   Serial.print(F("°C "));
  67.   Serial.print(temperatureF);
  68.   Serial.print(F("°F"));
  69.  
  70.   float heatIndexC = dht.computeHeatIndex(temperatureC, humidity);
  71.   float heatIndexF = dht.computeHeatIndex(temperatureF, humidity, false);
  72.  
  73.   Serial.print(F("  Heat index: "));
  74.   Serial.print(heatIndexC);
  75.   Serial.print(F("°C "));
  76.   Serial.print(heatIndexF);
  77.   Serial.println(F("°F"));
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement