SemlerPDX

AVCS_DHT1_DIY_Sensor_v3

Jun 1st, 2022 (edited)
144,204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "DHT.h"
  2.  
  3. /*
  4. AVCS-DHT1 DIY Temperature & Humidity USB Sensor Sketch v3
  5. - used in AVCS SENS profile for VoiceAttack & Arduino Nano
  6. - by SemlerPDX Mar/May 2022 CC BY-SA 4.0
  7. - VETERANS-GAMING.COM/AVCS
  8.  
  9. DIY Build Guide:
  10. https://veterans-gaming.com/avcs-wiki/dht1-guide/
  11.  
  12. --This AVCS-DHT1 Sketch is using the Adafruit "DHT.h" Library above, credits:
  13. ==================================================================================
  14. Copyright (c) 2020 Adafruit Industries
  15.  
  16.  
  17. Permission is hereby granted, free of charge, to any person obtaining a copy
  18. of this software and associated documentation files (the "Software"), to deal
  19. in the Software without restriction, including without limitation the rights
  20. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  21. copies of the Software, and to permit persons to whom the Software is
  22. furnished to do so, subject to the following conditions:
  23.  
  24. The above copyright notice and this permission notice shall be included in all
  25. copies or substantial portions of the Software.
  26.  
  27. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  28. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  29. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  30. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  31. DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  32. OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
  33. OR OTHER DEALINGS IN THE SOFTWARE.
  34. ==================================================================================
  35. */
  36.  
  37. // IF you are using any other pin, ensure it is defined here, and of the same type pin as Uno/Nano Pin#2
  38. #define DHTPIN 2
  39.  
  40. // IF you are using a DHT22, change the value here to define & use this type of sensor
  41. #define DHTTYPE DHT11
  42.  
  43. #define REGION1
  44. DHT dht(DHTPIN, DHTTYPE);
  45.  
  46. void setup() {
  47.   Serial.begin(9600); // Define speed at 9600 baud, do not change this value
  48.   while (!Serial) {
  49.     ; // Wait for serial port to connect. Needed for native USB
  50.   }
  51.   dht.begin();
  52. }
  53. void loop() {
  54.   float h = dht.readHumidity();
  55.   float c = dht.readTemperature();
  56.   if (isnan(h) || isnan(c)) {
  57.     return;
  58.   }
  59.  
  60.   h += 9; // Add calculated offset for radiant case heat
  61.   c -= 2.25; // Subtract calculated offset for radiant case heat
  62.   float f = ((c * 9) / 5) + 32; // Calculate 'f' (°F) due to manually changing 'c' (°C) above
  63.   float x = dht.computeHeatIndex(f, h);
  64.  
  65.   // AVCS SENS profile may allow sensor arrays in future, this is DHT#1
  66.   // Serial Data Output must result in the following final format:
  67.   // [AVCS,cc.cc,hh.hh,ff.ff,xx.xx,DHT1]
  68.  
  69.   String dataPrints = "";
  70.   dataPrints.concat("[AVCS,");
  71.   dataPrints.concat(c);
  72.   dataPrints.concat(",");
  73.   dataPrints.concat(h);
  74.   dataPrints.concat(",");
  75.   dataPrints.concat(f);
  76.   dataPrints.concat(",");
  77.   dataPrints.concat(x);
  78.   dataPrints.concat(",DHT1]");
  79.  
  80.   for (int chars = 0; chars <= dataPrints.length(); chars++) {
  81.     Serial.write(dataPrints.charAt(chars));
  82.   }
  83.   //Uncomment for (slower) debug testing through Arduino IDE Serial Monitor:
  84.   //delay(1000);
  85.   //Serial.println();
  86. }
Add Comment
Please, Sign In to add comment