Hi, I’m trying to merge code for temperature and humidity based on DHT22 readings with Arduino PID control.
I’m unsure how to get get the correct output.
I would like to be able to set the setpoint humidity by the blynk slider ex. at 40% and also follow the flow and the measurements as the screen dump below.
Ok first of all if you don’t know theory behind PID please read it as it helps a lot in understanding what you are doing, why and how you gonna achieve it. Based on what you chose your P, I, D? Have you done any tuning of your system whatsoever? Make sure you are casting your variable correctly from float to double when initializing myPID. Also you need to set sampleTime for myPID
Actually you can use Matlab to tune your PID controller if you take some readings without actuall PID controller and measure how environment reacts.
Hi, yes I will dig into the PID routines and I have not done any tuning yet.
The plan is to set up the code and do some tuning 1:1. If you have any input to the set point temp or the timewindow, please provide.
I use a dehumidifier for controlling the environment - it can take 50% humidity to 30% in around 60 minutes.
Hi, I will use the setup for controlling the humidity in a part of the basement in my house - this part of the basement is not yet renovated and the bottom floor and walls are in bad condition.
If I do nothing the humidity will rise to a high level and it would be perfect to control it over wifi and with PID control.
Start tuning from having I and D as 0 and changing P only then adding other parameters. Plot your graphs using Plotly for example as with Blynk it’s gonna be quite hard. Write some code to be able to change PIDs on the fly through serial port or in Blynk. Lastly add some filtering to your humidity readings cause you don’t want some disturbance to alter your system (as I can see it fluctuates a lot on your graph)
for my moisture reduction ventilation system (not using a de-humidifier) i use a running median calculation to smooth the readings… i don’t use PID though - my target humidity is “the lowest possible”…
PID Controller has nothing to do with filtering. It’s basically a way to control Complex control industrial systems that usually have some kind of delay from let’s say using heater to heat up sth to actual change in temperature.
it must be possible to make a simple humidity Control - it is possible to buy these exhaust fans at homedepot.com, they all have a buildin humidity controller. (+ wifi and live feed in Blynk for turning on and off a dehumifier)
Besides the PID routine (code) that has to be tunede, can anybody help with the code setup. I think it is somehow the timer lib., that is giving me problems. It is compiling without errors but the relay is not kicking in.
KSinning I haven’t got a clue what PID is and know very little about humidity.
All I can really make out in your sketch is that the relay should be on for 5 seconds based on “Output” or it should be off.
Can’t you just have a 5 second SimpleTimer rather than the millis stuff to check for your condition and then turn the relay on and off. Are you familiar with SimpleTimer?
hi, Costas. As i understand the code - the millis() set the windows size for the PID calculation and it is changing based on the calculation over time.
I still want the temperature and humidity readings send to Blynk every second (sendUptime)…but i’m also new to coding so i might be doing everything the wrong way…maybe SimpleTimer can do the job, i’m not sure?
The optimum void loop for Blynk is shown below and everything else should normally be done outside the loop i.e. timers. That is why Blynk provide the SimpleTimer library. Your millis() looks fine and shouldn’t be a problem but timers are easier to read in the sketch.
TImers in normal MCUs are only used to have either precise events or efficient power management. It’s massive overkill to have timers in some situations also in some other situations it’s actually not suitable to use timers. First of all use brackets makes code clearer.
The reason for your code not to work is fact that your PID is broken as Input you should use humidity readings. Your set point should be some constant or variable you want to have and the output is pretty much relay state. In your code nothing changes.
There is however one big “but”. Why you are using PID if you only control 0/1 state of your humidifier. In my opinion using PID in your case doesn’t make sense because the whole point of PID would be to control intensity or the power output of your humidifier. Read about PID and think about it