フィルターのクリア

Build a relay on code

12 ビュー (過去 30 日間)
Ricardo López
Ricardo López 2020 年 12 月 18 日
回答済み: Rik 2020 年 12 月 18 日
Good afternoon
I want to build a thermostat code in an existing building. I want to start the heater when the inside temperature (Tinv) is lower than a set point temperature (Ts) and turning it off when Tin reaches a maximum (Tmax). This problem is being conducted over a certain time period, so variables are Tin(j), Ts(j), Tmax(j).
The on/off variable is just a 1 or a 0 (v(j)). I wanted to build some kind of relay into it but it is not working for me so far, so I wanted to ask you people.
My code is as follows:
if Tinv(j)<=Ts(j)
v(j)=1;
if v(j-1)==1
v(j)=1;
else
if v(j-1)==0
v(j)=0;
end
end
end
Temperature just keep going down once it reaches the set point temp.
Thank you in advance,

採用された回答

Rik
Rik 2020 年 12 月 18 日
You should sketch the two behaviors (don't use i or j as a variable name, and use comments to describe what your code is doing):
if Tin(t)<Ts
%temperature below setpoint, turn heating on
v(t)=1;
elseif v(t-1)==1 && Tin(t)>Tmax
%heating was on and max temp reached, turn off
v(t)=0;
else
%otherwise keep the same setting as last time interval
v(t)=v(t-1);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStatics and Dynamics についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by