Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
/* * This is lightly modified from the built-in SimpleDHT example code for the DHT22 humidity & temperature sensor, * "DHT22Default". * * First, use male-to-female wires or a male-to-male and a breadboard to connect the following pins on the DHT22 * to the Arduino: * * pin "+" on DHT22: connects to 5V on Arduino (any 5v pin will do) * pin "out" on DHT22: connects to pin 2 on Arduino * pin "-" on DHT22: connects to GND on Arduino (any GND pin will do) * * Finally, use the Serial Monitor to see the output! Go to Tools > Serial Monitor, and make sure the speed * in the lower right corner of the window is on "9600 baud" (long story for another day). * * To calculate the "heat index", which combines temperature and humidity for what it "feels like", it's kind of complicated. * Modified from https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml: * First, we do this calculation: * HI (heat index) = 0.5 * {T + 61.0 + [(T-68.0)*1.2] + (RH*0.094)} * (T is temperature in degrees F, and RH is % relative humidity) * * Average HI with the temperature to find the heat index: * AVERAGE = (HI + T) / 2 * If the average is less than 80, we use that number. This is sometimes called the "humiture" (ha!). * * If HI is greater than 80, we need to use the following equation, called the "Rothfusz regression": * HI = -42.379 + 2.04901523*T + 10.14333127*RH - .22475541*T*RH - .00683783*T*T - .05481717*RH*RH + .00122874*T*T*RH + .00085282*T*RH*RH - .00000199*T*T*RH*RH * * Wow, that's ugly! Also, if the RH is less than 13% and the temperature is between 80 and 112 degrees F, * then the following adjustment is subtracted from HI: * * ADJUSTMENT = [(13-RH)/4]*SQRT{[17-ABS(T-95.)]/17} * where ABS and SQRT are the absolute value and square root functions, respectively. * * On the other hand, if the RH is greater than 85% and the temperature is between 80 and 87 degrees F, * then the following adjustment is added to HI: * ADJUSTMENT = [(RH-85)/10] * [(87-T)/5] * * What does this all mean? Just use the calculateHeatIndex function that I wrote for you. :) * */ #include <SimpleDHT.h> // for DHT22, // VCC: 5V or 3V // GND: GND // DATA: 2 int pinDHT22 = 2; // if you don't want to connect it to pin 2, you can change that here, just don't use 0 or 1! SimpleDHT22 dht22(pinDHT22); void setup() { Serial.begin(9600); Serial.println("================================="); Serial.println("Reading from DHT22..."); } void loop() { // read without samples. // @remark We use read2 to get a float data, such as 10.1*C // if user doesn't care about the accurate data, use read to get a byte data, such as 10*C. float tempC = 0; float humidity = 0; // this checks to see if there are errors int err = SimpleDHTErrSuccess; if ((err = dht22.read2(&tempC, &humidity, NULL)) != SimpleDHTErrSuccess) { Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000); return; } float tempF = tempC * 1.8 + 32; // convert Celsius to Fahrenheit float hi = calculateHeatIndex(tempF, humidity); // if the sample is okay, display it: // Serial.print((float)tempC); // Americans don't use Celsius! :P // Serial.print(" *C, "); Serial.print((float)tempF); Serial.print(" *F, "); Serial.print("feels like "); Serial.print((float)hi); Serial.print(" *F, "); Serial.print((float)humidity); Serial.println(" RH%"); // DHT22 sampling rate is 0.5Hz, or once every 2 seconds delay(2500); } float calculateHeatIndex(float t, float rh) { // HI = 0.5 * {T + 61.0 + [(T-68.0)*1.2] + (RH*0.094)} float hi = 0.5 * ( t + 61.0 + ( ( t - 68.0 ) * 1.2 ) + ( rh * 0.094 ) ); float avg = (hi + t) / 2; if (avg < 80) { return avg; } else { // the average is greater than 80, so we have to continue on! // Rothfusz regression: // HI = -42.379 + 2.04901523*T + 10.14333127*RH - .22475541*T*RH - .00683783*T*T - .05481717*RH*RH + .00122874*T*T*RH + .00085282*T*RH*RH - .00000199*T*T*RH*RH hi = -42.379 + (2.04901523 * t) + (10.14333127 * rh) - (0.22475541 * t * rh) - (0.00683783 * t * t) - (0.05481717 * rh * rh) + (0.00122874 * t * t * rh) + (0.00085282 * t * rh * rh) - (0.00000199 * t * t * rh * rh); // If the RH is less than 13% and the temperature is between 80 and 112 degrees F if (rh < 13 && t >= 80 && t <= 112) { // the following adjustment is subtracted from HI: // ADJUSTMENT = [(13-RH)/4]*SQRT{[17-ABS(T-95.)]/17} float adjustment = ( ( 13 - rh ) / 4 ) * sqrt( ( 17 - abs( t - 95.0 ) ) /17 ); hi = hi - adjustment; return hi; } else if (rh > 85 && t >= 80 && t <= 87) { // if the RH is greater than 85% and the temperature is between 80 and 87 degrees F, then the following adjustment is added to HI: // ADJUSTMENT = [(RH-85)/10] * [(87-T)/5] float adjustment = ( ( rh - 85 ) / 10 ) * ( ( 87 - t ) /5 ); hi = hi + adjustment; return hi; } else { // no adjustment necessary, just use original regression return hi; } } }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
⭐⭐ INSTANT MONEY EXPLOIT ⭐⭐ ✅
JavaScript | 2 min ago | 0.67 KB
⚡ Earn 8,000$ Monthly Leaked Guide 🎯⭐
JavaScript | 4 min ago | 0.67 KB
⭐⭐ Crypto Swap Glitch ✅ Easy money ⭐⭐
JavaScript | 6 min ago | 0.67 KB
💎 2OOO$ 15 MIN INSANE METHOD 💵🚨 ✅✅
JavaScript | 10 min ago | 0.67 KB
💎💎💎 EXPLOIT 2,500$ IN 10 MINUTES
JavaScript | 10 min ago | 0.67 KB
✅ FREE 2,000$ FROM SWAPZONE ✅
JavaScript | 14 min ago | 0.67 KB
📌 QUICK 1K$ 20 MINUTES ✅📌
JavaScript | 15 min ago | 0.67 KB
💎 UNLIMITED MONEY GLITCH 💎
JavaScript | 18 min ago | 0.67 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!