I am building a humidity controller using the HTU21DF humidity and temperature sensor from Adafruit. So far everything is working correctly but I was wondering how I could get the temperature to read back in Fahrenheit rather than Celsius. I know the formula is 9/5*C+32=F but I don’t know exactly how to get this to work with my code.
Aha. You need to do more than just print the value returned by the function.
Whoever wrote this should be trussed up like a Thanksgiving turkey. Storing the return value in a variable and then print the variable's value makes it so much easier to add a line of code to alter the value in the variable.
My only remaining question is where should I declare the variables? I've seen code where the variables are declared before the setup loop but my Humidity and Temperature variables didn't work unless I declared them in the void loop.
My only remaining question is where should I declare the variables?
Variables that need global scope should be declared outside of any function. Variables that need local scope should be declared in the function/block where they are needed.
I've seen code where the variables are declared before the setup loop but my Humidity and Temperature variables didn't work unless I declared them in the void loop.
First, the readTemperature() function returns an int. But, no one refers to it as "the int readTemperature". So, it is grating on the ears (and eyes) to hear "the void loop". It is "the loop function".
Second, you have not shown where you declared the variables at global scope, nor have you defined what "didn't work" means. Therefore, we can't help with that problem.
I apologize for my ignorance on some terminology. This is my first time working with Arduino so I'm still learning the basics in some areas.
By "didn't work" I meant that I got nothing in the serial monitor. When I declare the variables inside the loop function the serial monitor shows the correct information (Humidifier On/Off, Temperature, Humidity).
My first attempt to declare the variables looked like this:
The above code led to getting nothing in the serial monitor.
After moving the humidity and temperature variable declarations to the loop function I was getting correct information int the serial monitor. That code is the code I posted in my previous post.