PID LCD KeypadShield DS18B20

Kann man das mit dem DS18B20 so machen?

#include <PID_v1.h>
#include <OneWire.h>
#include <DallasTemperature.h>

//28A2B3EB03000014 
#define ONE_WIRE_BUS A1
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

#define RELAY_PIN 3
//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
double Kp=1, Ki=20, Kd=0;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

int WindowSize = 5000;
unsigned long windowStartTime;

void setup()
{
  sensors.begin();
  windowStartTime = millis();
Serial.begin(9600);
  //initialize the variables we're linked to
  Setpoint = 42;

  //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(); // Send the command to get temperatures
  Input = sensors.getTempCByIndex(0);
  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) digitalWrite(RELAY_PIN, HIGH);
  else digitalWrite(RELAY_PIN, LOW);
    Serial.print(" INPUT:");
  Serial.println(Input);
  Serial.print("OUTPUT:");
  Serial.print(Output);
  Serial.print(" SETPOINT:");
  Serial.print(Setpoint);

}

Als ausgabe hab ich dies

OUTPUT:720.00 SETPOINT:42.00 INPUT:26.00
OUTPUT:752.00 SETPOINT:42.00 INPUT:26.00
OUTPUT:784.00 SETPOINT:42.00 INPUT:25.50
OUTPUT:817.50 SETPOINT:42.00 INPUT:26.00
OUTPUT:849.00 SETPOINT:42.00 INPUT:26.00
OUTPUT:881.00 SETPOINT:42.00 INPUT:25.50
OUTPUT:914.50 SETPOINT:42.00 INPUT:26.00

Das SSR wird aber nicht geschaltet.
Pin3->SSR+
GND->SSR-
Viel kann man ja bei der Verdrahtung nicht falsch machen also muss es am Code liegen.

skorpi08:
Das SSR wird aber nicht geschaltet.
Pin3->SSR+
GND->SSR-
Viel kann man ja bei der Verdrahtung nicht falsch machen also muss es am Code liegen.

Ich würde mal kontrollieren, wo Du in Deinem Code den pinMode für das Relay auf OUTPUT setzt.

Dachte es übernimmt die PID Lib?!

Gut, bei Analogen Pins muss man ja nicht extra als Output setzen, da hatte ichs nämlich als erstes probiert.
Und ich meine ich hatte denselben Sketch schon mal mit einem Poti anstatt DS18B20 am laufen.

Wo soll das die PID Lib übernehmen? Die weiß doch von dem Pin gar nichts

Original Beispiel:

/********************************************************
 * PID RelayOutput Example
 * Same as basic example, except that this time, the output
 * is going to a digital pin which (we presume) is controlling
 * a relay.  the pid is designed to Output an analog value,
 * but the relay can only be On/Off.
 *
 *   to connect them together we use "time proportioning
 * control"  it's essentially a really slow version of PWM.
 * first we decide on a window size (5000mS say.) we then
 * set the pid to adjust its output between 0 and that window
 * size.  lastly, we add some logic that translates the PID
 * output into "Relay On Time" with the remainder of the
 * window being "Relay Off Time"
 ********************************************************/

#include <PID_v1.h>

#define PIN_INPUT 0
#define RELAY_PIN 6

//Define Variables we'll be connecting to
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()
{
  windowStartTime = millis();

  //initialize the variables we're linked to
  Setpoint = 100;

  //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()
{
  Input = analogRead(PIN_INPUT);
  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) digitalWrite(RELAY_PIN, HIGH);
  else digitalWrite(RELAY_PIN, LOW);

}

Habe aber den Pin auch als OUTPUT gesetzt, kein Unterschied.
SSR funzt aber, mit GND und 5V getestet.
Am Pin kommen 0.15V

Mal nen Mega angeschlossen, mit pinmode output, Relais ist immer an.
Ohne pinmode output iss es halt immer aus.

OUTPUT:10.00 SETPOINT:29.00Sensor 1: 32.00 �C
 INPUT:32.00
OUTPUT:4.00 SETPOINT:29.00Sensor 1: 32.00 �C
 INPUT:32.50
OUTPUT:0.00 SETPOINT:29.00Sensor 1: 32.50 �C
 INPUT:32.50
OUTPUT:0.00 SETPOINT:29.00Sensor 1: 32.50 �C
 INPUT:32.50
OUTPUT:0.00 SETPOINT:29.00Sensor 1: 32.50 �C
#include <PID_v1.h>
#include <OneWire.h>
#include <DallasTemperature.h>

//28A2B3EB03000014 
#define ONE_WIRE_BUS A1
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

#define RELAY_PIN 31
//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
double Kp=1, Ki=20, Kd=0;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

int WindowSize = 5000;
unsigned long windowStartTime;

void setup()
{
  sensors.begin();
  windowStartTime = millis();
Serial.begin(9600);
  //initialize the variables we're linked to
  Setpoint = 29;
 pinMode(RELAY_PIN, OUTPUT);
  //tell the PID to range between 0 and the full window size
  myPID.SetOutputLimits(0, WindowSize);

  //turn the PID on
  myPID.SetMode(AUTOMATIC);

    Serial.print("Sensoren: "); 
  
  Serial.println(sensors.getDeviceCount());
   
}

void loop()
{
  sensors.requestTemperatures(); // Send the command to get temperatures
  Input = sensors.getTempCByIndex(0);
  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) digitalWrite(RELAY_PIN, HIGH);
  else digitalWrite(RELAY_PIN, LOW);

for(byte i=0;i<sensors.getDeviceCount();i++){  // Temperatur ausgeben
    show_temperature(i+1,sensors.getTempCByIndex(i));  
  }
    delay(1000);  // 5s Pause bis zur nächsten Messung
}

// Temperatur ausgeben
void show_temperature(byte num,float temp){
      Serial.print(" INPUT:");
  Serial.println(Input);
  Serial.print("OUTPUT:");
  Serial.print(Output);
  Serial.print(" SETPOINT:");
  Serial.print(Setpoint);
  
  Serial.print("Sensor ");
  Serial.print(num);
  Serial.print(": ");
  Serial.print(temp);
  Serial.print(" ");  // Hier müssen wir ein wenig tricksen
  Serial.write(176);  // um das °-Zeichen korrekt darzustellen
  Serial.println("C");
}

Danke jungs, es lag an dem delay und dem pinmode.