#include "DHT.h"
/*
AVCS-DHT1 DIY Temperature & Humidity USB Sensor Sketch v3
- used in AVCS SENS profile for VoiceAttack & Arduino Nano
- by SemlerPDX Mar/May 2022 CC BY-SA 4.0
- VETERANS-GAMING.COM/AVCS
DIY Build Guide:
https://veterans-gaming.com/avcs-wiki/dht1-guide/
--This AVCS-DHT1 Sketch is using the Adafruit "DHT.h" Library above, credits:
==================================================================================
Copyright (c) 2020 Adafruit Industries
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================================
*/
// IF you are using any other pin, ensure it is defined here, and of the same type pin as Uno/Nano Pin#2
#define DHTPIN 2
// IF you are using a DHT22, change the value here to define & use this type of sensor
#define DHTTYPE DHT11
#define REGION1
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600); // Define speed at 9600 baud, do not change this value
while (!Serial) {
; // Wait for serial port to connect. Needed for native USB
}
dht.begin();
}
void loop() {
float h = dht.readHumidity();
float c = dht.readTemperature();
if (isnan(h) || isnan(c)) {
return;
}
h += 9; // Add calculated offset for radiant case heat
c -= 2.25; // Subtract calculated offset for radiant case heat
float f = ((c * 9) / 5) + 32; // Calculate 'f' (°F) due to manually changing 'c' (°C) above
float x = dht.computeHeatIndex(f, h);
// AVCS SENS profile may allow sensor arrays in future, this is DHT#1
// Serial Data Output must result in the following final format:
// [AVCS,cc.cc,hh.hh,ff.ff,xx.xx,DHT1]
String dataPrints = "";
dataPrints.concat("[AVCS,");
dataPrints.concat(c);
dataPrints.concat(",");
dataPrints.concat(h);
dataPrints.concat(",");
dataPrints.concat(f);
dataPrints.concat(",");
dataPrints.concat(x);
dataPrints.concat(",DHT1]");
for (int chars = 0; chars <= dataPrints.length(); chars++) {
Serial.write(dataPrints.charAt(chars));
}
//Uncomment for (slower) debug testing through Arduino IDE Serial Monitor:
//delay(1000);
//Serial.println();
}
Comments