Hi, my Project is trying to control a Heating Plate with Relays to Keep the Fluid inside under the Set Temperature, and I wanted to use the Slider Widget to Change the Temperature where the heating plate turns on or off.
I’m using two Sliders for this, one that determines the Target Temperature and one that determines when the heater turns back on after the Target is reached.
And as you see in my code I’m Pulling the Value of the sliders with Blynk_Write but the variable that I assigned it to isn’t global, so I get the “was not declared in this scope” error, how do I solve this?
It’s not the processor that can’t keep up, it’s the sensor. You won’t have any joy with Blynk until you move that code out of the void loop into a function called with a timer.
As far as variable scope is concerned, that’s really a C++ programming 101 question, and there are lots of resources that explain how to manage variable scope.
The 200ms was just for testing.
But how exactly would I declare variables globally? How can I use the temperatureC variable outside the temp_reading function?
Now i moved the If functions out of the temp_reading function because the relays would turn off and on very fast if the temperature was between target and tempMin, so I put them in the function relay, so that wouldn’t happen, but the problem is I declared temperatureC as float temperatureC = 0; but it doesn’t change globally, outside the temp_reading function its 0 C° as I specified in the declaration
How do I solve this?
You should go back to the structure of your previous ketch, where the code that is now in relay was in temp_reading.
The problem you had with the relays turning on and off rapidly was because of the logic of your if statements…
You checked if the temp was less than 100 and if it was turned the relays on. Then, immediately after checked if the temp was greater than 95 and if it was turned the relays off.
So, the code was doing exactly what you asked it to, but the logic is flawed.
Your second if test needs to be something like…
if (temperatureC > 102) {
That way, it would turn the relay on if the temp is below 100 and off when it reaches 102