Skip to content

Instantly share code, notes, and snippets.

@cfangmeier
Created June 16, 2020 00:16
Show Gist options
  • Save cfangmeier/f208abe7b0bd4912d86184c612f303e5 to your computer and use it in GitHub Desktop.
Save cfangmeier/f208abe7b0bd4912d86184c612f303e5 to your computer and use it in GitHub Desktop.
int humd_pin = A0;
int temp_pin = A1;
int temp_val = 0;
int humd_val = 0;
float temp = 0; // Temperature in F
float temp_c = 0; // Temperature in C
float humd = 0;
float dp = 0; // Dew Point in F
float dp_c = 0; // Dew Point in C
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
}
float cnvt_temp() {
temp = temp_val / 1023.0; // Scale to 0-1
temp_c = (temp * 130) - 30; // Convert to C
temp = (temp * 234) - 22; // Convert to F
}
float cnvt_humd() {
humd = humd_val / 1023.0; // Scale 0-1
humd = humd * 100; // Convert to Relative Humidity
}
float dew_pt() {
// Calculation from here: https://en.wikipedia.org/wiki/Dew_point
float b = 17.67;
float c = 243.5; // C
float gamma = log(humd / 100.0) + b*temp_c / (c + temp_c);
dp_c = c*gamma / (b - gamma);
dp = (dp_c * 1.8) + 32;
}
void loop() {
temp_val = analogRead(temp_pin);
humd_val = analogRead(humd_pin);
cnvt_temp();
cnvt_humd();
dew_pt();
Serial.print("Temp: ");
Serial.print(temp);
Serial.print(" Humd: ");
Serial.print(humd);
Serial.print(" Dew Pt: ");
Serial.println(dp);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment