我正在尝试将带有PID库的ds1820温度探头用于继电器输出。我从探头得到的温度很好,但我希望继电器输出,在这种情况下只是打开/关闭的打印语句,在温度高于设定值时改变。他们不。也许我已经错过了一些东西,但我认为另外一套眼睛是有用的,因为它几乎是逐字逐句的PID库示例代码,修改从ds1820获取输入,可能非常有用给别人在这个例子中,设定值是60.我希望打印语句在温度低于60时打开,在温度高于时关闭。如果温度低于60,我得到的是“开启”,如果温度高于60,我仍然“开启”。
/*-----( Import needed libraries )-----*/
// Get 1-wire Library here: http://www.pjrc.com/teensy/td_libs_OneWire.html
#include <OneWire.h>
//Get DallasTemperature Library here: http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
#include <DallasTemperature.h>
#include <PID_v1.h>
#define ONE_WIRE_BUS_PIN 3
OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);
DeviceAddress Probe01 = { 0x28, 0x92, 0xBA, 0xAF, 0x06, 0x00, 0x00, 0xD1 }; //x1
//Define Variables we'll be connecting to
double pidInputTemp;
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
double Kp=2, Ki=5, Kd=1;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
int WindowSize = 5000;
unsigned long windowStartTime;
void setup()
{
Serial.begin(19200);
sensors.begin();
// set the resolution of the ds1820s to 12 bit (Can be 9 to 12 bits .. lower is faster)
sensors.setResolution(Probe01, 12);
windowStartTime = millis();
//initialize the variables we're linked to
Setpoint = 60;
//tell the PID to range between 0 and the full window size
myPID.SetOutputLimits(0, WindowSize);
//turn the PID on
myPID.SetMode(AUTOMATIC);
}
void loop()
{
sensors.requestTemperatures();
theTemperature(Probe01);
myPID.Compute();
/************************************************
* turn the output pin on/off based on pid output
************************************************/
if(millis() - windowStartTime>WindowSize)
{ //time to shift the Relay Window
windowStartTime += WindowSize;
}
if(Output < millis() - windowStartTime) Serial.println("On");
else Serial.println("Off");
}
void theTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00)
{
Serial.println("Error getting temperature ");
}
else
{
float tempF = (DallasTemperature::toFahrenheit(tempC));
Serial.println("Setpoint: ");
Serial.println(Setpoint);
Serial.println("Now: ");
Serial.println(tempF);
Input = tempF;
}
}
答案 0 :(得分:0)
我找到了一个似乎可以做我想要的资源,尽管液晶屏幕和按钮有很多膨胀。 Adafruit有一个更强大的PID中断,EPROM写入/调用参数,并在https://learn.adafruit.com/sous-vide-powered-by-arduino-the-sous-viduino/the-whole-enchilada自动调整 - 我需要删除大量的代码,因为我没有使用LCD而且会而是用串行命令替换按钮。