PID tempreture control

Hello,

For a schoolproject i need to heat up a block of aluminium and for that i need to use a PID.
We have evrything now but it doesn’t work and we dont know why.
My question is, is our code correct or did we miss something.
I attached out code so if someone might take a look at it i would appreciate it.

Cheers.

PID_2.5.ino (6.03 KB)

Please provide a detailed description of what you mean by "it doesn't work"

Ah yes ofcourse my excuses. it doesn't send the signal to heat up. The components work without eachother but when connected is doesn't work.

I didn't read the whole code but your code is returning error:

PID_2.5.ino: In function 'void loop()':
PID_2.5:62: error: 'THERMISTORPIN' was not declared in this scope
'THERMISTORPIN' was not declared in this scope

If this is the error then try defining THERMISTORPIN before setup. using:

#define THERMISTORPIN A4 //Or some other analog PIN

Hope this helps.

Chocomann: it doesn't send the signal to heat up.

And what does that mean? That uitsturing is not pwm'd on pin 3? If that's what you mean, how do you know that? Have you stuck a meter or a 'scope on the pin? If you serial print uitsturing is it the correct value? Is pin 3 a pwm pin on your board?- I know it is on a Uno but I don't know if it is on all boards, and you didn't say it's a Uno or whatever.

(btw, you assign the value 3 to heaterpin, and make heaterpin an output, but the analogWrite refers to the pin by number. Bit dangerous if you later make it pin 5 in the declare, but forgot to change the analogWrite. That's the whole point of using names ;) )

(Plus, I see that Anshu_Raj didn't get a compile, nor did I. That could explain why it's not working but I somehow think you would have noticed if it hadn't compiled. But it obviously means you haven't psted the last compilable version.....)

Ah yes as I saw Anshu_Raj’s comment I noticed i uploaded the wrong version of the PID, so attached is the right version we are working with right now and is compiling at us.

  • We are using an Arduino UNO.
  • PIN 3 is a PWM pin

I hope the information i gave now is sufficient.

thanks for the help.

PID_2.0.ino (5.67 KB)

Chocomann: I hope the information i gave now is sufficient.

You still didn't say exactly what you mean by it not sending the signal- you not getting the expected output on the pin? And if not, how do you know?

edit.... and if you serial print it, what is it and is it what you expect?

what is your serial monitor output? I cannot see where you print the samples[] or average? I assume you have had simple on off control operational? if you put an oscilloscope on pin 3 do you see any signal?

we are getting the roomtemperature and the pwm signal is sending out full to heat up the heatelement. But the heatelement is somehow not getting the signal (or something else) to heat up, because it stays roomtemperature.

We don't have a oscilloscope.

if you put an LED on pin 3 can you see its output varying as the temperature changes? if you don't have an oscilloscope try a multimeter post the circuit?

How do you know then that pwm signla is there?- voltmeter? You could always force it 100% on with analogWrite(heaterpin, 255) just to test, btw.

And if it is getting out, then what’s the circuit? You saying there’s a pwm signal but it’s not “arriving” for want of a better word?

Maybe we ought to see the circuit. I hope that signal is going to a transistor or h-bridge or something which is the in turn, switching the element on? Hope you’re not trying to run a heater off the pwm direct?

hereby the circuit and a screenshot of the serial plotter

An IRF540 mosfet isn’t logic level, so it’s not switching on. Needs 10V for that…

You need something like an IRLZ44 with RDS(on) quoted at 5V.

Well sir, you just solved our problem... Thank you very much! and thanks to the rest too for thinking with us!

Chocomann: Well sir, you just solved our problem... Thank you very much! and thanks to the rest too for thinking with us!

Have you actually tried it with a logic level mosfet already or just taking my word for it? I wouldn't do the latter ;)

haha yes we tried it, we had a lower level mosfet in an other circuit but we had to reorder new mosfets but the guy who ordered them didn't look at the voltage levels and we thought he ordered the same as we had before. But after we put in de lower level mosfet it worked "perfect". so that were a lot of hours wasted just by overlooking the mosfet :/

OP -- I understand you’re still a student, so I hope this has been a learning experience for you. As someone who has worked as an engineer and engineering manager for more than 30 years, I’ll offer some free advice:

The more thoroughly you describe your problem and the more supporting documentation you provide up-front, the better your chances of getting the help required to solve it.

If one of the engineers who works for me came in with a problem statement of: “It Doesn’t Work”, and it then required a dozen Q & A interactions for me to pull the required information out of him -- then there’s a good chance he may not be working for me for very long.

Chocomann: . so that were a lot of hours wasted just by overlooking the mosfet :/

There's a moral in there somewhere.

And another one: post a schematic early on in the forum thread ;)

Glad I could help.

Imagine though, if the schematic showed the correct mosfet from the previous batch; we'd still be farting around. It's lucky there was an up to date schematic (what we call the "as-built" in engineering) showing the right number for the wrong mosfet.

Talking of as-builts, don't forget to update the schematic for your records.

And fix that analogWrite(3, uitsturing ) since the pin already has a name, else as sure as hell you will change heaterpin to 5 for some reason and the analogWrite will not work anymore.