Re: [diy-pid-control] Digest for diy-pid-control@googlegroups.com - 4 updates in 1 topic

133 views
Skip to first unread message

Rakesh Patel

unread,
Apr 4, 2023, 9:15:10 AM4/4/23
to diy-pid...@googlegroups.com
Hi,

 I had one project where the oven heater coil temperature needed to be controlled. I used the following components. 


First I think you will have to analyse the heat/cool behaviour of the heater coil. My application was a ramp/soak profile. 

Attaching the Arduino Mega code. Let me know if you need help.

Thanks,
Rakesh

On Tue, Apr 4, 2023 at 5:54 PM <diy-pid...@googlegroups.com> wrote:
Schlappo22 <lukas.po...@gmail.com>: Apr 03 07:56AM -0700

Hello PID Group,
 
glad I found this group here and was hoping to get a bit of feedback /
input regarding a project that I am working on.
 
I am working on a water cycle which I want to use to dispense water at a
certain temperature between room temperature and (around) 95degC. In my
application I don't want to heat the water in the tank but rather use a
"flow through heater" to heat the water instantaneously to the desired
temperature. There a lot of heaters out there that are able to heat small
amounts of water when flowing through without the need of preheating.
See my rough sketch below.
 
[image: 2023-04-03 16_53_34-Formula_Makr.drawio - diagrams.net.png]
 
As you can see, I will have a Thermocouple on the inlet and on the outlet
side, which I intend to use for the PID. I have started with the Arduino
Library by Brett and was wondering if anyone has some advice when
approaching this project. I hope that I can keep you posted on progress and
showstoppers once components arrive.
 
Regards, Lukas
Steve Edmonds <st...@edmondsfamily.co.nz>: Apr 03 12:43PM -0700

Do you have variable flow rate, what temperature deviation is acceptable?
 
I have a wax melter project where I found for various reasons straight PID
was not the best option and I resorted to energy balance control. It was
not until I started running various tests and logging the data that I found
this.
I started with a thermocouple, but because I could not insert it in the
melter water jacket that response was far too slow, so I changed to a thin
film RTD bonded to the outer jacket.
My thermal lag is about 5-7 minutes, long enough to input enough heat to
boil the water jacket before I see any temperature rise, and as I ideally
need to run the melter at 91-93C my biggest issue is not boiling the water
jacket.
In your case with low flow not boiling the water during a heating cycle. To
solve this I ran some tests to determine thermal response and losses so I
could limit heat input during any heating cycle to an amount calculated to
be less than that required to boil the water.
 
You may be able to use some similar energy calculations to limit heat input
and possibly scale the PID output control based on flow and temperature
differential.
 
On Tuesday, 4 April 2023 at 02:56:06 UTC+12 Schlappo22 wrote:
 
Steve Edmonds <st...@edmondsfamily.co.nz>: Apr 03 05:19PM -0700

I also had issues with the proportioning of the relay output when run in
the main loop, initial heating for me is at 100% but steady state
requirement when the wax has melted is about 7.5%. I moved the
proportioning into a timer interrupt routine where the interrupt runs every
0.1s and gained better control. With a 20 second control window 0.5%
equates to half a cycle of the AC power controlled by the solid state relay.
 
On Tuesday, 4 April 2023 at 07:43:41 UTC+12 Steve Edmonds wrote:
 
Schlappo22 <lukas.po...@gmail.com>: Apr 04 12:31AM -0700

Thanks very much for your reply.
I think a variable flowrate will overcomplicate the application. So I will
start with a set flowrate and maybe tackle that problem a bit later. So for
now, lets assume constant flow rate.
Interesting application you have there! The thermal lag that you have
should not be such a big problem for me. And if, I need to fix it. If I
need 5-7 minutes to heat up my flow through heater, than the whole
application does not make any sense.
To answer you question regarding the deviation, I don't know what is going
to be achievable, but I am aiming for as small as possible. And would
generally allow larger deviations with rising temperatures. When it comes
to temperatures below 40degC. it has to be within the +-1degC bracket.
I intend to use this Flow Through Heater: FTH II from Ferro Techniek
<https://www.ferrotechniek.com/wp-content/uploads/2021/03/FTH-II-Single-sheet-v4.pdf> (so
you know what I mean when I talk about FTH).
The heater has two power circuits (400W and 800W) that combined and spread
across 5 phases will provide up to 1200W. So switching them on / off at the
zero crossings, is how the intended use case looks like. They also mention
a constant flow-rate, so we will keep it that way.
 
Is that how you control your system as well?
 
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to diy-pid-contr...@googlegroups.com.


--
Thanks and Regards
Rakesh Patel
TCRTD_RAMP.ino

John Schindler

unread,
Apr 19, 2023, 7:08:45 PM4/19/23
to DIY PID Control
Lucas,

You don't mention the flow rate, or the volume in one dispense cycle and the time between cycles.

At 4 ml volume of the heater and 1000 W, you shouldn't have any trouble reaching 40 C in an instant.

Please let us know how it goes.

John

Schlappo22

unread,
May 1, 2023, 5:23:27 AM5/1/23
to DIY PID Control
Thanks for your replies.

Like you say John, no problem at all to get it to the temperature at all. Now my problem is the PID itself.

I use Brett's PID Library for the Arduino and there I use the relay outlet example. As the Flow Through Heater should not be controlled by Phase Cutting I am using Zero Crossing control. To make things a bit easier in the beginning I am only using one out of two power tracks to heat up the water. So only one SSR is being used. By adjusting the on / offs across 10 phases, I am able to get different power states. All off = 0W, All on = 1200W and e.g. every other phase = 50% etc.

I am using the following components as a test setup. 2 Thermocouples, 1 attached to the surface of the FTH to track the temperature of the component. One TC on the outlet to compare the temperatures between the NTC inside the FTH and the Outlet (very accurate and little reading error between the NTC and the TC as of now). The NTC inside the FTH as an Input value. The SSR as an output. The setpoint is in degC. Code provided below. My issue right now is that even if Ki and Kd are 0 and I start with Kp = 1 I immediately hit 70degC even though the setpoint is at 35degC. I have the same behavior for Kp=0.1. I am a bit clueless how to proceed here. Any advice?



#include <FlowSensor.h>
#include <LcdBarGraph.h>
#include <LiquidCrystal.h>

//Internal NTC Stuff
#define RT0 50000  // Ω
#define B 3970     //  K
#define VCC 5      //Supply  voltage
#define R 12000    //R=10KΩ

//Variables
float RT, VR, ln, TX, T0, VRT;

//Thermocouple Stuff
#include <SPI.h>
#include "Adafruit_MAX31855.h"

// Example creating a thermocouple instance with software SPI on any three
// digital IO pins.
#define MAXDO_1 31
#define MAXCS_1 30
#define MAXCLK_1 29

// initialize the Thermocouple
Adafruit_MAX31855 thermocouple_1(MAXCLK_1, MAXCS_1, MAXDO_1);

#define MAXDO_2 26
#define MAXCS_2 27
#define MAXCLK_2 28

// initialize the Thermocouple
Adafruit_MAX31855 thermocouple_2(MAXCLK_2, MAXCS_2, MAXDO_2);

//PID Stuff
#include <PID_v1.h>
#define RELAY_PIN 19

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

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

int WindowSize = 83;
unsigned long windowStartTime;

//LCD
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
byte LCD_Columns = 20;
byte LCD_Rows = 4;

//Flow Sensor
FlowSensor Sensor(YFS201, 18);
unsigned long timebefore = 0;  // same type as millis()
const int Pump = 10;

int variables[2][2] = { { 0, 1 }, { 2, 150 } };

void count() {
  Sensor.count();
}

void setup() {
  Serial.begin(9600);
  //PID Stuff
  windowStartTime = millis();
  //initialize the variables we're linked to
  Setpoint = 35;  //Temperature is the Setpoint
  //tell the PID to range between 0 and the full window size
  myPID.SetOutputLimits(0, WindowSize);
  //turn the PID on
  myPID.SetMode(AUTOMATIC);

  //Thermocouple
  thermocouple_1.begin();
  thermocouple_2.begin();
  T0 = 25 + 273.15;

  //Flowmeter
  Sensor.begin(count);

  //Flow Through Heater
  pinMode(RELAY_PIN, OUTPUT);

  //Pump
  pinMode(Pump, OUTPUT);

  //LCD Begin and Test
  lcd.begin(20, 4);
  lcd.print("Test");
  delay(1000);
  lcd.clear();
}

void loop() {
  // Pump and show progress on LCD until the desired volume has been reached
  LcdBarGraph lbg0(&lcd, 19, 1, 2);
  for (variables[0][0]; variables[0][0] < variables[1][1];) {
    lcd.setCursor(7, 1);
    lcd.print("PROGRESS");
    lbg0.drawValue(variables[0][0], variables[1][1]);
    delay(10);
    digitalWrite(Pump, HIGH);
    Sensor.read();
    variables[0][0] = Sensor.getVolume() * 1000;
    //Serial.println(variables[0][0]);
    //Temperature Stuff
    VRT = analogRead(A15);         //Acquisition analog value of VRT
    VRT = (5.00 / 1023.00) * VRT;  //Conversion to voltage
    VR = VCC - VRT;
    RT = VRT / (VR / R);  //Resistance of RT
    ln = log(RT / RT0);
    TX = (1 / ((ln / B) + (1 / T0)));  //Temperature from thermistor
    TX = TX - 273.15;                  //Conversion to Celsius
    Serial.print(" --- NTC Temperature: ");
    Serial.print(TX);
    //Thermocouple
    Serial.print(" degC --- ");
    //Serial.print("Internal Temp 2 = ");
    //Serial.print(thermocouple_2.readInternal());
    double d = thermocouple_2.readCelsius();
    Serial.print("C_2 = ");
    Serial.print(d);
    Serial.print(" degC");
    //Serial.print(" --- Internal Temp 1 = ");
    //Serial.print(thermocouple_1.readInternal());
    double c = thermocouple_1.readCelsius();
    Serial.print(" --- C_1 = ");
    Serial.print(c);
    Serial.println(" degC");
    /*reading++;
    error = abs(c - TX);
    Serial.print(" --- Error = ");
    Serial.print(error);
    Serial.println(" degC");
    overall = overall + error;
    */

    Input = TX;
    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);
  }
  digitalWrite(RELAY_PIN, LOW);
  digitalWrite(Pump, LOW);
  lcd.clear();
  lcd.setCursor(8, 1);
  lcd.print("DONE");
  while (1) {}
}

John Schindler

unread,
May 1, 2023, 9:54:57 AM5/1/23
to DIY PID Control
Lucas,

Some more info would help to understand: flow rate, amount dispensed,  time between dispense cycles, etc.

Earlier, you mentioned a target of 95 C. Ignoring the thermal mass of the heater, taking 4 ml (the volume of the heater), 4*(95-20)*4.184 = 1225 J. The 1200 W heater setting would provide this energy in 1 second. If you can reduce the power to as low as 10 W, it seems like it could be controlled.

Now the setpoint is 35 C, 1/5 the energy is needed, or 24 J. 10 W would take 2.4 seconds to supply this, so it should still be OK (if you have that much time).

How are you syncing to the Zero Crossing and how often? If you just sync once and use 83 ms for the window size, you will walk away from it.

Have you tried tuning it by bumping the output? I used the Åström-Hägglund method from https://www.sentekdynamics.com/sentek-dynamics-news/2020/8/24/pid-control-theory?gclid=CjwKCAiA-8SdBhBGEiwAWdgtcKC5nUJV-dJEhAbG19pclRlvRE9kiGj6sg_JBqZ_-CxDNVcoxtXzBRoCWlQQAvD_BwE to get my environemental chamber pretty close.

Could you lower the power by putting a step-down transformer before the heater?

John

Lukas Podschlapp

unread,
May 1, 2023, 10:21:38 AM5/1/23
to diy-pid...@googlegroups.com
Hello again,

ok let me try and provide more information regarding my system.

Yes the target is still at 95degC however currently I am running only one of two power circuits within the heater (trying to get that to work and will move on from there with the second circuit) That Hi-Power Circuit I am using currently provides 1200W. The Pump I am using is a Ulka EP5 that operates at constant flow rate of ca. 650cc/min (as I have an open system and don't try to push the water through a narrow section). In the example I posted I am dispensing 150ml which is controlled by the Flow Sensor (that actually works very accurately).

Currently I am not synching or to put it in other words have not put any effort into synching them. It is the first time I hear about this and I am not sure what is needed to do so. But I will do my  research.

I have not tried tuning it yet, because it seems I can't even get it to work like it is right now. But the link you shared has valuable information that I will consider once I can get to a certain level.

I implemented a bit of Serial.print() in my code so that I can see what is happening. I'll add some of it below:

Relay Pin: HIGH --- VALUES: Input: 58.12 --- Setpoint: 40.00 --- Output: 0.00 --- Relay HIGH for: 102s
Relay LOW for: 16 --- NTC Temperature: 63.84 degC --- FTH Control Temp. = 37.50 degC --- Water Outlet Control Temp. = 48.75 degC
Input: 63.84 --- Error: -23.84 --- Delta Input: 5.72 --- OutputSum Ki added: 0.00 --- OutputSum Kp added: 0.00 --- myOutput: 0.00
Relay Window shifted
Relay Pin: HIGH --- VALUES: Input: 63.84 --- Setpoint: 40.00 --- Output: 0.00 --- Relay HIGH for: 103s
Relay LOW for: 15 --- NTC Temperature: 79.41 degC --- FTH Control Temp. = 39.25 degC --- Water Outlet Control Temp. = 63.75 degC
Input: 79.41 --- Error: -39.41 --- Delta Input: 15.57 --- OutputSum Ki added: 0.00 --- OutputSum Kp added: 0.00 --- myOutput: 0.00
Relay Window shifted
Relay Pin: HIGH --- VALUES: Input: 79.41 --- Setpoint: 40.00 --- Output: 0.00 --- Relay HIGH for: 102s
Relay LOW for: 16 --- NTC Temperature: 91.48 degC --- FTH Control Temp. = 41.25 degC --- Water Outlet Control Temp. = 90.50 degC
Input: 91.48 --- Error: -51.48 --- Delta Input: 12.07 --- OutputSum Ki added: 0.00 --- OutputSum Kp added: 0.00 --- myOutput: 0.00
Relay Window shifted
Relay Pin: HIGH --- VALUES: Input: 91.48 --- Setpoint: 40.00 --- Output: 0.00 --- Relay HIGH for: 102s
Relay LOW for: 15 --- NTC Temperature: 97.49 degC --- FTH Control Temp. = 43.75 degC --- Water Outlet Control Temp. = 92.00 degC
Input: 97.49 --- Error: -57.49 --- Delta Input: 6.01 --- OutputSum Ki added: 0.00 --- OutputSum Kp added: 0.00 --- myOutput: 0.00
Relay Pin: HIGH --- VALUES: Input: 97.49 --- Setpoint: 40.00 --- Output: 0.00 --- Relay HIGH for: 103s
Relay LOW for: 15 --- NTC Temperature: 98.24 degC --- FTH Control Temp. = 45.50 degC --- Water Outlet Control Temp. = 90.75 degC
Input: 98.24 --- Error: -58.24 --- Delta Input: 0.76 --- OutputSum Ki added: 0.00 --- OutputSum Kp added: 0.00 --- myOutput: 0.00
Relay Window shifted

As you can see I am starting with a temperature below the setpoint. It actually started at 25degC. In the snip above, the Temperature is at 37.5, the Output is calculated to 0 and the relay is high for 103ms. (s in the print, need to correct that). I then overshoot even though the output is still calculated to 0. and keep going in that direction till I reach the desired water volume. The relay LOW might as well be not there at all as 15ms don't make a big difference. This was based on a window size of 500ms

--
You received this message because you are subscribed to a topic in the Google Groups "DIY PID Control" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/diy-pid-control/ooqO6HDhm1M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to diy-pid-contr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diy-pid-control/bc17891a-4391-4ca6-93b3-4015052551e7n%40googlegroups.com.

Steve Edmonds

unread,
May 3, 2023, 10:04:32 AM5/3/23
to DIY PID Control
Where have you added code for Relay HIGH for: 102s, Relay LOW for: 16. Into the library code?
Possibly the above calculations are wrong, 102-16 = 86 which is close to window size. Also you have Output: 0.00 so on time should be zero and off time 83. Is the red LED on the relay blinking?

Lukas Podschlapp

unread,
May 3, 2023, 10:21:21 AM5/3/23
to diy-pid...@googlegroups.com
I managed to fix it now.
The issue was that the if loop was comparing to > instead of <.
Now it is working fine and I can tune the PID. Thanks for your help anyway!

John Schindler

unread,
May 4, 2023, 12:39:53 PM5/4/23
to DIY PID Control
I'm glad you found the typo. It's hard to not read the code as what you meant it to do.

On the thermal side of your project, see if I have it correct:

You want to dispense 150 ml at 650 ml/min; which gives you 150*60/650 = 14 seconds to heat the water with a 1200 W heater. This gives you 1200 W * 14 s = 16800 J from the heater.

You want to raise the temperature from 20 to 95, for a delta T of 75 C (or K), for 150 g, this will require 4.184 J/(g*K) * 150 g * 75 K = 47070 J   (4.184 J/(g*K) is the specific heat of water)

I estimate that with 14 s of heating, the 150 g of water will reach about 46 C assuming all of the heat from the heater gets into the water.

I did a reality check in the kitchen and heated ~ 1.1 l of water to near boiling with a 1100 W kettle. It took about 330 s. Scaling to 150 ml gives 45 s.

I confirmed this with a calculation, letting delta T be 75 K. 4.184*1100*75 = 345180 J needed, which would be supplied in 345180/1100 = 314 s.

If my understanding of your flow rate and volume is correct, you will need a bigger heater, and/or a slower flow rate.

Keep us posted!

Schlappo22

unread,
May 9, 2023, 12:39:04 PM5/9/23
to DIY PID Control
I believe you are correct.
I still have the option of also using the second power trail which will give me additional 600W so would give me 1800W.
Unfortunately I was away for a few days and have not been able to work on the device.
Now working on a different functionality but will get back to this later on. And will keep you posted again.

Regards

Lukas Podschlapp

unread,
Jul 8, 2023, 7:51:20 AM7/8/23
to diy-pid...@googlegroups.com
Hello fellow PIDlers,

I have not been working on the PID for some time but picked it up again this week.
I am happy with where I am right now, up to 70degC I get very well regulated results in a short amount of time (needs to heat up in the beginning, I could introduce a preheat).

However I faced the following issue which I cannot seem to resolve and thought you might be able to help.
The code works fine, however in the beginning when starting the PID, it shifts the window after every adjustment, only after a few cycles will it actually give me the desired result. Might not be noticeable in the actual temperature, but looking at the Serial Monitor I notice something is wrong. But have a look for yourself:



```cpp

#include <FlowSensor.h>
#include <LcdBarGraph.h>
#include <LiquidCrystal.h>

//Internal NTC Stuff
const long int RT0 = 50000;  // Ω
const int B = 3970;          //  K
const int VCC = 5;           //Supply  voltage
const long int R = 12000;    //R=10KΩ


//Variables
float RT, VR, ln, TX, T0, VRT;

//Thermocouple Stuff
#include <SPI.h>
#include "Adafruit_MAX31855.h"

// Example creating a thermocouple instance with software SPI on any three
// digital IO pins.
#define MAXDO_1 31
#define MAXCS_1 30
#define MAXCLK_1 29


// initialize the Thermocouple
Adafruit_MAX31855 thermocouple_1(MAXCLK_1, MAXCS_1, MAXDO_1);

#define MAXDO_2 26
#define MAXCS_2 27
#define MAXCLK_2 28

// initialize the Thermocouple
Adafruit_MAX31855 thermocouple_2(MAXCLK_2, MAXCS_2, MAXDO_2);

//PID Stuff
#include <PID_v1.h>
#define RELAY_PIN 19
#define RELAY_ON HIGH
#define RELAY_OFF LOW


//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
double Kp = 30, Ki = 10, Kd = 100;

PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);

//WindowSize DON'T CHANGE FOR NOW!!!
int WindowSize = 100;

unsigned long windowStartTime;

//LCD
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
byte LCD_Columns = 20;
byte LCD_Rows = 4;

//Flow Sensor
FlowSensor Sensor(YFS201, 18);
unsigned long timebefore = 0;  // same type as millis(), is not being used again in this sketch



const int Pump = 10;

int variables[2][2] = { { 0, 1 }, { 2, 200 } };  // I want to link to the array in the array that I setup in the Menu file


void count() {
  Sensor.count();
}

void setup() {
  Serial.begin(115200);

  //PID Stuff
  windowStartTime = millis();
  //initialize the variables we're linked to
  Setpoint = 70;  //Temperature is the Setpoint

  //tell the PID to range between 0 and the full window size
  myPID.SetOutputLimits(0, WindowSize);
  myPID.SetSampleTime(WindowSize / 10);  // make sure we measure and sample at least 10 times per WindowSize.

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

  //Thermocouple
  thermocouple_1.begin();
  thermocouple_2.begin();

  //NTC

  T0 = 25 + 273.15;

  //Flowmeter
  Sensor.begin(count);

  //Flow Through Heater
  pinMode(RELAY_PIN, OUTPUT);

  //Pump
  pinMode(Pump, OUTPUT);

  //LCD Begin and Test
  lcd.begin(20, 4);
  lcd.print("Test");
  delay(1000);
  lcd.clear();

  //This is not needed in the setup, can be called in the normal loop
  double c = thermocouple_1.readCelsius();
  Serial.print(" --- Water Tank Control Temp. = ");
  Serial.print(c);
  Serial.println(" degC");
}

void loop() {
  // Pump and show progress on LCD until the desired volume has been reached
  LcdBarGraph lbg0(&lcd, 19, 1, 2);
  for (variables[0][0]; variables[0][0] < variables[1][1];) {
    //for (millis(); millis() < 10000;) {

    lcd.setCursor(7, 1);
    lcd.print("PROGRESS");
    lbg0.drawValue(variables[0][0], variables[1][1]);
    //delay(10);

    digitalWrite(Pump, HIGH);
    Sensor.read();
    variables[0][0] = Sensor.getVolume() * 1000;
    Serial.print("Volume: ");
    Serial.print(variables[0][0]);
    Serial.print("ml --- ");

    //Temperature Stuff
    VRT = analogRead(A15);         //Acquisition analog value of VRT
    VRT = (5.00 / 1023.00) * VRT;  //Conversion to voltage
    VR = VCC - VRT;
    RT = VRT / (VR / R);  //Resistance of RT
    ln = log(RT / RT0);
    TX = (1 / ((ln / B) + (1 / T0)));  //Temperature from thermistor
    TX = TX - 273.15;                  //Conversion to Celsius
    Serial.print("NTC Temperature: ");
    Serial.print(TX);
    Serial.print(" degC --- ");
    //Thermocouple

    //Serial.print("Internal Temp 2 = ");
    //Serial.print(thermocouple_2.readInternal());
    double d = thermocouple_2.readCelsius();
    Serial.print("FTH Control Temp. = ");

    Serial.print(d);
    Serial.print(" degC");
    //Serial.print(" --- Internal Temp 1 = ");
    //Serial.print(thermocouple_1.readInternal());

    Input = TX;
    myPID.Compute();

    /************************************************
   * turn the output pin on/off based on pid output
   ************************************************/

    if (millis() - windowStartTime > WindowSize) {  //time to shift the Relay Window
      windowStartTime += WindowSize;
      Serial.println("");
      Serial.print("Relay Window shifted");
      //Serial.print(" --- VALUES: Input: ");
      //Serial.print(Input);
      Serial.print(" --- Setpoint: ");
      Serial.print(Setpoint);
      Serial.print(" --- Output: ");
      Serial.print(Output);

    }

    if (Output > millis() - windowStartTime) {
      digitalWrite(RELAY_PIN, RELAY_ON);
      Serial.print(" --- Relay ON ");
      Serial.print(" --- Time: ");
      Serial.print(millis());
      Serial.println("ms");

    } else {
      digitalWrite(RELAY_PIN, RELAY_OFF);
      Serial.print(" --- Relay OFF");
      Serial.print(" --- Time: ");
      Serial.print(millis());
      Serial.println("ms");
    }
  }
  digitalWrite(RELAY_PIN, RELAY_OFF);
  digitalWrite(Pump, RELAY_OFF);

  lcd.clear();
  lcd.setCursor(8, 1);
  lcd.print("DONE");
  while (1) {}
}

```

and this is what I get in the Serial Monitor:

13:42:05.261 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC
13:42:05.261 -> Relay Window shifted --- Setpoint: 70.00 --- Output: 0.00 --- Relay OFF --- Time: 1043ms
13:42:05.293 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC
13:42:05.293 -> Relay Window shifted --- Setpoint: 70.00 --- Output: 100.00 --- Relay OFF --- Time: 1057ms
13:42:05.293 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC
13:42:05.293 -> Relay Window shifted --- Setpoint: 70.00 --- Output: 100.00 --- Relay OFF --- Time: 1072ms
13:42:05.293 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC
13:42:05.326 -> Relay Window shifted --- Setpoint: 70.00 --- Output: 100.00 --- Relay OFF --- Time: 1087ms
13:42:05.326 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC
13:42:05.326 -> Relay Window shifted --- Setpoint: 70.00 --- Output: 100.00 --- Relay OFF --- Time: 1101ms
13:42:05.326 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC
13:42:05.359 -> Relay Window shifted --- Setpoint: 70.00 --- Output: 100.00 --- Relay OFF --- Time: 1116ms
13:42:05.359 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC
13:42:05.359 -> Relay Window shifted --- Setpoint: 70.00 --- Output: 100.00 --- Relay OFF --- Time: 1131ms
13:42:05.359 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC
13:42:05.359 -> Relay Window shifted --- Setpoint: 70.00 --- Output: 100.00 --- Relay OFF --- Time: 1145ms
13:42:05.392 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC
13:42:05.392 -> Relay Window shifted --- Setpoint: 70.00 --- Output: 100.00 --- Relay OFF --- Time: 1160ms
13:42:05.392 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC
13:42:05.425 -> Relay Window shifted --- Setpoint: 70.00 --- Output: 100.00 --- Relay ON  --- Time: 1213ms
13:42:05.458 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.00 degC --- Relay ON  --- Time: 1222ms
13:42:05.458 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.00 degC --- Relay ON  --- Time: 1232ms
13:42:05.458 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.00 degC --- Relay ON  --- Time: 1242ms
13:42:05.490 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.00 degC --- Relay ON  --- Time: 1251ms
13:42:05.490 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.00 degC --- Relay ON  --- Time: 1260ms
13:42:05.490 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.00 degC --- Relay ON  --- Time: 1269ms
13:42:05.490 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC --- Relay ON  --- Time: 1280ms
13:42:05.523 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC --- Relay ON  --- Time: 1289ms
13:42:05.523 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC --- Relay ON  --- Time: 1298ms
13:42:05.523 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC
13:42:05.556 -> Relay Window shifted --- Setpoint: 70.00 --- Output: 100.00 --- Relay ON  --- Time: 1312ms
13:42:05.556 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC --- Relay ON  --- Time: 1323ms
13:42:05.556 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC --- Relay ON  --- Time: 1332ms
13:42:05.556 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC --- Relay ON  --- Time: 1341ms
13:42:05.589 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC --- Relay ON  --- Time: 1350ms
13:42:05.589 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC --- Relay ON  --- Time: 1359ms
13:42:05.589 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 26.25 degC --- Relay ON  --- Time: 1370ms

As you can see, in the beginning something is wrong but it seems to regulate itself.
Note that the pump was not connected in this trial, so no change in temp. nor in volume.

Any suggestions?






Thanks in advance!
Lukas

Pieter S

unread,
Jul 8, 2023, 10:25:03 AM7/8/23
to diy-pid...@googlegroups.com
What happens if Windowsize is increased fro 500ms to say 5000ms (5s)?

Speed of relays switching?

You received this message because you are subscribed to the Google Groups "DIY PID Control" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diy-pid-contr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diy-pid-control/CABKR0R%2BVXeBAs%3DttRn_btxmYkeeRiwWDS_2P_%2BMYtGeSyuoUbg%40mail.gmail.com.

Lukas Podschlapp

unread,
Jul 8, 2023, 11:51:12 AM7/8/23
to diy-pid...@googlegroups.com
I changed it from 100ms to 500ms. It decreases the amount of wrong windows in the beginning to only two and then keeps going normally. I would like to keep it at 100ms though. 

17:48:41.919 -> Volume: 0ml --- NTC Temperature: 26.11 degC --- FTH Control Temp. = 27.00 degC
17:48:41.919 -> Relay Window shifted --- Setpoint: 70.00 --- Output: 0.00 --- Relay OFF --- Time: 1038ms
17:48:41.919 -> Volume: 0ml --- NTC Temperature: 26.11 degC --- FTH Control Temp. = 27.00 degC
17:48:41.919 -> Relay Window shifted --- Setpoint: 70.00 --- Output: 0.00 --- Relay OFF --- Time: 1044ms
17:48:41.952 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 27.00 degC --- Relay OFF --- Time: 1050ms
17:48:41.952 -> Volume: 0ml --- NTC Temperature: 26.11 degC --- FTH Control Temp. = 27.00 degC --- Relay OFF --- Time: 1055ms
17:48:41.952 -> Volume: 0ml --- NTC Temperature: 26.25 degC --- FTH Control Temp. = 27.00 degC --- Relay OFF --- Time: 1060ms


Steve Edmonds

unread,
Jul 8, 2023, 2:21:17 PM7/8/23
to diy-pid...@googlegroups.com
In the first part, relay is off although output is 100 for about one window.
Serial.print WindowSize and windowStartTime, I suspect  initially you loop through if millis() - windowStartTime > WindowSize){}

Steve
      Serial.println("");Summary
--
You received this message because you are subscribed to the Google Groups "DIY PID Control" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diy-pid-contr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diy-pid-control/CABKR0R%2BVXeBAs%3DttRn_btxmYkeeRiwWDS_2P_%2BMYtGeSyuoUbg%40mail.gmail.com.

Pieter S

unread,
Jul 8, 2023, 2:30:49 PM7/8/23
to diy-pid...@googlegroups.com
What is pid.compute() cycle time? 1000ms comes to mind?

Try matching the pid cycle time with window?

Steve Edmonds

unread,
Jul 8, 2023, 2:47:31 PM7/8/23
to diy-pid...@googlegroups.com
Looking at serial output it seems to take 14-15ms to loop.
--
You received this message because you are subscribed to the Google Groups "DIY PID Control" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diy-pid-contr...@googlegroups.com.

Steve Edmonds

unread,
Jul 8, 2023, 3:11:36 PM7/8/23
to diy-pid...@googlegroups.com
I have found adding a window start time initialisation first time through the loop helped. I have abstracted the relay control to an interrupt cycle so it runs independent of the loop cycle but think the equivalent in your code would be;
in setup()
windowStartTime = 0;

In loop()
before


  if (millis() - windowStartTime > WindowSize) {  //time to shift the Relay Window
      windowStartTime += WindowSize;
      Serial.println("");
.............

Add
if (windowStartTime ==0 ) windowStartTime = millis();

I.e.
if (windowStartTime ==0 ) windowStartTime = millis();

  if (millis() - windowStartTime > WindowSize) {  //time to shift the Relay Window
      windowStartTime += WindowSize;
      Serial.println("");

On 8/07/23 23:51, Lukas Podschlapp wrote:
You received this message because you are subscribed to the Google Groups "DIY PID Control" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diy-pid-contr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diy-pid-control/CABKR0R%2BVXeBAs%3DttRn_btxmYkeeRiwWDS_2P_%2BMYtGeSyuoUbg%40mail.gmail.com.

Pieter S

unread,
Jul 9, 2023, 2:30:09 AM7/9/23
to diy-pid...@googlegroups.com
Yes!, that old bug... variables not probably init.

I see the default sampling is indeed 200ms

Lukas Podschlapp

unread,
Jul 25, 2023, 1:13:53 PM7/25/23
to diy-pid...@googlegroups.com
Hello again,

so the PID on its own works with the changes suggested by Steve above. However (and here comes the tricky part) I am trying to do something else at the same time.
The PID controls the water temperature as it is being pumped to the outlet. in parallel I am turning a motor that dispenses powder which is being mixed with the water on the outlet side. They both have to happen at the same time otherwise they will clog.
The progress shall be displayed on an LCD.

The progress so far:
PID works on its own without other tasks, however I get the same mistake again when implementing further tasks along the way.
Sometimes I get weird characters on the LCD, this seems to happen irregularly, trying to avoid lcd.clear() seems to resolve it most of the time. But I still have that issue once in a while on startup.
But I am more worried about the PID working with the other tasks at the same time.
Can anyone help to suggest what the best way to go about this is?
I implemented different window sizes for the different tasks, but the relay window changes in very irregular windows it seems.

Serial Output:

Volume: 5ml --- NTC Temperature: 26.65 [C] --- FTH Control Temp. = nan[C]
Relay Window shifted --- Setpoint: 36.00 --- Output: 0.00 --- Relay OFF --- Time: 8166 ms
Current dispensed weight: -0 [g] --- Motor ON
Volume: 11ml --- NTC Temperature: 26.25 [C] --- FTH Control Temp. = nan[C]
Relay Window shifted --- Setpoint: 36.00 --- Output: 250.00 --- Relay OFF --- Time: 8957 ms
Current dispensed weight: 0 [g] --- Motor ON
Volume: 15ml --- NTC Temperature: 26.93 [C] --- FTH Control Temp. = nan[C]
Relay Window shifted --- Setpoint: 36.00 --- Output: 0.00 --- Relay OFF --- Time: 9486 ms
Current dispensed weight: 0 [g] --- Motor ON
Volume: 19ml --- NTC Temperature: 26.11 [C] --- FTH Control Temp. = nan[C]
Relay Window shifted --- Setpoint: 36.00 --- Output: 250.00 --- Relay OFF --- Time: 10014 ms
Current dispensed weight: 0 [g] --- Motor ON
Volume: 24ml --- NTC Temperature: 26.11 [C] --- FTH Control Temp. = nan[C]
Relay Window shifted --- Setpoint: 36.00 --- Output: 250.00 --- Relay OFF --- Time: 10543 ms
Current dispensed weight: 0 [g] --- Motor ON
Volume: 28ml --- NTC Temperature: 26.11 [C] --- FTH Control Temp. = nan[C]
Relay Window shifted --- Setpoint: 36.00 --- Output: 250.00 --- Relay OFF --- Time: 11070 ms
Current dispensed weight: 0 [g] --- Motor ON
Volume: 32ml --- NTC Temperature: 26.11 [C] --- FTH Control Temp. = nan[C]
Relay Window shifted --- Setpoint: 36.00 --- Output: 250.00 --- Relay OFF --- Time: 11598 ms

My code:

#include <FlowSensor.h>
#include <LcdBarGraph.h>
#include <LiquidCrystal.h>
#include "HX711.h"

//Internal NTC Stuff
const long int RT0 = 50000;  // Ω
const int B = 3970;          //  K
const int VCC = 5;           //Supply  voltage
const long int R = 12000;    //R=10KΩ

//Variables
float RT, VR, ln, TX, T0, VRT;

//DC Motor
const int DC_Motor = 6;

//Scale Back Left
#define LOADCELL_DOUT_PIN_1 22
#define LOADCELL_SCK_PIN_1 24
HX711 scale_1;
float calibration_factor_1 = -660;

//Scale Front Left
#define LOADCELL_DOUT_PIN_2 32
#define LOADCELL_SCK_PIN_2 33
HX711 scale_2;
float calibration_factor_2 = -810;

//Scale Back Right
#define LOADCELL_DOUT_PIN_3 25
#define LOADCELL_SCK_PIN_3 23
HX711 scale_3;
float calibration_factor_3 = -700;

//Scale Front Right
#define LOADCELL_DOUT_PIN_4 34
#define LOADCELL_SCK_PIN_4 35
HX711 scale_4;
float calibration_factor_4 = -740;

//Constants
/*
const int One_Cycle = 6000;
const int Scale_Interval = 100;
const int Scale_Pause = One_Cycle - Scale_Interval;
const int Motor_Interval = 4000;
const int Motor_Pause = One_Cycle - Motor_Interval;
*/
const int Desired_Weight = 15;  // this is in the variables section in the overall sketch

byte DC_Motor_Status = LOW;
byte Scale_Status = LOW;
byte Water_Status = LOW;
byte Powder_Status = LOW;
int i = 0;

//Variables
float current_weight = 0;

unsigned long currentMillis = 0;
unsigned long previous_motor_Millis = 0;
unsigned long previous_scale_Millis = 0;
unsigned long previous_lcd_Millis = 0;
int WindowSize = 250;
int WindowSize_Scale = 500;
int WindowSize_LCD = 1000;
unsigned long windowStartTime;
unsigned long windowStartTime_Scale;
unsigned long windowStartTime_LCD;

//LCD
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
byte LCD_Columns = 20;
byte LCD_Rows = 4;

//Flow Sensor
FlowSensor Sensor(YFS201, 18);
unsigned long timebefore = 0;  // same type as millis(), is not being used again in this sketch


const int Pump = 10;

int variables[2][2] = { { 0, 1 }, { 2, 90 } };  // I want to link to the array in the array that I setup in the Menu file

void count() {
  Sensor.count();
}

void setup() {
  Serial.begin(115200);

  //DC Motor
  pinMode(DC_Motor, OUTPUT);

  //Scale
  scale_1.begin(LOADCELL_DOUT_PIN_1, LOADCELL_SCK_PIN_1);
  scale_2.begin(LOADCELL_DOUT_PIN_2, LOADCELL_SCK_PIN_2);
  scale_3.begin(LOADCELL_DOUT_PIN_3, LOADCELL_SCK_PIN_3);
  scale_4.begin(LOADCELL_DOUT_PIN_4, LOADCELL_SCK_PIN_4);

  scale_1.set_scale(calibration_factor_1);  // this value is obtained by calibrating the scale with known weights; see the README for details
  scale_2.set_scale(calibration_factor_2);  // this value is obtained by calibrating the scale with known weights; see the README for details
  scale_3.set_scale(calibration_factor_3);  // this value is obtained by calibrating the scale with known weights; see the README for details
  scale_4.set_scale(calibration_factor_4);  // this value is obtained by calibrating the scale with known weights; see the README for details

  scale_1.tare();  // reset the scale to 0
  scale_2.tare();  // reset the scale to 0
  scale_3.tare();  // reset the scale to 0
  scale_4.tare();  // reset the scale to 0

  //PID Stuff
  windowStartTime = millis();
  windowStartTime_Scale = millis();
  windowStartTime_LCD = millis();

  //initialize the variables we're linked to
  Setpoint = 36;  //Temperature is the Setpoint
  //tell the PID to range between 0 and the full window size
  myPID.SetOutputLimits(0, WindowSize);
  myPID.SetSampleTime(WindowSize / 10);  // make sure we measure and sample at least 10 times per WindowSize.
  //turn the PID on
  myPID.SetMode(AUTOMATIC);

  //Thermocouple
  thermocouple_1.begin();
  thermocouple_2.begin();

  //NTC
  T0 = 25 + 273.15;

  //Flowmeter
  Sensor.begin(count);

  //Flow Through Heater
  pinMode(RELAY_PIN, OUTPUT);

  //Pump
  pinMode(Pump, OUTPUT);

  //LCD
  lcd.begin(20, 4);

  delay(1000);
}



void Drink_preparation() {
  i = 1;
  scale_1.tare();  // reset the scale to 0
  scale_2.tare();  // reset the scale to 0
  scale_3.tare();  // reset the scale to 0
  scale_4.tare();  // reset the scale to 0
  while (Water_Status == LOW || Powder_Status == LOW) {
    //Serial.println("while loop called");
    currentMillis = millis();
    Water_Dispensing();
    Powder_Dispensing();
    Update_LCD();
  }
  delay(1500);
  lcd.clear();
  lcd.setCursor(5, 1);
  lcd.print("PREPARATION");
  lcd.setCursor(8, 2);
  lcd.print("DONE");
  return;
}

void Update_LCD() {

  if (millis() - windowStartTime_LCD > WindowSize_LCD) {  //time to shift the Relay Window
    if (variables[0][0] < variables[1][1] || Powder_Status == LOW) {
      windowStartTime_LCD += WindowSize_LCD;
      LcdBarGraph lbg0(&lcd, 17, 1, 1);
      lcd.setCursor(6, 0);
      lcd.print("PROGRESS");
      lbg0.drawValue(variables[0][0], variables[1][1]);

      // Volume Display
      // Printing the Vol.: will always be called
      lcd.setCursor(0, 2);
      lcd.print("Vol.: ");
      // Single digit volumes
      if (variables[0][0] < 10) {
        lcd.setCursor(8, 2);
        lcd.print(variables[0][0]);
      }
      // Double digit volumes
      if (variables[0][0] >= 10 && variables[0][0] < 100) {
        lcd.setCursor(7, 2);
        lcd.print(variables[0][0]);
      }
      // Triple digit volumes
      if (variables[0][0] >= 100) {
        lcd.setCursor(6, 2);
        lcd.print(variables[0][0]);
      }

      // Powder Display
      // Printing the Form.: will always be called
      lcd.setCursor(0, 3);
      lcd.print("Form.: ");
      // Single digit Weight
      if (current_weight * (-1) < 10) {
        lcd.setCursor(8, 3);
        lcd.print(current_weight * (-1), 0);
      }
      // Double digit Weight
      if (current_weight * (-1) >= 10 && current_weight * (-1) < 100) {
        lcd.setCursor(7, 3);
        lcd.print(current_weight * (-1), 0);
      }
      // Triple digit Weight
      if (current_weight * (-1) >= 100) {
        lcd.setCursor(6, 3);
        lcd.print(current_weight * (-1), 0);
      }

      // Water Temperature
      // Printing the Temp.: will always be called
      lcd.setCursor(11, 2);
      lcd.print("Temp.: ");
      // Single digit Temp
      if (TX < 10) {
        lcd.setCursor(19, 2);
        lcd.print(TX, 0);
      }
      // Double digit Temp
      if (TX >= 10 && TX < 100) {
        lcd.setCursor(18, 2);
        lcd.print(TX, 0);
      }
      // Triple digit Temp
      if (TX >= 100) {
        lcd.setCursor(17, 2);
        lcd.print(TX, 0);
      }
    }
  }
}

void Water_Dispensing() {

  if (variables[0][0] < variables[1][1]) {
    digitalWrite(Pump, HIGH);
    Sensor.read();
    variables[0][0] = Sensor.getVolume() * 1000;
    Serial.print("Volume: ");
    Serial.print(variables[0][0]);
    Serial.print("ml --- ");
    //Temperature NTC
    VRT = analogRead(A15);         //Acquisition analog value of VRT
    VRT = (5.00 / 1023.00) * VRT;  //Conversion to voltage
    VR = VCC - VRT;
    RT = VRT / (VR / R);  //Resistance of RT
    ln = log(RT / RT0);
    TX = (1 / ((ln / B) + (1 / T0)));  //Temperature from thermistor
    TX = TX - 273.15;                  //Conversion to Celsius
    Serial.print("NTC Temperature: ");
    Serial.print(TX);
    Serial.print(" [C] --- ");
    //Thermocouple
    double d = thermocouple_2.readCelsius();
    Serial.print("FTH Control Temp. = ");
    Serial.print(d);
    Serial.print("[C]");

    Input = TX;
    myPID.Compute();

    if (windowStartTime == 0) windowStartTime = millis();
    if (millis() - windowStartTime > WindowSize) {  //time to shift the Relay Window
      windowStartTime += WindowSize;
      Serial.println("");
      Serial.print("Relay Window shifted");
      Serial.print(" --- Setpoint: ");
      Serial.print(Setpoint);
      Serial.print(" --- Output: ");
      Serial.print(Output);
    }

    if (Output > millis() - windowStartTime) {
      digitalWrite(RELAY_PIN, RELAY_ON);
      Serial.print(" --- Relay ON ");
      Serial.print(" --- Time: ");
      Serial.print(millis());
      Serial.println(" ms");

    } else {
      digitalWrite(RELAY_PIN, RELAY_OFF);
      Serial.print(" --- Relay OFF");
      Serial.print(" --- Time: ");
      Serial.print(millis());
      Serial.println(" ms");
    }
  } else {
    digitalWrite(Pump, LOW);
    digitalWrite(RELAY_PIN, RELAY_OFF);
    Serial.println("Pump OFF");
    Water_Status = HIGH;
  }
}

void Powder_Dispensing() {
  if (millis() - windowStartTime_Scale > WindowSize_Scale) {  //time to read the scales and maybe change the motor status
    windowStartTime_Scale += WindowSize_Scale;
    if (current_weight > (-1) * Desired_Weight && Powder_Status == LOW) {
      Serial.println("");
      Serial.print("Current dispensed weight: ");
      current_weight = (scale_1.get_units(3) + scale_2.get_units(3) + scale_3.get_units(3) + scale_4.get_units(3));
      Serial.print(current_weight, 0);
      Serial.print(" [g]");
      digitalWrite(DC_Motor, HIGH);
      Serial.println(" --- Motor ON");
    } else {
      digitalWrite(DC_Motor, LOW);
      Powder_Status = HIGH;
      Serial.println("Motor OFF");
    }
  }
}

void loop() {
  if (i == 0) {
    Drink_preparation();
  }
}

--
You received this message because you are subscribed to a topic in the Google Groups "DIY PID Control" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/diy-pid-control/ooqO6HDhm1M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to diy-pid-contr...@googlegroups.com.

Lukas Podschlapp

unread,
Jul 25, 2023, 1:32:12 PM7/25/23
to diy-pid...@googlegroups.com
I think I found the trouble maker:
      current_weight = (scale_1.get_units(3) + scale_2.get_units(3) + scale_3.get_units(3) + scale_4.get_units(3));
this took way too long as each scale took three readings to average it out. Changed it to (1) each and that seems to work again.

However the LCD weird character problem got worse. Now I never get a proper reading on the LCD. Any suggestions? It worked before, which is confusing


Reply all
Reply to author
Forward
0 new messages