Changing Setpoint on a PID controller with Serial

Hello!

As silly as this may be… I just recently started playing with Arduino and am currently trying to set the sketch up to turn the PID function off until the User sends a new Setpoint higher than 300 and less than 800.
the goal is to try to use Fahrenheit even though I’m fairly familiar with Celsius.
i would also be ok with the Setpoint being 0 when the PID is “OFF” as it will very rarely actually be powered down.

the Code below is what currently have. Once I can change the Setpoint I can manage the rest I believe.

Arduino_PID.ino (2.08 KB)

I should have mentioned that the arduino is controlling a SSR on pin 8 and getting a readout from a MAX6675 Thermocouple. The Thermocouple is reading a heating element, which is heated by the SSR

What you have attempted for serial input won't work, as you have already probably figured out.

For a good introduction to using serial communications to exchange data, see the Serial Input Basics tutorial.

thanks for the reply!
the Serial was definitely one of the big problem areas and I'm currently fixing.

ok,
Code updated to use multi character code based on an end character.

and its functioning setting the PID Setpoint… Kinda… no matter what type in it sets the Setpoint to 48…

well below the power on thresh hold

Arduino_PID.ino (2.69 KB)

As you seem to be new to programming why have you not used my recvWithEndMarker() without any changes?

…R

I’ve been slowly pouring over it and learning how everything functions as I go along. but at the moment i think i need to implement the start character as well then parse it?

enkitheotter:
I've been slowly pouring over it and learning how everything functions as I go along. but at the moment i think i need to implement the start character as well then parse it?

It is much easier to help if you use the examples unchanged because then I don't have to try to figure out if you have broken something.

It is not essential to use a start-character. It does make things more reliable but it will make things a little less convenient for a human entering data at the keyboard.

There is a parse example in Serial Input Basics

Update your program and then post the updated code if you still have a problem.

...R

alrighty, everything is pulled over now.

I can set my Setpoint now. but i can visibly change it while bool Power = true

the only other issue I’m having at the moment is the temp is reading out live. It was working in the same spot as before. it reads the temp once when the arduino starts the code then reads the same over and over

Arduino_PID.ino (3.18 KB)

enkitheotter:
the only other issue I'm having at the moment is the temp is reading out live.

I don't understand that and I can't make sense of your code because you have {} braces all over the place. Use the AutoFormat tool to lay your code out consistently for easy reading. It also makes code easier to read if you always use pairs of {} with IF and ELSE even when not strictly necessary.

...R

sorry i meant the temp isn’t reading out live.

I got the Serial Code working. also Auto formatted for easier reading.
As of now my PID code is having issues. The temperature is running away well past the Setpoint.
when i disconnect the AC from it the temp drop drastically(about 200-300F).

Arduino_PID.ino (3.4 KB)

enkitheotter:
sorry i meant the temp isn't reading out live.

I got the Serial Code working. also Auto formatted for easier reading.
As of now my PID code is having issues. The temperature is running away well past the Setpoint.
when i disconnect the AC from it the temp drop drastically(about 200-300F).

You are still assuming we know all about your project. What has AC got to do with it? Write a proper explanation so we know what you know

And your code does not look any more readable.

...R

enkitheotter:
I should have mentioned that the arduino is controlling a SSR on pin 8 and getting a readout from a MAX6675 Thermocouple. The Thermocouple is reading a heating element, which is heated by the SSR

I have actually already explained the project as seen above.

The 110V 25A SSR is controlled by the “RelayPin” (currently Pin 8. I’ve defined the “RelayPin” before Setup.) and lets Power flow to the heating element( in this case a Hotrunner).

The MAX6675 board is connected to 5 CLK, 6 DO, 7 CS. It also reads the Heating Elements temp.

The temperature is running away then stabilizing which is fine. pretty sure its supposed to do that?

The goal is for the user to input a new Setpoint = 0 or Setpoint >=300 && Setpoint <= 800

so setpoint has a value of 0 or somewhere between 300-800F

0 would be off in this case.

The PIDs goal in this case is to control the SSR based on the temperature readout from the MAX6675.

If the temp that is read is too high turn off the SSR

If the Temp that is read is too low turn on the SSR.

the PID is checking about every 100ms based from the library

enkitheotter:
the PID is checking about every 100ms based from the library

What is being heated?

How many degrees will the temperature change in 100 millisecs?

Let's take things step by step ...

If you "hard code" different setpoint values in your program does it work properly? If not then that needs to be fixed before you worry about Serial input.

If it does work with hard-coded values then it is a simple matter to update the value of the variable using input from Serial.

...R

the heating element is a Hotrunner coil for a plastic injection molding machine. the coil is rated at 100W at 120V

the temperature changes about 15F every 100ms

with the current code it works nicely

again reformatted for hopefully easier reading

Arduino_PID2.ino (3.28 KB)

enkitheotter:
with the current code it works nicely

Good to hear it is now working.

...R