Controllo ON/OFF di temperatura  software con Delphi e Arduino.

Schema elettrico

Schema di montaggio

Template del programma di controllo

Form

Sorgente software

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Shape1: TShape;
    Label1: TLabel;
    Shape2: TShape;
    Shape3: TShape;
    Shape4: TShape;
    Label2: TLabel;
    Shape5: TShape;
    Shape6: TShape;
    Shape7: TShape;
    Shape8: TShape;
    Label3: TLabel;
    StaticText1: TStaticText;
    StaticText2: TStaticText;
    StaticText3: TStaticText;
    TrackBar1: TTrackBar;
    StaticText4: TStaticText;
    Shape9: TShape;
    Shape10: TShape;
    StaticText5: TStaticText;
    Label4: TLabel;
    Shape11: TShape;
    Shape12: TShape;
    Label5: TLabel;
    Shape13: TShape;
    Shape14: TShape;
    Shape15: TShape;
    StaticText6: TStaticText;
    Timer1: TTimer;
    CheckBox1: TCheckBox;
    Shape16: TShape;
    Image1: TImage;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TrackBar1Change(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Grafica;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses UArduSerCom;

{$R *.DFM}
const
  KV=5/1023;
  KT=5/1023*100;
  RNTC_25=11037;
  RNTC_80=3677;
  R1=6800;
  MaxRef=5*(R1/(R1+RNTC_80));
  MinRef=5*(R1/(R1+RNTC_25));

var
  Rif:real;
  Retro:real;
  Err:real;
  Attuat:real;
  Uscita:real;

  ORif:real;
  ORetro:real;
  CurGr:integer;


procedure TForm1.Button1Click(Sender: TObject);
begin
  FormArduSerCom.Show;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  TrackBar1.Max:=round(MaxRef/KV);
  TrackBar1.Min:=round(MinRef/KV);
  TrackBar1.Frequency:=(TrackBar1.Max-TrackBar1.Min) div 10;

end;

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
  Rif:=TrackBar1.Position*KV;
  StaticText3.Caption:=Format('%5.2fV',[Rif]);
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  if CheckBox1.Checked then
  begin
    FormArduSerCom.SetMode(3,1);
    FormArduSerCom.WrDig(3,False);
    Timer1.Enabled:=True;
    CurGr:=0;
  end
  else
  begin
    FormArduSerCom.WrDig(3,False);
    Timer1.Enabled:=False;
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Uscita:=FormArduSerCom.RdAna(0)*KT;
  StaticText6.Caption:=Format('%5.1fC',[Uscita]);
  Retro:=FormArduSerCom.RdAna(1)*KV;
  StaticText2.Caption:=Format('%5.2fV',[Retro]);
  Err:=Rif-Retro;
  StaticText1.Caption:=Format('%5.2fV',[Err]);
  if Err>0 then
  begin
    StaticText4.Caption:='On';
    StaticText5.Caption:='24V';
    FormArduSerCom.WrDig(3,True);
  end
  else
  if Err<0 then
  begin
    StaticText4.Caption:='Off';
    StaticText5.Caption:='0V';
    FormArduSerCom.WrDig(3,False);
  end;
  Grafica;
end;

procedure TForm1.Grafica;
begin
  if CurGr>0 then
  begin
    Image1.Canvas.Pen.Color:=ClBlue;
    Image1.Canvas.MoveTo(CurGr-1,Image1.Height-round(ORif*Image1.Height/5));
    Image1.Canvas.LineTo(CurGr,Image1.Height-round(Rif*Image1.Height/5));
    Image1.Canvas.Pen.Color:=ClRed;
    Image1.Canvas.MoveTo(CurGr-1,Image1.Height-round(ORetro*Image1.Height/5));
    Image1.Canvas.LineTo(CurGr,Image1.Height-round(Retro*Image1.Height/5))
  end
  else
  begin
    Image1.Canvas.Brush.Color:=clWhite;
    Image1.Canvas.Pen.Color:=clBlack;
    Image1.Canvas.rectangle(0,0,Image1.Width,Image1.Height);
    CurGr:=0;
  end;
  inc(CurGr);
  if CurGr>Image1.Width then
  begin
    CurGr:=0;
  end;
  ORif:=Rif;
  ORetro:=Retro;
end;

end.